Skip to content

Commit e3c8698

Browse files
authored
Merge pull request #5163 from garlick/convert_streq
cleanup: use ccan/str in place of strcmp(), strncmp()
2 parents 77d90d2 + 99d1062 commit e3c8698

File tree

214 files changed

+1081
-874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+1081
-874
lines changed

src/bindings/lua/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ AM_LDFLAGS = $(CODE_COVERAGE_LIBS)
44
AM_CPPFLAGS = \
55
-I$(top_srcdir) \
66
-I$(top_srcdir)/src/include \
7+
-I$(top_srcdir)/src/common/libccan \
78
-I$(top_builddir)/src/common/libflux \
89
$(LUA_INCLUDE)
910

src/bindings/lua/flux-lua.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "flux/core.h"
2727

28+
#include "ccan/str/str.h"
29+
2830
#include "jansson-lua.h"
2931
#include "zmsg-lua.h"
3032
#include "lutil.h"
@@ -242,9 +244,9 @@ static int l_flux_index (lua_State *L)
242244
if (key == NULL)
243245
return luaL_error (L, "flux: invalid index");
244246

245-
if (strcmp (key, "size") == 0)
247+
if (streq (key, "size"))
246248
return l_flux_size (L);
247-
if (strcmp (key, "rank") == 0)
249+
if (streq (key, "rank"))
248250
return l_flux_rank (L);
249251

