diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-25 10:55:35 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-25 10:55:35 +0000 |
commit | 80b8b39899a09c7516920cda5fd343b3086d4824 (patch) | |
tree | aa9903fd6b64d19c5f640fa302272d85c92b204e | |
parent | 1399282b47bb218132a554cbe5b2b0ce4dcc055f (diff) | |
download | busybox-w32-80b8b39899a09c7516920cda5fd343b3086d4824.tar.gz busybox-w32-80b8b39899a09c7516920cda5fd343b3086d4824.tar.bz2 busybox-w32-80b8b39899a09c7516920cda5fd343b3086d4824.zip |
Consolidate ARRAY_SIZE macro; remove one unneeded global var (walter harms <wharms@bfs.de>)
-rw-r--r-- | applets/applets.c | 3 | ||||
-rw-r--r-- | coreutils/od_bloaty.c | 2 | ||||
-rw-r--r-- | coreutils/stty.c | 4 | ||||
-rw-r--r-- | coreutils/test.c | 3 | ||||
-rw-r--r-- | editors/awk.c | 4 | ||||
-rw-r--r-- | editors/vi.c | 3 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/speed_table.c | 2 | ||||
-rw-r--r-- | libbb/u_signal_names.c | 4 | ||||
-rw-r--r-- | miscutils/crond.c | 5 | ||||
-rw-r--r-- | modutils/insmod.c | 4 | ||||
-rw-r--r-- | networking/httpd.c | 5 | ||||
-rw-r--r-- | networking/ifconfig.c | 2 | ||||
-rw-r--r-- | networking/ifupdown.c | 12 | ||||
-rw-r--r-- | networking/libiproute/ll_proto.c | 4 | ||||
-rw-r--r-- | networking/libiproute/ll_types.c | 2 | ||||
-rw-r--r-- | networking/tftp.c | 4 | ||||
-rw-r--r-- | procps/ps.c | 4 | ||||
-rw-r--r-- | shell/ash.c | 13 | ||||
-rw-r--r-- | shell/hush.c | 4 | ||||
-rw-r--r-- | shell/lash.c | 4 | ||||
-rw-r--r-- | shell/msh.c | 6 | ||||
-rw-r--r-- | util-linux/fdisk.c | 2 | ||||
-rw-r--r-- | util-linux/fdisk_osf.c | 7 | ||||
-rw-r--r-- | util-linux/fdisk_sun.c | 10 | ||||
-rw-r--r-- | util-linux/mount.c | 5 |
26 files changed, 55 insertions, 66 deletions
diff --git a/applets/applets.c b/applets/applets.c index cff792fb7..57c972f79 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -47,7 +47,6 @@ static const char usage_messages[] = "" | |||
47 | /* Define struct bb_applet applets[] */ | 47 | /* Define struct bb_applet applets[] */ |
48 | #include "applets.h" | 48 | #include "applets.h" |
49 | /* The -1 arises because of the {0,NULL,0,-1} entry. */ | 49 | /* The -1 arises because of the {0,NULL,0,-1} entry. */ |
50 | const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1; | ||
51 | 50 | ||
52 | const struct bb_applet *current_applet; | 51 | const struct bb_applet *current_applet; |
53 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; | 52 | const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; |
@@ -488,7 +487,7 @@ static int applet_name_compare(const void *name, const void *vapplet) | |||
488 | const struct bb_applet *find_applet_by_name(const char *name) | 487 | const struct bb_applet *find_applet_by_name(const char *name) |
489 | { | 488 | { |
490 | /* Do a binary search to find the applet entry given the name. */ | 489 | /* Do a binary search to find the applet entry given the name. */ |
491 | return bsearch(name, applets, NUM_APPLETS, sizeof(applets[0]), | 490 | return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]), |
492 | applet_name_compare); | 491 | applet_name_compare); |
493 | } | 492 | } |
494 | 493 | ||
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c index 325085626..af5eba9ce 100644 --- a/coreutils/od_bloaty.c +++ b/coreutils/od_bloaty.c | |||
@@ -158,7 +158,7 @@ static const signed char width_bytes[] = { | |||
158 | initializer in the width_bytes array. */ | 158 | initializer in the width_bytes array. */ |
159 | struct dummy { | 159 | struct dummy { |
160 | int assert_width_bytes_matches_size_spec_decl | 160 | int assert_width_bytes_matches_size_spec_decl |
161 | [sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS ? 1 : -1]; | 161 | [ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1]; |
162 | }; | 162 | }; |
163 | 163 | ||
164 | static size_t string_min; | 164 | static size_t string_min; |
diff --git a/coreutils/stty.c b/coreutils/stty.c index e6d054ff2..0983532cf 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -319,7 +319,7 @@ static const struct mode_info mode_info[] = { | |||
319 | }; | 319 | }; |
320 | 320 | ||
321 | enum { | 321 | enum { |
322 | NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0])) | 322 | NUM_mode_info = ARRAY_SIZE(mode_info) |
323 | }; | 323 | }; |
324 | 324 | ||
325 | /* Control character settings */ | 325 | /* Control character settings */ |
@@ -371,7 +371,7 @@ static const struct control_info control_info[] = { | |||
371 | }; | 371 | }; |
372 | 372 | ||
373 | enum { | 373 | enum { |
374 | NUM_control_info = (sizeof(control_info) / sizeof(control_info[0])) | 374 | NUM_control_info = ARRAY_SIZE(control_info) |
375 | }; | 375 | }; |
376 | 376 | ||
377 | /* The width of the screen, for output wrapping */ | 377 | /* The width of the screen, for output wrapping */ |
diff --git a/coreutils/test.c b/coreutils/test.c index 36fb38a64..7b87a42f9 100644 --- a/coreutils/test.c +++ b/coreutils/test.c | |||
@@ -146,7 +146,6 @@ static const struct t_op { | |||
146 | { ")" , RPAREN , PAREN }, | 146 | { ")" , RPAREN , PAREN }, |
147 | }; | 147 | }; |
148 | 148 | ||
149 | enum { NUM_OPS = sizeof(ops) / sizeof(ops[0]) }; | ||
150 | 149 | ||
151 | #if ENABLE_FEATURE_TEST_64 | 150 | #if ENABLE_FEATURE_TEST_64 |
152 | typedef int64_t arith_t; | 151 | typedef int64_t arith_t; |
@@ -471,7 +470,7 @@ static enum token t_lex(char *s) | |||
471 | return op->op_num; | 470 | return op->op_num; |
472 | } | 471 | } |
473 | op++; | 472 | op++; |
474 | } while (op < ops + NUM_OPS); | 473 | } while (op < ops + ARRAY_SIZE(ops)); |
475 | 474 | ||
476 | return OPERAND; | 475 | return OPERAND; |
477 | } | 476 | } |
diff --git a/editors/awk.c b/editors/awk.c index 90ba64348..940a7948e 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -390,7 +390,7 @@ static const char vValues[] = | |||
390 | /* hash size may grow to these values */ | 390 | /* hash size may grow to these values */ |
391 | #define FIRST_PRIME 61; | 391 | #define FIRST_PRIME 61; |
392 | static const unsigned PRIMES[] = { 251, 1021, 4093, 16381, 65521 }; | 392 | static const unsigned PRIMES[] = { 251, 1021, 4093, 16381, 65521 }; |
393 | enum { NPRIMES = sizeof(PRIMES) / sizeof(PRIMES[0]) }; | 393 | |
394 | 394 | ||
395 | 395 | ||
396 | /* Globals. Split in two parts so that first one is addressed | 396 | /* Globals. Split in two parts so that first one is addressed |
@@ -570,7 +570,7 @@ static void hash_rebuild(xhash *hash) | |||
570 | unsigned newsize, i, idx; | 570 | unsigned newsize, i, idx; |
571 | hash_item **newitems, *hi, *thi; | 571 | hash_item **newitems, *hi, *thi; |
572 | 572 | ||
573 | if (hash->nprime == NPRIMES) | 573 | if (hash->nprime == ARRAY_SIZE(PRIMES)) |
574 | return; | 574 | return; |
575 | 575 | ||
576 | newsize = PRIMES[hash->nprime++]; | 576 | newsize = PRIMES[hash->nprime++]; |
diff --git a/editors/vi.c b/editors/vi.c index b961ca5b8..01d45e50e 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2230,8 +2230,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2230 | {"[13~", VI_K_FUN3}, // Function Key F3 | 2230 | {"[13~", VI_K_FUN3}, // Function Key F3 |
2231 | {"[14~", VI_K_FUN4}, // Function Key F4 | 2231 | {"[14~", VI_K_FUN4}, // Function Key F4 |
2232 | }; | 2232 | }; |
2233 | 2233 | enum { ESCCMDS_COUNT = ARRAY_SIZE(esccmds) }; | |
2234 | #define ESCCMDS_COUNT (sizeof(esccmds)/sizeof(struct esc_cmds)) | ||
2235 | 2234 | ||
2236 | alarm(0); // turn alarm OFF while we wait for input | 2235 | alarm(0); // turn alarm OFF while we wait for input |
2237 | fflush(stdout); | 2236 | fflush(stdout); |
diff --git a/include/libbb.h b/include/libbb.h index b7b0657b6..3cdf28fab 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1071,4 +1071,7 @@ extern const char bb_default_login_shell[]; | |||
1071 | #include <dmalloc.h> | 1071 | #include <dmalloc.h> |
1072 | #endif | 1072 | #endif |
1073 | 1073 | ||
1074 | |||
1075 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | ||
1076 | |||
1074 | #endif /* __LIBBUSYBOX_H__ */ | 1077 | #endif /* __LIBBUSYBOX_H__ */ |
diff --git a/libbb/speed_table.c b/libbb/speed_table.c index 6137b7731..0f0b33d3b 100644 --- a/libbb/speed_table.c +++ b/libbb/speed_table.c | |||
@@ -54,7 +54,7 @@ static const struct speed_map speeds[] = { | |||
54 | #endif | 54 | #endif |
55 | }; | 55 | }; |
56 | 56 | ||
57 | enum { NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map)) }; | 57 | enum { NUM_SPEEDS = ARRAY_SIZE(speeds) }; |
58 | 58 | ||
59 | unsigned int tty_baud_to_value(speed_t speed) | 59 | unsigned int tty_baud_to_value(speed_t speed) |
60 | { | 60 | { |
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index dc4c0b237..f8eaea76d 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -127,7 +127,7 @@ int get_signum(const char *name) | |||
127 | return i; | 127 | return i; |
128 | if (strncasecmp(name, "SIG", 3) == 0) | 128 | if (strncasecmp(name, "SIG", 3) == 0) |
129 | name += 3; | 129 | name += 3; |
130 | for (i = 0; i < sizeof(signals) / sizeof(signals[0]); i++) | 130 | for (i = 0; i < ARRAY_SIZE(signals); i++) |
131 | if (strcasecmp(name, signals[i]) == 0) | 131 | if (strcasecmp(name, signals[i]) == 0) |
132 | return i; | 132 | return i; |
133 | 133 | ||
@@ -152,7 +152,7 @@ int get_signum(const char *name) | |||
152 | 152 | ||
153 | const char *get_signame(int number) | 153 | const char *get_signame(int number) |
154 | { | 154 | { |
155 | if ((unsigned)number < sizeof(signals) / sizeof(signals[0])) { | 155 | if ((unsigned)number < ARRAY_SIZE(signals)) { |
156 | if (signals[number][0]) /* if it's not an empty str */ | 156 | if (signals[number][0]) /* if it's not an empty str */ |
157 | return signals[number]; | 157 | return signals[number]; |
158 | } | 158 | } |
diff --git a/miscutils/crond.c b/miscutils/crond.c index a490d417f..5653f6804 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include "libbb.h" | 15 | #include "libbb.h" |
16 | #include <sys/syslog.h> | 16 | #include <sys/syslog.h> |
17 | 17 | ||
18 | #define arysize(ary) (sizeof(ary)/sizeof((ary)[0])) | ||
19 | 18 | ||
20 | #ifndef CRONTABS | 19 | #ifndef CRONTABS |
21 | #define CRONTABS "/var/spool/cron/crontabs" | 20 | #define CRONTABS "/var/spool/cron/crontabs" |
@@ -468,13 +467,13 @@ static void FixDayDow(CronLine * line) | |||
468 | int weekUsed = 0; | 467 | int weekUsed = 0; |
469 | int daysUsed = 0; | 468 | int daysUsed = 0; |
470 | 469 | ||
471 | for (i = 0; i < (int)(arysize(line->cl_Dow)); ++i) { | 470 | for (i = 0; i < (int)(ARRAY_SIZE(line->cl_Dow)); ++i) { |
472 | if (line->cl_Dow[i] == 0) { | 471 | if (line->cl_Dow[i] == 0) { |
473 | weekUsed = 1; | 472 | weekUsed = 1; |
474 | break; | 473 | break; |
475 | } | 474 | } |
476 | } | 475 | } |
477 | for (i = 0; i < (int)(arysize(line->cl_Days)); ++i) { | 476 | for (i = 0; i < (int)(ARRAY_SIZE(line->cl_Days)); ++i) { |
478 | if (line->cl_Days[i] == 0) { | 477 | if (line->cl_Days[i] == 0) { |
479 | daysUsed = 1; | 478 | daysUsed = 1; |
480 | break; | 479 | break; |
diff --git a/modutils/insmod.c b/modutils/insmod.c index cba8dc4a0..8a6cc05dd 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
@@ -3632,7 +3632,7 @@ static int obj_gpl_license(struct obj_file *f, const char **license) | |||
3632 | int i; | 3632 | int i; |
3633 | if (license) | 3633 | if (license) |
3634 | *license = value+1; | 3634 | *license = value+1; |
3635 | for (i = 0; i < sizeof(gpl_licenses)/sizeof(gpl_licenses[0]); ++i) { | 3635 | for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) { |
3636 | if (strcmp(value+1, gpl_licenses[i]) == 0) | 3636 | if (strcmp(value+1, gpl_licenses[i]) == 0) |
3637 | return 0; | 3637 | return 0; |
3638 | } | 3638 | } |
@@ -3833,7 +3833,7 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename, | |||
3833 | #endif /* _NOT_SUPPORTED_ */ | 3833 | #endif /* _NOT_SUPPORTED_ */ |
3834 | /* tag the desired sections if size is non-zero */ | 3834 | /* tag the desired sections if size is non-zero */ |
3835 | 3835 | ||
3836 | for (i = 0; i < sizeof(section_names)/sizeof(section_names[0]); ++i) { | 3836 | for (i = 0; i < ARRAY_SIZE(section_names); ++i) { |
3837 | sec = obj_find_section(f, section_names[i]); | 3837 | sec = obj_find_section(f, section_names[i]); |
3838 | if (sec && sec->header.sh_size) { | 3838 | if (sec && sec->header.sh_size) { |
3839 | l = sizeof(symprefix)+ /* "__insmod_" */ | 3839 | l = sizeof(symprefix)+ /* "__insmod_" */ |
diff --git a/networking/httpd.c b/networking/httpd.c index 8c0a83e52..383a00635 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -878,11 +878,8 @@ static int sendHeaders(HttpResponseNum responseNum) | |||
878 | time_t timer = time(0); | 878 | time_t timer = time(0); |
879 | char timeStr[80]; | 879 | char timeStr[80]; |
880 | int len; | 880 | int len; |
881 | enum { | ||
882 | numNames = sizeof(httpResponseNames) / sizeof(httpResponseNames[0]) | ||
883 | }; | ||
884 | 881 | ||
885 | for (i = 0; i < numNames; i++) { | 882 | for (i = 0; i < ARRAY_SIZE(httpResponseNames); i++) { |
886 | if (httpResponseNames[i].type == responseNum) { | 883 | if (httpResponseNames[i].type == responseNum) { |
887 | responseString = httpResponseNames[i].name; | 884 | responseString = httpResponseNames[i].name; |
888 | infoString = httpResponseNames[i].info; | 885 | infoString = httpResponseNames[i].info; |
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 5742399c5..5e11b2b7c 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c | |||
@@ -337,7 +337,7 @@ int ifconfig_main(int argc, char **argv) | |||
337 | } | 337 | } |
338 | 338 | ||
339 | /* We fell through, so treat as possible hostname. */ | 339 | /* We fell through, so treat as possible hostname. */ |
340 | a1op = Arg1Opt + (sizeof(Arg1Opt) / sizeof(Arg1Opt[0])) - 1; | 340 | a1op = Arg1Opt + ARRAY_SIZE(Arg1Opt) - 1; |
341 | mask = op->arg_flags; | 341 | mask = op->arg_flags; |
342 | goto HOSTNAME; | 342 | goto HOSTNAME; |
343 | 343 | ||
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 2b748f11d..8843184bf 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -375,7 +375,7 @@ static const struct method_t methods6[] = { | |||
375 | 375 | ||
376 | static const struct address_family_t addr_inet6 = { | 376 | static const struct address_family_t addr_inet6 = { |
377 | "inet6", | 377 | "inet6", |
378 | sizeof(methods6) / sizeof(struct method_t), | 378 | ARRAY_SIZE(methods6), |
379 | methods6 | 379 | methods6 |
380 | }; | 380 | }; |
381 | #endif /* FEATURE_IFUPDOWN_IPV6 */ | 381 | #endif /* FEATURE_IFUPDOWN_IPV6 */ |
@@ -471,8 +471,8 @@ static const struct dhcp_client_t ext_dhcp_clients[] = { | |||
471 | static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) | 471 | static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) |
472 | { | 472 | { |
473 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP | 473 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
474 | int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]); | 474 | int i ; |
475 | for (i = 0; i < nclients; i++) { | 475 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { |
476 | if (exists_execable(ext_dhcp_clients[i].name)) | 476 | if (exists_execable(ext_dhcp_clients[i].name)) |
477 | return execute(ext_dhcp_clients[i].startcmd, ifd, exec); | 477 | return execute(ext_dhcp_clients[i].startcmd, ifd, exec); |
478 | } | 478 | } |
@@ -490,8 +490,8 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec) | |||
490 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) | 490 | static int dhcp_down(struct interface_defn_t *ifd, execfn *exec) |
491 | { | 491 | { |
492 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP | 492 | #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
493 | int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]); | 493 | int i ; |
494 | for (i = 0; i < nclients; i++) { | 494 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { |
495 | if (exists_execable(ext_dhcp_clients[i].name)) | 495 | if (exists_execable(ext_dhcp_clients[i].name)) |
496 | return execute(ext_dhcp_clients[i].stopcmd, ifd, exec); | 496 | return execute(ext_dhcp_clients[i].stopcmd, ifd, exec); |
497 | } | 497 | } |
@@ -551,7 +551,7 @@ static const struct method_t methods[] = { | |||
551 | 551 | ||
552 | static const struct address_family_t addr_inet = { | 552 | static const struct address_family_t addr_inet = { |
553 | "inet", | 553 | "inet", |
554 | sizeof(methods) / sizeof(methods[0]), | 554 | ARRAY_SIZE(methods), |
555 | methods | 555 | methods |
556 | }; | 556 | }; |
557 | 557 | ||
diff --git a/networking/libiproute/ll_proto.c b/networking/libiproute/ll_proto.c index 10d749881..4e62e876e 100644 --- a/networking/libiproute/ll_proto.c +++ b/networking/libiproute/ll_proto.c | |||
@@ -96,7 +96,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len) | |||
96 | 96 | ||
97 | id = ntohs(id); | 97 | id = ntohs(id); |
98 | 98 | ||
99 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | 99 | for (i=0; i < ARRAY_SIZE(llproto_names); i++) { |
100 | if (llproto_names[i].id == id) | 100 | if (llproto_names[i].id == id) |
101 | return llproto_names[i].name; | 101 | return llproto_names[i].name; |
102 | } | 102 | } |
@@ -107,7 +107,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len) | |||
107 | int ll_proto_a2n(unsigned short *id, char *buf) | 107 | int ll_proto_a2n(unsigned short *id, char *buf) |
108 | { | 108 | { |
109 | int i; | 109 | int i; |
110 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { | 110 | for (i=0; i < ARRAY_SIZE(llproto_names); i++) { |
111 | if (strcasecmp(llproto_names[i].name, buf) == 0) { | 111 | if (strcasecmp(llproto_names[i].name, buf) == 0) { |
112 | *id = htons(llproto_names[i].id); | 112 | *id = htons(llproto_names[i].id); |
113 | return 0; | 113 | return 0; |
diff --git a/networking/libiproute/ll_types.c b/networking/libiproute/ll_types.c index 5d2843b14..84fd628cb 100644 --- a/networking/libiproute/ll_types.c +++ b/networking/libiproute/ll_types.c | |||
@@ -108,7 +108,7 @@ __PF(VOID,void) | |||
108 | #undef __PF | 108 | #undef __PF |
109 | 109 | ||
110 | int i; | 110 | int i; |
111 | for (i = 0; i < sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) { | 111 | for (i = 0; i < ARRAY_SIZE(arphrd_names); i++) { |
112 | if (arphrd_names[i].type == type) | 112 | if (arphrd_names[i].type == type) |
113 | return arphrd_names[i].name; | 113 | return arphrd_names[i].name; |
114 | } | 114 | } |
diff --git a/networking/tftp.c b/networking/tftp.c index 8517830b7..b20486cc1 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -280,13 +280,13 @@ static int tftp( USE_GETPUT(const int cmd,) | |||
280 | "no such user", | 280 | "no such user", |
281 | "bad option", | 281 | "bad option", |
282 | }; | 282 | }; |
283 | enum { NUM_ERRCODE = sizeof(errcode_str) / sizeof(errcode_str[0]) }; | 283 | |
284 | const char *msg = ""; | 284 | const char *msg = ""; |
285 | 285 | ||
286 | if (rbuf[4] != '\0') { | 286 | if (rbuf[4] != '\0') { |
287 | msg = &rbuf[4]; | 287 | msg = &rbuf[4]; |
288 | rbuf[tftp_bufsize - 1] = '\0'; | 288 | rbuf[tftp_bufsize - 1] = '\0'; |
289 | } else if (recv_blk < NUM_ERRCODE) { | 289 | } else if (recv_blk < ARRAY_SIZE(errcode_str)) { |
290 | msg = errcode_str[recv_blk]; | 290 | msg = errcode_str[recv_blk]; |
291 | } | 291 | } |
292 | bb_error_msg("server error: (%u) %s", recv_blk, msg); | 292 | bb_error_msg("server error: (%u) %s", recv_blk, msg); |
diff --git a/procps/ps.c b/procps/ps.c index fd53eca5b..003e8eacd 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -134,8 +134,6 @@ static const ps_out_t out_spec[] = { | |||
134 | #endif | 134 | #endif |
135 | }; | 135 | }; |
136 | 136 | ||
137 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) | ||
138 | |||
139 | #if ENABLE_SELINUX | 137 | #if ENABLE_SELINUX |
140 | #define SELINIX_O_PREFIX "label," | 138 | #define SELINIX_O_PREFIX "label," |
141 | #define DEFAULT_O_STR SELINIX_O_PREFIX "pid,user" /* TODO: ,vsz,stat */ ",args" | 139 | #define DEFAULT_O_STR SELINIX_O_PREFIX "pid,user" /* TODO: ,vsz,stat */ ",args" |
@@ -171,7 +169,7 @@ static ps_out_t* new_out_t(void) | |||
171 | static const ps_out_t* find_out_spec(const char *name) | 169 | static const ps_out_t* find_out_spec(const char *name) |
172 | { | 170 | { |
173 | int i; | 171 | int i; |
174 | for (i = 0; i < VEC_SIZE(out_spec); i++) { | 172 | for (i = 0; i < ARRAY_SIZE(out_spec); i++) { |
175 | if (!strcmp(name, out_spec[i].name)) | 173 | if (!strcmp(name, out_spec[i].name)) |
176 | return &out_spec[i]; | 174 | return &out_spec[i]; |
177 | } | 175 | } |
diff --git a/shell/ash.c b/shell/ash.c index b54f66609..d9fe64121 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -101,7 +101,7 @@ static const char *const optletters_optnames[] = { | |||
101 | #define optletters(n) optletters_optnames[(n)][0] | 101 | #define optletters(n) optletters_optnames[(n)][0] |
102 | #define optnames(n) (&optletters_optnames[(n)][1]) | 102 | #define optnames(n) (&optletters_optnames[(n)][1]) |
103 | 103 | ||
104 | #define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0])) | 104 | enum { NOPTS = ARRAY_SIZE(optletters_optnames) }; |
105 | 105 | ||
106 | static char optlist[NOPTS]; | 106 | static char optlist[NOPTS]; |
107 | 107 | ||
@@ -1837,7 +1837,7 @@ initvar(void) | |||
1837 | vps1.text = "PS1=# "; | 1837 | vps1.text = "PS1=# "; |
1838 | #endif | 1838 | #endif |
1839 | vp = varinit; | 1839 | vp = varinit; |
1840 | end = vp + sizeof(varinit) / sizeof(varinit[0]); | 1840 | end = vp + ARRAY_SIZE(varinit); |
1841 | do { | 1841 | do { |
1842 | vpp = hashvar(vp->text); | 1842 | vpp = hashvar(vp->text); |
1843 | vp->next = *vpp; | 1843 | vp->next = *vpp; |
@@ -6876,8 +6876,8 @@ static const char *const * | |||
6876 | findkwd(const char *s) | 6876 | findkwd(const char *s) |
6877 | { | 6877 | { |
6878 | return bsearch(s, tokname_array + KWDOFFSET, | 6878 | return bsearch(s, tokname_array + KWDOFFSET, |
6879 | (sizeof(tokname_array) / sizeof(char *)) - KWDOFFSET, | 6879 | ARRAY_SIZE(tokname_array) - KWDOFFSET, |
6880 | sizeof(char *), pstrcmp); | 6880 | sizeof(tokname_array[0]), pstrcmp); |
6881 | } | 6881 | } |
6882 | 6882 | ||
6883 | /* | 6883 | /* |
@@ -8094,7 +8094,6 @@ static const struct builtincmd builtintab[] = { | |||
8094 | { BUILTIN_REGULAR "wait", waitcmd }, | 8094 | { BUILTIN_REGULAR "wait", waitcmd }, |
8095 | }; | 8095 | }; |
8096 | 8096 | ||
8097 | #define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0])) | ||
8098 | 8097 | ||
8099 | #define COMMANDCMD (builtintab + 5 + \ | 8098 | #define COMMANDCMD (builtintab + 5 + \ |
8100 | 2 * ENABLE_ASH_BUILTIN_TEST + \ | 8099 | 2 * ENABLE_ASH_BUILTIN_TEST + \ |
@@ -8116,7 +8115,7 @@ find_builtin(const char *name) | |||
8116 | struct builtincmd *bp; | 8115 | struct builtincmd *bp; |
8117 | 8116 | ||
8118 | bp = bsearch( | 8117 | bp = bsearch( |
8119 | name, builtintab, NUMBUILTINS, sizeof(builtintab[0]), | 8118 | name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]), |
8120 | pstrcmp | 8119 | pstrcmp |
8121 | ); | 8120 | ); |
8122 | return bp; | 8121 | return bp; |
@@ -11255,7 +11254,7 @@ helpcmd(int argc, char **argv) | |||
11255 | int col, i; | 11254 | int col, i; |
11256 | 11255 | ||
11257 | out1fmt("\nBuilt-in commands:\n-------------------\n"); | 11256 | out1fmt("\nBuilt-in commands:\n-------------------\n"); |
11258 | for (col = 0, i = 0; i < NUMBUILTINS; i++) { | 11257 | for (col = 0, i = 0; i < ARRAY_SIZE(builtintab) ; i++) { |
11259 | col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), | 11258 | col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '), |
11260 | builtintab[i].name + 1); | 11259 | builtintab[i].name + 1); |
11261 | if (col > 60) { | 11260 | if (col > 60) { |
diff --git a/shell/hush.c b/shell/hush.c index a446bbeb2..275b69ef3 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2889,10 +2889,10 @@ static int reserved_word(o_string *dest, struct p_context *ctx) | |||
2889 | { "done", RES_DONE, FLAG_END } | 2889 | { "done", RES_DONE, FLAG_END } |
2890 | #endif | 2890 | #endif |
2891 | }; | 2891 | }; |
2892 | enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) }; | 2892 | |
2893 | const struct reserved_combo *r; | 2893 | const struct reserved_combo *r; |
2894 | 2894 | ||
2895 | for (r = reserved_list; r < reserved_list + NRES; r++) { | 2895 | for (r = reserved_list; r < reserved_list + ARRAY_SIZE(reserved_list); r++) { |
2896 | if (strcmp(dest->data, r->literal) != 0) | 2896 | if (strcmp(dest->data, r->literal) != 0) |
2897 | continue; | 2897 | continue; |
2898 | debug_printf("found reserved word %s, code %d\n", r->literal, r->code); | 2898 | debug_printf("found reserved word %s, code %d\n", r->literal, r->code); |
diff --git a/shell/lash.c b/shell/lash.c index 4e8b23776..e5c7ef670 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -146,8 +146,8 @@ static const struct built_in_command bltins[] = { | |||
146 | /* to do: add ulimit */ | 146 | /* to do: add ulimit */ |
147 | }; | 147 | }; |
148 | 148 | ||
149 | #define VEC_SIZE(v) (sizeof(v)/sizeof(v[0])) | 149 | |
150 | #define VEC_LAST(v) v[VEC_SIZE(v)-1] | 150 | #define VEC_LAST(v) v[ARRAY_SIZE(v)-1] |
151 | 151 | ||
152 | 152 | ||
153 | static int shell_context; /* Type prompt trigger (PS1 or PS2) */ | 153 | static int shell_context; /* Type prompt trigger (PS1 or PS2) */ |
diff --git a/shell/msh.c b/shell/msh.c index 2328e0734..effdc0107 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -596,7 +596,7 @@ static const char * const signame[] = { | |||
596 | "Terminated", | 596 | "Terminated", |
597 | }; | 597 | }; |
598 | 598 | ||
599 | #define NSIGNAL (sizeof(signame)/sizeof(signame[0])) | 599 | |
600 | 600 | ||
601 | struct res { | 601 | struct res { |
602 | const char *r_name; | 602 | const char *r_name; |
@@ -2997,7 +2997,7 @@ static int waitfor(int lastpid, int canintr) | |||
2997 | } else { | 2997 | } else { |
2998 | rv = WAITSIG(s); | 2998 | rv = WAITSIG(s); |
2999 | if (rv != 0) { | 2999 | if (rv != 0) { |
3000 | if (rv < NSIGNAL) { | 3000 | if (rv < ARRAY_SIZE(signame)) { |
3001 | if (signame[rv] != NULL) { | 3001 | if (signame[rv] != NULL) { |
3002 | if (pid != lastpid) { | 3002 | if (pid != lastpid) { |
3003 | prn(pid); | 3003 | prn(pid); |
@@ -3016,7 +3016,7 @@ static int waitfor(int lastpid, int canintr) | |||
3016 | } | 3016 | } |
3017 | if (WAITCORE(s)) | 3017 | if (WAITCORE(s)) |
3018 | prs(" - core dumped"); | 3018 | prs(" - core dumped"); |
3019 | if (rv >= NSIGNAL || signame[rv]) | 3019 | if (rv >= ARRAY_SIZE(signame) || signame[rv]) |
3020 | prs("\n"); | 3020 | prs("\n"); |
3021 | rv = -1; | 3021 | rv = -1; |
3022 | } else | 3022 | } else |
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 4ecbadf78..870789112 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -20,8 +20,6 @@ | |||
20 | # define USE_FEATURE_FDISK_BLKSIZE(a) | 20 | # define USE_FEATURE_FDISK_BLKSIZE(a) |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | #define SIZE(a) (sizeof(a)/sizeof((a)[0])) | ||
24 | |||
25 | #define DEFAULT_SECTOR_SIZE 512 | 23 | #define DEFAULT_SECTOR_SIZE 512 |
26 | #define MAX_SECTOR_SIZE 2048 | 24 | #define MAX_SECTOR_SIZE 2048 |
27 | #define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */ | 25 | #define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */ |
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c index afb8459a2..9f0dc7fd3 100644 --- a/util-linux/fdisk_osf.c +++ b/util-linux/fdisk_osf.c | |||
@@ -163,7 +163,7 @@ static const char * const xbsd_dktypenames[] = { | |||
163 | "floppy", | 163 | "floppy", |
164 | 0 | 164 | 0 |
165 | }; | 165 | }; |
166 | #define BSD_DKMAXTYPES (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1) | 166 | |
167 | 167 | ||
168 | /* | 168 | /* |
169 | * Filesystem type and version. | 169 | * Filesystem type and version. |
@@ -219,7 +219,6 @@ static const char *const xbsd_fstypes[] = { | |||
219 | "\x10" "AdvFS", /* BSD_FS_ADVFS */ | 219 | "\x10" "AdvFS", /* BSD_FS_ADVFS */ |
220 | NULL | 220 | NULL |
221 | }; | 221 | }; |
222 | #define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1) | ||
223 | 222 | ||
224 | 223 | ||
225 | /* | 224 | /* |
@@ -509,7 +508,7 @@ xbsd_print_disklabel(int show_all) | |||
509 | #else | 508 | #else |
510 | printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0)); | 509 | printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0)); |
511 | #endif | 510 | #endif |
512 | if ((unsigned) lp->d_type < BSD_DKMAXTYPES) | 511 | if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1) |
513 | printf("type: %s\n", xbsd_dktypenames[lp->d_type]); | 512 | printf("type: %s\n", xbsd_dktypenames[lp->d_type]); |
514 | else | 513 | else |
515 | printf("type: %d\n", lp->d_type); | 514 | printf("type: %d\n", lp->d_type); |
@@ -571,7 +570,7 @@ xbsd_print_disklabel(int show_all) | |||
571 | ); | 570 | ); |
572 | } | 571 | } |
573 | 572 | ||
574 | if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES) | 573 | if ((unsigned) pp->p_fstype < ARRAY_SIZE(xbsd_fstypes)-1) |
575 | printf("%8.8s", xbsd_fstypes[pp->p_fstype]); | 574 | printf("%8.8s", xbsd_fstypes[pp->p_fstype]); |
576 | else | 575 | else |
577 | printf("%8x", pp->p_fstype); | 576 | printf("%8x", pp->p_fstype); |
diff --git a/util-linux/fdisk_sun.c b/util-linux/fdisk_sun.c index 2fa7b2b86..d4614fd4f 100644 --- a/util-linux/fdisk_sun.c +++ b/util-linux/fdisk_sun.c | |||
@@ -207,7 +207,7 @@ sun_autoconfigure_scsi(void) | |||
207 | if (!q) | 207 | if (!q) |
208 | break; | 208 | break; |
209 | *q = '\0'; | 209 | *q = '\0'; |
210 | for (i = 0; i < SIZE(sun_drives); i++) { | 210 | for (i = 0; i < ARRAY_SIZE(sun_drives); i++) { |
211 | if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor)) | 211 | if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor)) |
212 | continue; | 212 | continue; |
213 | if (!strstr(model, sun_drives[i].model)) | 213 | if (!strstr(model, sun_drives[i].model)) |
@@ -244,7 +244,7 @@ create_sunlabel(void) | |||
244 | puts("Drive type\n" | 244 | puts("Drive type\n" |
245 | " ? auto configure\n" | 245 | " ? auto configure\n" |
246 | " 0 custom (with hardware detected defaults)"); | 246 | " 0 custom (with hardware detected defaults)"); |
247 | for (i = 0; i < SIZE(sun_drives); i++) { | 247 | for (i = 0; i < ARRAY_SIZE(sun_drives); i++) { |
248 | printf(" %c %s%s%s\n", | 248 | printf(" %c %s%s%s\n", |
249 | i + 'a', sun_drives[i].vendor, | 249 | i + 'a', sun_drives[i].vendor, |
250 | (*sun_drives[i].vendor) ? " " : "", | 250 | (*sun_drives[i].vendor) ? " " : "", |
@@ -255,11 +255,11 @@ create_sunlabel(void) | |||
255 | if (c == '0') { | 255 | if (c == '0') { |
256 | break; | 256 | break; |
257 | } | 257 | } |
258 | if (c >= 'a' && c < 'a' + SIZE(sun_drives)) { | 258 | if (c >= 'a' && c < 'a' + ARRAY_SIZE(sun_drives)) { |
259 | p = sun_drives + c - 'a'; | 259 | p = sun_drives + c - 'a'; |
260 | break; | 260 | break; |
261 | } | 261 | } |
262 | if (c >= 'A' && c < 'A' + SIZE(sun_drives)) { | 262 | if (c >= 'A' && c < 'A' + ARRAY_SIZE(sun_drives)) { |
263 | p = sun_drives + c - 'A'; | 263 | p = sun_drives + c - 'A'; |
264 | break; | 264 | break; |
265 | } | 265 | } |
@@ -446,7 +446,7 @@ verify_sun(void) | |||
446 | else | 446 | else |
447 | array[i] = -1; | 447 | array[i] = -1; |
448 | } | 448 | } |
449 | qsort(array,SIZE(array),sizeof(array[0]), | 449 | qsort(array, ARRAY_SIZE(array), sizeof(array[0]), |
450 | (int (*)(const void *,const void *)) verify_sun_cmp); | 450 | (int (*)(const void *,const void *)) verify_sun_cmp); |
451 | if (array[0] == -1) { | 451 | if (array[0] == -1) { |
452 | printf("No partitions defined\n"); | 452 | printf("No partitions defined\n"); |
diff --git a/util-linux/mount.c b/util-linux/mount.c index fe2f1d969..4dd1a85a2 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -120,7 +120,6 @@ struct { | |||
120 | {"remount", MS_REMOUNT}, // action flag | 120 | {"remount", MS_REMOUNT}, // action flag |
121 | }; | 121 | }; |
122 | 122 | ||
123 | #define VECTOR_SIZE(v) (sizeof(v) / sizeof((v)[0])) | ||
124 | 123 | ||
125 | /* Append mount options to string */ | 124 | /* Append mount options to string */ |
126 | static void append_mount_options(char **oldopts, const char *newopts) | 125 | static void append_mount_options(char **oldopts, const char *newopts) |
@@ -168,7 +167,7 @@ static int parse_mount_options(char *options, char **unrecognized) | |||
168 | if (comma) *comma = 0; | 167 | if (comma) *comma = 0; |
169 | 168 | ||
170 | // Find this option in mount_options | 169 | // Find this option in mount_options |
171 | for (i = 0; i < VECTOR_SIZE(mount_options); i++) { | 170 | for (i = 0; i < ARRAY_SIZE(mount_options); i++) { |
172 | if (!strcasecmp(mount_options[i].name, options)) { | 171 | if (!strcasecmp(mount_options[i].name, options)) { |
173 | long fl = mount_options[i].flags; | 172 | long fl = mount_options[i].flags; |
174 | if (fl < 0) flags &= fl; | 173 | if (fl < 0) flags &= fl; |
@@ -177,7 +176,7 @@ static int parse_mount_options(char *options, char **unrecognized) | |||
177 | } | 176 | } |
178 | } | 177 | } |
179 | // If unrecognized not NULL, append unrecognized mount options */ | 178 | // If unrecognized not NULL, append unrecognized mount options */ |
180 | if (unrecognized && i == VECTOR_SIZE(mount_options)) { | 179 | if (unrecognized && i == ARRAY_SIZE(mount_options)) { |
181 | // Add it to strflags, to pass on to kernel | 180 | // Add it to strflags, to pass on to kernel |
182 | i = *unrecognized ? strlen(*unrecognized) : 0; | 181 | i = *unrecognized ? strlen(*unrecognized) : 0; |
183 | *unrecognized = xrealloc(*unrecognized, i+strlen(options)+2); | 182 | *unrecognized = xrealloc(*unrecognized, i+strlen(options)+2); |