250252
lua_getmetatable (L, 1);
@@ -786,7 +788,7 @@ static int l_msghandler_index (lua_State *L)
786788
/*
787789
* Check for method names
788790
*/
789-
if (strcmp (key, "remove") == 0) {
791+
if (streq (key, "remove")) {
790792
lua_getmetatable (L, 1);
791793
lua_getfield (L, -1, "remove");
792794
return (1);
@@ -937,7 +939,7 @@ static int l_watcher_index (lua_State *L)
937939
/*
938940
* Check for method names
939941
*/
940-
if (strcmp (key, "remove") == 0) {
942+
if (streq (key, "remove")) {
941943
lua_getmetatable (L, 1);
942944
lua_getfield (L, -1, "remove");
943945
return (1);
@@ -1046,9 +1048,9 @@ static int l_flux_reactor_start (lua_State *L)
10461048
flux_t *h;
10471049
int mode = 0;
10481050
if ((lua_gettop (L) > 1) && (arg = lua_tostring (L, 2))) {
1049-
if (strcmp (arg, "once") == 0)
1051+
if (streq (arg, "once"))
10501052
mode = FLUX_REACTOR_ONCE;
1051-
else if (strcmp (arg, "nowait") == 0)
1053+
else if (streq (arg, "nowait"))
10521054
mode = FLUX_REACTOR_NOWAIT;
10531055
else
10541056
return lua_pusherror (L, "flux_reactor: Invalid argument");

src/bindings/lua/zmsg-lua.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <lauxlib.h>
1616

1717
#include "src/common/libczmqcontainers/czmq_containers.h"
18+
#include "ccan/str/str.h"
1819

1920
#include "flux/core.h"
2021
#include "lutil.h"
@@ -121,23 +122,23 @@ static int l_zmsg_info_index (lua_State *L)
121122
if (key == NULL)
122123
return lua_pusherror (L, "zmsg: invalid member");
123124

124-
if (strcmp (key, "type") == 0) {
125+
if (streq (key, "type")) {
125126
lua_pushstring (L, zmsg_type_string (zi->typemask));
126127
return (1);
127128
}
128-
if (strcmp (key, "tag") == 0) {
129+
if (streq (key, "tag")) {
129130
if (zi->tag)
130131
lua_pushstring (L, zi->tag);
131132
else
132133
lua_pushnil (L);
133134
return (1);
134135
}
135-
if (strcmp (key, "data") == 0) {
136+
if (streq (key, "data")) {
136137
if (!zi->o || json_object_to_lua (L, zi->o) < 0)
137138
lua_pushnil (L);
138139
return (1);
139140
}
140-
if (strcmp (key, "errnum") == 0) {
141+
if (streq (key, "errnum")) {
141142
int errnum;
142143
if (!(zi->typemask & FLUX_MSGTYPE_RESPONSE))
143144
return lua_pusherror (L,
@@ -146,7 +147,7 @@ static int l_zmsg_info_index (lua_State *L)
146147
lua_pushnumber (L, errnum);
147148
return (1);
148149
}
149-
if (strcmp (key, "matchtag") == 0) {
150+
if (streq (key, "matchtag")) {
150151
uint32_t matchtag;
151152
if (flux_msg_get_matchtag (zi->msg, &matchtag) < 0)
152153
return lua_pusherror (L, "zmsg: matchtag: %s",

src/broker/boot_config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "src/common/libutil/log.h"
2626
#include "src/common/libutil/errno_safe.h"
27+
#include "ccan/str/str.h"
2728

2829
#include "attr.h"
2930
#include "overlay.h"
@@ -378,7 +379,7 @@ int boot_config_getrankbyname (json_t *hosts, const char *name, uint32_t *rank)
378379
/* N.B. entry already validated by boot_config_parse().
379380
*/
380381
if (json_unpack (entry, "{s:s}", "host", &host) == 0
381-
&& !strcmp (name, host)) {
382+
&& streq (name, host)) {
382383
*rank = index;
383384
return 0;
384385
}

src/broker/boot_pmi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "src/common/libutil/ipaddr.h"
2424
#include "src/common/libutil/errno_safe.h"
2525
#include "src/common/libpmi/upmi.h"
26+
#include "ccan/str/str.h"
2627

2728
#include "attr.h"
2829
#include "overlay.h"
@@ -114,7 +115,7 @@ static bool use_ipc (attr_t *attrs)
114115
const char *val;
115116

116117
if (attr_get (attrs, "tbon.prefertcp", &val, NULL) == 0
117-
&& strcmp (val, "0") != 0)
118+
&& !streq (val, "0"))
118119
goto done;
119120
if (attr_get (attrs, "broker.mapping", &val, NULL) < 0 || !val)
120121
goto done;

src/broker/broker.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <argz.h>
2020
#include <flux/core.h>
2121
#include <czmq.h>
22+
#undef streq // redefined by ccan/str/str.h below
2223
#include <jansson.h>
2324
#if HAVE_CALIPER
2425
#include <caliper/cali.h>
@@ -43,6 +44,7 @@
4344
#include "src/common/libutil/errprintf.h"
4445
#include "src/common/libfluxutil/method.h"
4546
#include "ccan/array_size/array_size.h"
47+
#include "ccan/str/str.h"
4648

4749
#include "module.h"
4850
#include "brokercfg.h"
@@ -690,8 +692,8 @@ static bool is_interactive_shell (const char *argz, size_t argz_len)
690692
char *shell;
691693
char *cmd = argz_next (argz, argz_len, NULL);
692694
while ((shell = getusershell ())) {
693-
if (strcmp (cmd, shell) == 0
694-
|| strcmp (cmd, basename (shell)) == 0) {
695+
if (streq (cmd, shell)
696+
|| streq (cmd, basename (shell))) {
695697
result = true;
696698
break;
697699
}
@@ -935,7 +937,7 @@ static int init_local_uri_attr (struct overlay *ov, attr_t *attrs)
935937
else {
936938
char path[1024];
937939

938-
if (strncmp (uri, "local://", 8) != 0) {
940+
if (!strstarts (uri, "local://")) {
939941
log_msg ("local-uri is malformed");
940942
return -1;
941943
}
@@ -1507,7 +1509,7 @@ static int service_allow (struct flux_msg_cred cred, const char *name)
15071509
if ((cred.rolemask & FLUX_ROLE_OWNER))
15081510
return 0;
15091511
snprintf (prefix, sizeof (prefix), "%" PRIu32 "-", cred.userid);
1510-
if (!strncmp (prefix, name, strlen (prefix)))
1512+
if (strstarts (name, prefix))
15111513
return 0;
15121514
errno = EPERM;
15131515
return -1;
@@ -1571,7 +1573,7 @@ static void service_remove_cb (flux_t *h, flux_msg_handler_t *w,
15711573
errno = ENOENT;
15721574
goto error;
15731575
}
1574-
if (strcmp (uuid, sender) != 0) {
1576+
if (!streq (uuid, sender)) {
15751577
errno = EINVAL;
15761578
goto error;
15771579
}
@@ -1793,7 +1795,7 @@ static int handle_event (broker_ctx_t *ctx, const flux_msg_t *msg)
17931795
*/
17941796
s = zlist_first (ctx->subscriptions);
17951797
while (s) {
1796-
if (!strncmp (s, topic, strlen (s))) {
1798+
if (strstarts (topic, s)) {
17971799
if (flux_requeue (ctx->h, msg, FLUX_RQ_TAIL) < 0)
17981800
flux_log_error (ctx->h, "%s: flux_requeue\n", __FUNCTION__);
17991801
break;

src/broker/content-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "src/common/libutil/iterators.h"
2525
#include "src/common/libutil/log.h"
2626
#include "src/common/libcontent/content.h"
27+
#include "ccan/str/str.h"
2728

2829
#include "attr.h"
2930
#include "content-cache.h"
@@ -748,7 +749,7 @@ static void content_register_backing_request (flux_t *h,
748749
if (!(cache->backing_name = strdup (name)))
749750
goto error;
750751
}
751-
if (strcmp (cache->backing_name, name) != 0) {
752+
if (!streq (cache->backing_name, name)) {
752753
errno = EINVAL;
753754
errstr = "content backing store cannot be changed on the fly";
754755
goto error;
@@ -999,7 +1000,7 @@ static int content_cache_getattr (const char *name, const char **val, void *arg)
9991000
{
10001001
struct content_cache *cache = arg;
10011002

1002-
if (!strcmp (name, "content.backing-module"))
1003+
if (streq (name, "content.backing-module"))
10031004
*val = cache->backing_name;
10041005
else
10051006
return -1;

src/broker/groups.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "src/common/libidset/idset.h"
4444
#include "src/common/libutil/errno_safe.h"
4545
#include "src/common/libczmqcontainers/czmq_containers.h"
46+
#include "ccan/str/str.h"
4647

4748
#include "overlay.h"
4849
#include "groups.h"
@@ -727,15 +728,16 @@ static void overlay_monitor_cb (struct overlay *ov, uint32_t rank, void *arg)
727728
/* Generate LEAVEs for any groups 'rank' (and subtree) may be a member
728729
* of if transitioning to lost (crashed) or offline (shutdown).
729730
*/
730-
if (!strcmp (status, "lost") || !strcmp (status, "offline")) {
731+
if (streq (status, "lost")
732+
|| streq (status, "offline")) {
731733
auto_leave (g, status, rank, ids);
732734
}
733735
/* Update broker.torpid if torpidity has changed while subtree is in
734736
* one of the "online" states.
735737
*/
736-
else if (!strcmp (status, "full")
737-
|| !strcmp (status, "partial")
738-
|| !strcmp (status, "degraded")) {
738+
else if (streq (status, "full")
739+
|| streq (status, "partial")
740+
|| streq (status, "degraded")) {
739741
torpid_update (g, rank, ids, overlay_peer_is_torpid (ov, rank));
740742
}
741743

src/broker/log.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "src/common/libutil/wallclock.h"
2424
#include "src/common/libutil/stdlog.h"
2525
#include "src/common/libutil/timestamp.h"
26+
#include "ccan/str/str.h"
2627

2728
#include "log.h"
2829

@@ -255,19 +256,19 @@ static int attr_get_log (const char *name, const char **val, void *arg)
255256
{
256257
logbuf_t *logbuf = arg;
257258

258-
if (!strcmp (name, "log-forward-level"))
259+
if (streq (name, "log-forward-level"))
259260
*val = int_to_string (logbuf->forward_level);
260-
else if (!strcmp (name, "log-critical-level"))
261+
else if (streq (name, "log-critical-level"))
261262
*val = int_to_string (logbuf->critical_level);
262-
else if (!strcmp (name, "log-stderr-level"))
263+
else if (streq (name, "log-stderr-level"))
263264
*val = int_to_string (logbuf->stderr_level);
264-
else if (!strcmp (name, "log-stderr-mode"))
265+
else if (streq (name, "log-stderr-mode"))
265266
*val = logbuf->stderr_mode == MODE_LEADER ? "leader" : "local";
266-
else if (!strcmp (name, "log-ring-size"))
267+
else if (streq (name, "log-ring-size"))
267268
*val = int_to_string (logbuf->ring_size);
268-
else if (!strcmp (name, "log-filename"))
269+
else if (streq (name, "log-filename"))
269270
*val = logbuf->filename;
270-
else if (!strcmp (name, "log-level"))
271+
else if (streq (name, "log-level"))
271272
*val = int_to_string (logbuf->level);
272273
else {
273274
errno = ENOENT;
@@ -281,35 +282,35 @@ static int attr_set_log (const char *name, const char *val, void *arg)
281282
logbuf_t *logbuf = arg;
282283
int rc = -1;
283284

284-
if (!strcmp (name, "log-forward-level")) {
285+
if (streq (name, "log-forward-level")) {
285286
int level = strtol (val, NULL, 10);
286287
if (logbuf_set_forward_level (logbuf, level) < 0)
287288
goto done;
288-
} else if (!strcmp (name, "log-critical-level")) {
289+
} else if (streq (name, "log-critical-level")) {
289290
int level = strtol (val, NULL, 10);
290291
if (logbuf_set_critical_level (logbuf, level) < 0)
291292
goto done;
292-
} else if (!strcmp (name, "log-stderr-level")) {
293+
} else if (streq (name, "log-stderr-level")) {
293294
int level = strtol (val, NULL, 10);
294295
if (logbuf_set_stderr_level (logbuf, level) < 0)
295296
goto done;
296-
} else if (!strcmp (name, "log-stderr-mode")) {
297-
if (!strcmp (val, "leader"))
297+
} else if (streq (name, "log-stderr-mode")) {
298+
if (streq (val, "leader"))
298299
logbuf->stderr_mode = MODE_LEADER;
299-
else if (!strcmp (val, "local"))
300+
else if (streq (val, "local"))
300301
logbuf->stderr_mode = MODE_LOCAL;
301302
else {
302303
errno = EINVAL;
303304
goto done;
304305
}
305-
} else if (!strcmp (name, "log-ring-size")) {
306+
} else if (streq (name, "log-ring-size")) {
306307
int size = strtol (val, NULL, 10);
307308
if (logbuf_set_ring_size (logbuf, size) < 0)
308309
goto done;
309-
} else if (!strcmp (name, "log-filename")) {
310+
} else if (streq (name, "log-filename")) {
310311
if (logbuf_set_filename (logbuf, val) < 0)
311312
goto done;
312-
} else if (!strcmp (name, "log-level")) {
313+
} else if (streq (name, "log-level")) {
313314
int level = strtol (val, NULL, 10);
314315
if (logbuf_set_level (logbuf, level) < 0)
315316
goto done;

src/broker/modservice.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "src/common/libutil/errno_safe.h"
1717
#include "src/common/libfluxutil/method.h"
18+
#include "ccan/str/str.h"
1819

1920
#include "module.h"
2021
#include "modservice.h"
@@ -73,13 +74,13 @@ static void debug_cb (flux_t *h, flux_msg_handler_t *mh,
7374
}
7475
flux_aux_set (h, "flux::debug_flags", debug_flags, free);
7576
}
76-
if (!strcmp (op, "setbit"))
77+
if (streq (op, "setbit"))
7778
*debug_flags |= flags;
78-
else if (!strcmp (op, "clrbit"))
79+
else if (streq (op, "clrbit"))
7980
*debug_flags &= ~flags;
80-
else if (!strcmp (op, "set"))
81+
else if (streq (op, "set"))
8182
*debug_flags = flags;
82-
else if (!strcmp (op, "clr"))
83+
else if (streq (op, "clr"))
8384
*debug_flags = 0;
8485
else {
8586
errno = EPROTO;

0 commit comments

Comments
 (0)