Consolidate ARRAY_SIZE macro; remove one unneeded global var (walter harms <wharms...
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 25 Jun 2007 10:55:35 +0000 (10:55 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 25 Jun 2007 10:55:35 +0000 (10:55 -0000)
26 files changed:
applets/applets.c
coreutils/od_bloaty.c
coreutils/stty.c
coreutils/test.c
editors/awk.c
editors/vi.c
include/libbb.h
libbb/speed_table.c
libbb/u_signal_names.c
miscutils/crond.c
modutils/insmod.c
networking/httpd.c
networking/ifconfig.c
networking/ifupdown.c
networking/libiproute/ll_proto.c
networking/libiproute/ll_types.c
networking/tftp.c
procps/ps.c
shell/ash.c
shell/hush.c
shell/lash.c
shell/msh.c
util-linux/fdisk.c
util-linux/fdisk_osf.c
util-linux/fdisk_sun.c
util-linux/mount.c

index cff792fb718206bae4d0bae50dc791c175147b89..57c972f792e0aca24ee7f93e69f8e33397ef014c 100644 (file)
@@ -47,7 +47,6 @@ static const char usage_messages[] = ""
 /* Define struct bb_applet applets[] */
 #include "applets.h"
 /* The -1 arises because of the {0,NULL,0,-1} entry. */
-const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(applets[0]) - 1;
 
 const struct bb_applet *current_applet;
 const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
@@ -488,7 +487,7 @@ static int applet_name_compare(const void *name, const void *vapplet)
 const struct bb_applet *find_applet_by_name(const char *name)
 {
        /* Do a binary search to find the applet entry given the name. */
-       return bsearch(name, applets, NUM_APPLETS, sizeof(applets[0]),
+       return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
                                applet_name_compare);
 }
 
index 325085626b0ce40d88f628d21026b16b5ca29607..af5eba9cee2d854101a1767e0f583f5e18b8d0ee 100644 (file)
@@ -158,7 +158,7 @@ static const signed char width_bytes[] = {
    initializer in the width_bytes array.  */
 struct dummy {
        int assert_width_bytes_matches_size_spec_decl
-               [sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS ? 1 : -1];
+               [ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1];
 };
 
 static size_t string_min;
index e6d054ff2ae17989513e93e89760ef347894cbd0..0983532cf69b367506adcaec5870cfd44b5e9d59 100644 (file)
@@ -319,7 +319,7 @@ static const struct mode_info mode_info[] = {
 };
 
 enum {
-       NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0]))
+       NUM_mode_info = ARRAY_SIZE(mode_info)
 };
 
 /* Control character settings */
@@ -371,7 +371,7 @@ static const struct control_info control_info[] = {
 };
 
 enum {
-       NUM_control_info = (sizeof(control_info) / sizeof(control_info[0]))
+       NUM_control_info = ARRAY_SIZE(control_info)
 };
 
 /* The width of the screen, for output wrapping */
index 36fb38a64606e7b4874a3a803321d118ef5bd517..7b87a42f92a1b2221cf6b2cae682bff4c4b38b4d 100644 (file)
@@ -146,7 +146,6 @@ static const struct t_op {
        { ")"  , RPAREN , PAREN  },
 };
 
-enum { NUM_OPS = sizeof(ops) / sizeof(ops[0]) };
 
 #if ENABLE_FEATURE_TEST_64
 typedef int64_t arith_t;
@@ -471,7 +470,7 @@ static enum token t_lex(char *s)
                        return op->op_num;
                }
                op++;
-       } while (op < ops + NUM_OPS);
+       } while (op < ops + ARRAY_SIZE(ops));
 
        return OPERAND;
 }
index 90ba64348b9479d522ba048695733ec53835114e..940a7948ec17ae08f6643132fe92cf523d982258 100644 (file)
@@ -390,7 +390,7 @@ static const char vValues[] =
 /* hash size may grow to these values */
 #define FIRST_PRIME 61;
 static const unsigned PRIMES[] = { 251, 1021, 4093, 16381, 65521 };
-enum { NPRIMES = sizeof(PRIMES) / sizeof(PRIMES[0]) };
+
 
 
 /* Globals. Split in two parts so that first one is addressed
@@ -570,7 +570,7 @@ static void hash_rebuild(xhash *hash)
        unsigned newsize, i, idx;
        hash_item **newitems, *hi, *thi;
 
-       if (hash->nprime == NPRIMES)
+       if (hash->nprime == ARRAY_SIZE(PRIMES))
                return;
 
        newsize = PRIMES[hash->nprime++];
index b961ca5b87543fe958716ee4233a721e3a0472f4..01d45e50e18f27f130ad92af6d3e652ab950e25d 100644 (file)
@@ -2230,8 +2230,7 @@ static char readit(void)  // read (maybe cursor) key from stdin
                {"[13~", VI_K_FUN3},   // Function Key F3
                {"[14~", VI_K_FUN4},   // Function Key F4
        };
-
-#define ESCCMDS_COUNT (sizeof(esccmds)/sizeof(struct esc_cmds))
+       enum { ESCCMDS_COUNT = ARRAY_SIZE(esccmds) };
 
        alarm(0);       // turn alarm OFF while we wait for input
        fflush(stdout);
index b7b0657b6341a006df06d1be8f0242feeb9d7af9..3cdf28fabca99f71068c2d0357e80650994a82e1 100644 (file)
@@ -1071,4 +1071,7 @@ extern const char bb_default_login_shell[];
 #include <dmalloc.h>
 #endif
 
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
 #endif /* __LIBBUSYBOX_H__ */
index 6137b7731edbefeb6c00205b0cd9c963e2b33a14..0f0b33d3b27a4c07bcbbac9c49533ca1ca205e15 100644 (file)
@@ -54,7 +54,7 @@ static const struct speed_map speeds[] = {
 #endif
 };
 
-enum { NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map)) };
+enum { NUM_SPEEDS = ARRAY_SIZE(speeds) };
 
 unsigned int tty_baud_to_value(speed_t speed)
 {
index dc4c0b2371a177b07b7d35cb4937c4524315968f..f8eaea76da52311499d1e329e54d60dc6a08e095 100644 (file)
@@ -127,7 +127,7 @@ int get_signum(const char *name)
                return i;
        if (strncasecmp(name, "SIG", 3) == 0)
                name += 3;
-       for (i = 0; i < sizeof(signals) / sizeof(signals[0]); i++)
+       for (i = 0; i < ARRAY_SIZE(signals); i++)
                if (strcasecmp(name, signals[i]) == 0)
                        return i;
 
@@ -152,7 +152,7 @@ int get_signum(const char *name)
 
 const char *get_signame(int number)
 {
-       if ((unsigned)number < sizeof(signals) / sizeof(signals[0])) {
+       if ((unsigned)number < ARRAY_SIZE(signals)) {
                if (signals[number][0]) /* if it's not an empty str */
                        return signals[number];
        }
index a490d417fb9ca477fd6a4dd62b9656b7c17f7ac2..5653f680480722578c66ffe6ac471ce02780463d 100644 (file)
@@ -15,7 +15,6 @@
 #include "libbb.h"
 #include <sys/syslog.h>
 
-#define arysize(ary)    (sizeof(ary)/sizeof((ary)[0]))
 
 #ifndef CRONTABS
 #define CRONTABS        "/var/spool/cron/crontabs"
@@ -468,13 +467,13 @@ static void FixDayDow(CronLine * line)
        int weekUsed = 0;
        int daysUsed = 0;
 
-       for (i = 0; i < (int)(arysize(line->cl_Dow)); ++i) {
+       for (i = 0; i < (int)(ARRAY_SIZE(line->cl_Dow)); ++i) {
                if (line->cl_Dow[i] == 0) {
                        weekUsed = 1;
                        break;
                }
        }
-       for (i = 0; i < (int)(arysize(line->cl_Days)); ++i) {
+       for (i = 0; i < (int)(ARRAY_SIZE(line->cl_Days)); ++i) {
                if (line->cl_Days[i] == 0) {
                        daysUsed = 1;
                        break;
index cba8dc4a058a30615ca0dfc3be1d5e1bfe98bae9..8a6cc05ddff42866ea8cb2d7294ef711fa7399a0 100644 (file)
@@ -3632,7 +3632,7 @@ static int obj_gpl_license(struct obj_file *f, const char **license)
                                int i;
                                if (license)
                                        *license = value+1;
-                               for (i = 0; i < sizeof(gpl_licenses)/sizeof(gpl_licenses[0]); ++i) {
+                               for (i = 0; i < ARRAY_SIZE(gpl_licenses); ++i) {
                                        if (strcmp(value+1, gpl_licenses[i]) == 0)
                                                return 0;
                                }
@@ -3833,7 +3833,7 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
 #endif /* _NOT_SUPPORTED_ */
        /* tag the desired sections if size is non-zero */
 
-       for (i = 0; i < sizeof(section_names)/sizeof(section_names[0]); ++i) {
+       for (i = 0; i < ARRAY_SIZE(section_names); ++i) {
                sec = obj_find_section(f, section_names[i]);
                if (sec && sec->header.sh_size) {
                        l = sizeof(symprefix)+          /* "__insmod_" */
index 8c0a83e52da5640f14365aab699aa67c7a410d64..383a00635185f9213b07545a12b6575df2ba699b 100644 (file)
@@ -878,11 +878,8 @@ static int sendHeaders(HttpResponseNum responseNum)
        time_t timer = time(0);
        char timeStr[80];
        int len;
-       enum {
-               numNames = sizeof(httpResponseNames) / sizeof(httpResponseNames[0])
-       };
 
-       for (i = 0; i < numNames; i++) {
+       for (i = 0; i < ARRAY_SIZE(httpResponseNames); i++) {
                if (httpResponseNames[i].type == responseNum) {
                        responseString = httpResponseNames[i].name;
                        infoString = httpResponseNames[i].info;
index 5742399c5b460b6125513b4b860b33946305c94d..5e11b2b7c4ca45d90c074cc25626e7c3d5db59bf 100644 (file)
@@ -337,7 +337,7 @@ int ifconfig_main(int argc, char **argv)
                }
 
                /* We fell through, so treat as possible hostname. */
-               a1op = Arg1Opt + (sizeof(Arg1Opt) / sizeof(Arg1Opt[0])) - 1;
+               a1op = Arg1Opt + ARRAY_SIZE(Arg1Opt) - 1;
                mask = op->arg_flags;
                goto HOSTNAME;
 
index 2b748f11df7e2f023cfa6b3dfde85a31623b3b84..8843184bf6846cf065de1ee41f2e8c2a6fd80e0b 100644 (file)
@@ -375,7 +375,7 @@ static const struct method_t methods6[] = {
 
 static const struct address_family_t addr_inet6 = {
        "inet6",
-       sizeof(methods6) / sizeof(struct method_t),
+       ARRAY_SIZE(methods6),
        methods6
 };
 #endif /* FEATURE_IFUPDOWN_IPV6 */
@@ -471,8 +471,8 @@ static const struct dhcp_client_t ext_dhcp_clients[] = {
 static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
 {
 #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
-       int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
-       for (i = 0; i < nclients; i++) {
+       int i ;
+       for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
                if (exists_execable(ext_dhcp_clients[i].name))
                        return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
        }
@@ -490,8 +490,8 @@ static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
 static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
 {
 #if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
-       int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
-       for (i = 0; i < nclients; i++) {
+       int i ;
+       for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
                if (exists_execable(ext_dhcp_clients[i].name))
                        return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
        }
@@ -551,7 +551,7 @@ static const struct method_t methods[] = {
 
 static const struct address_family_t addr_inet = {
        "inet",
-       sizeof(methods) / sizeof(methods[0]),
+       ARRAY_SIZE(methods),
        methods
 };
 
index 10d749881cb4fef39465e09d2be2b6c76491bb87..4e62e876ee20b3624fbb728f2f9f4d78702ec8a5 100644 (file)
@@ -96,7 +96,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len)
 
        id = ntohs(id);
 
-       for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
+       for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
                 if (llproto_names[i].id == id)
                        return llproto_names[i].name;
        }
@@ -107,7 +107,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len)
 int ll_proto_a2n(unsigned short *id, char *buf)
 {
        int i;
-       for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
+       for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
                 if (strcasecmp(llproto_names[i].name, buf) == 0) {
                         *id = htons(llproto_names[i].id);
                         return 0;
index 5d2843b141a5b5c4b970b262797303093a4ba9f2..84fd628cba87c0203f282e1d6f0b2fc7a1e9aaa2 100644 (file)
@@ -108,7 +108,7 @@ __PF(VOID,void)
 #undef __PF
 
        int i;
-       for (i = 0; i < sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) {
+       for (i = 0; i < ARRAY_SIZE(arphrd_names); i++) {
                 if (arphrd_names[i].type == type)
                        return arphrd_names[i].name;
        }
index 8517830b7152c4289dce908ad77741cd84f6805d..b20486cc13b854fa422eaaa105a2b01a5e82f0a0 100644 (file)
@@ -280,13 +280,13 @@ static int tftp( USE_GETPUT(const int cmd,)
                                "no such user",
                                "bad option",
                        };
-                       enum { NUM_ERRCODE = sizeof(errcode_str) / sizeof(errcode_str[0]) };
+
                        const char *msg = "";
 
                        if (rbuf[4] != '\0') {
                                msg = &rbuf[4];
                                rbuf[tftp_bufsize - 1] = '\0';
-                       } else if (recv_blk < NUM_ERRCODE) {
+                       } else if (recv_blk < ARRAY_SIZE(errcode_str)) {
                                msg = errcode_str[recv_blk];
                        }
                        bb_error_msg("server error: (%u) %s", recv_blk, msg);
index fd53eca5b90297c4e4af3f140042dfdd2885be5e..003e8eacd9d34f49d3ad6aa5fe26ddf63aa1f413 100644 (file)
@@ -134,8 +134,6 @@ static const ps_out_t out_spec[] = {
 #endif
 };
 
-#define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) )
-
 #if ENABLE_SELINUX
 #define SELINIX_O_PREFIX "label,"
 #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)
 static const ps_out_t* find_out_spec(const char *name)
 {
        int i;
-       for (i = 0; i < VEC_SIZE(out_spec); i++) {
+       for (i = 0; i < ARRAY_SIZE(out_spec); i++) {
                if (!strcmp(name, out_spec[i].name))
                        return &out_spec[i];
        }
index b54f6660903ee0db3f7d120ceaa1e2ca466d3422..d9fe641219bb1212a6867fc34178b9f3e34a5e93 100644 (file)
@@ -101,7 +101,7 @@ static const char *const optletters_optnames[] = {
 #define optletters(n) optletters_optnames[(n)][0]
 #define optnames(n) (&optletters_optnames[(n)][1])
 
-#define NOPTS (sizeof(optletters_optnames)/sizeof(optletters_optnames[0]))
+enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
 
 static char optlist[NOPTS];
 
@@ -1837,7 +1837,7 @@ initvar(void)
                vps1.text = "PS1=# ";
 #endif
        vp = varinit;
-       end = vp + sizeof(varinit) / sizeof(varinit[0]);
+       end = vp + ARRAY_SIZE(varinit);
        do {
                vpp = hashvar(vp->text);
                vp->next = *vpp;
@@ -6876,8 +6876,8 @@ static const char *const *
 findkwd(const char *s)
 {
        return bsearch(s, tokname_array + KWDOFFSET,
-                       (sizeof(tokname_array) / sizeof(char *)) - KWDOFFSET,
-                       sizeof(char *), pstrcmp);
+                       ARRAY_SIZE(tokname_array) - KWDOFFSET,
+                       sizeof(tokname_array[0]), pstrcmp);
 }
 
 /*
@@ -8094,7 +8094,6 @@ static const struct builtincmd builtintab[] = {
        { BUILTIN_REGULAR       "wait", waitcmd },
 };
 
-#define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0]))
 
 #define COMMANDCMD (builtintab + 5 + \
        2 * ENABLE_ASH_BUILTIN_TEST + \
@@ -8116,7 +8115,7 @@ find_builtin(const char *name)
        struct builtincmd *bp;
 
        bp = bsearch(
-               name, builtintab, NUMBUILTINS, sizeof(builtintab[0]),
+               name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]),
                pstrcmp
        );
        return bp;
@@ -11255,7 +11254,7 @@ helpcmd(int argc, char **argv)
        int col, i;
 
        out1fmt("\nBuilt-in commands:\n-------------------\n");
-       for (col = 0, i = 0; i < NUMBUILTINS; i++) {
+       for (col = 0, i = 0; i < ARRAY_SIZE(builtintab) ; i++) {
                col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '),
                                        builtintab[i].name + 1);
                if (col > 60) {
index a446bbeb28cdb5ec005781e42555b0caf05d4135..275b69ef379e8aa6119e0d55cc802ef79deb3876 100644 (file)
@@ -2889,10 +2889,10 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
                { "done",  RES_DONE,  FLAG_END  }
 #endif
        };
-       enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) };
+
        const struct reserved_combo *r;
 
-       for (r = reserved_list; r < reserved_list + NRES; r++) {
+       for (r = reserved_list; r < reserved_list + ARRAY_SIZE(reserved_list); r++) {
                if (strcmp(dest->data, r->literal) != 0)
                        continue;
                debug_printf("found reserved word %s, code %d\n", r->literal, r->code);
index 4e8b23776c5c7844a54c358f0ea775bbef47e07f..e5c7ef670a6b58c6b0552ab74adc213bd1b56d9b 100644 (file)
@@ -146,8 +146,8 @@ static const struct built_in_command bltins[] = {
        /* to do: add ulimit */
 };
 
-#define VEC_SIZE(v) (sizeof(v)/sizeof(v[0]))
-#define VEC_LAST(v) v[VEC_SIZE(v)-1]
+
+#define VEC_LAST(v) v[ARRAY_SIZE(v)-1]
 
 
 static int shell_context;  /* Type prompt trigger (PS1 or PS2) */
index 2328e0734c1cc5b72b2d7d823c8da14a5fce2d2d..effdc0107ec08991122a01ab31036c37f9d742cb 100644 (file)
@@ -596,7 +596,7 @@ static const char * const signame[] = {
        "Terminated",
 };
 
-#define        NSIGNAL (sizeof(signame)/sizeof(signame[0]))
+
 
 struct res {
        const char *r_name;
@@ -2997,7 +2997,7 @@ static int waitfor(int lastpid, int canintr)
                } else {
                        rv = WAITSIG(s);
                        if (rv != 0) {
-                               if (rv < NSIGNAL) {
+                               if (rv < ARRAY_SIZE(signame)) {
                                        if (signame[rv] != NULL) {
                                                if (pid != lastpid) {
                                                        prn(pid);
@@ -3016,7 +3016,7 @@ static int waitfor(int lastpid, int canintr)
                                }
                                if (WAITCORE(s))
                                        prs(" - core dumped");
-                               if (rv >= NSIGNAL || signame[rv])
+                               if (rv >= ARRAY_SIZE(signame) || signame[rv])
                                        prs("\n");
                                rv = -1;
                        } else
index 4ecbadf7862f4976c241b3d75dec90619feb1e8c..870789112d244255e6565b02d7c54bf8c27d18d2 100644 (file)
@@ -20,8 +20,6 @@
 # define USE_FEATURE_FDISK_BLKSIZE(a)
 #endif
 
-#define SIZE(a) (sizeof(a)/sizeof((a)[0]))
-
 #define DEFAULT_SECTOR_SIZE     512
 #define MAX_SECTOR_SIZE 2048
 #define SECTOR_SIZE     512     /* still used in osf/sgi/sun code */
index afb8459a218fcefca67bbde64b554d4b2b59ee2b..9f0dc7fd3123a59cb4578674659f1e2b7df182a1 100644 (file)
@@ -163,7 +163,7 @@ static const char * const xbsd_dktypenames[] = {
        "floppy",
        0
 };
-#define BSD_DKMAXTYPES  (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)
+
 
 /*
  * Filesystem type and version.
@@ -219,7 +219,6 @@ static const char *const xbsd_fstypes[] = {
        "\x10" "AdvFS",             /* BSD_FS_ADVFS   */
        NULL
 };
-#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
 
 
 /*
@@ -509,7 +508,7 @@ xbsd_print_disklabel(int show_all)
 #else
                printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
 #endif
-               if ((unsigned) lp->d_type < BSD_DKMAXTYPES)
+               if ((unsigned) lp->d_type < ARRAY_SIZE(xbsd_dktypenames)-1)
                        printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
                else
                        printf("type: %d\n", lp->d_type);
@@ -571,7 +570,7 @@ xbsd_print_disklabel(int show_all)
                                );
                        }
 
-                       if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES)
+                       if ((unsigned) pp->p_fstype < ARRAY_SIZE(xbsd_fstypes)-1)
                                printf("%8.8s", xbsd_fstypes[pp->p_fstype]);
                        else
                                printf("%8x", pp->p_fstype);
index 2fa7b2b86441d1a32adf59faf20e4fc9900ad9f0..d4614fd4fa9c8d18f9372da7f29771e9673d4a7d 100644 (file)
@@ -207,7 +207,7 @@ sun_autoconfigure_scsi(void)
                if (!q)
                        break;
                *q = '\0';
-               for (i = 0; i < SIZE(sun_drives); i++) {
+               for (i = 0; i < ARRAY_SIZE(sun_drives); i++) {
                        if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor))
                                continue;
                        if (!strstr(model, sun_drives[i].model))
@@ -244,7 +244,7 @@ create_sunlabel(void)
                puts("Drive type\n"
                 "   ?   auto configure\n"
                 "   0   custom (with hardware detected defaults)");
-               for (i = 0; i < SIZE(sun_drives); i++) {
+               for (i = 0; i < ARRAY_SIZE(sun_drives); i++) {
                        printf("   %c   %s%s%s\n",
                                i + 'a', sun_drives[i].vendor,
                                (*sun_drives[i].vendor) ? " " : "",
@@ -255,11 +255,11 @@ create_sunlabel(void)
                        if (c == '0') {
                                break;
                        }
-                       if (c >= 'a' && c < 'a' + SIZE(sun_drives)) {
+                       if (c >= 'a' && c < 'a' + ARRAY_SIZE(sun_drives)) {
                                p = sun_drives + c - 'a';
                                break;
                        }
-                       if (c >= 'A' && c < 'A' + SIZE(sun_drives)) {
+                       if (c >= 'A' && c < 'A' + ARRAY_SIZE(sun_drives)) {
                                p = sun_drives + c - 'A';
                                break;
                        }
@@ -446,7 +446,7 @@ verify_sun(void)
                else
                        array[i] = -1;
        }
-       qsort(array,SIZE(array),sizeof(array[0]),
+       qsort(array, ARRAY_SIZE(array), sizeof(array[0]),
                (int (*)(const void *,const void *)) verify_sun_cmp);
        if (array[0] == -1) {
                printf("No partitions defined\n");
index fe2f1d9690622064b9ea2f918d7b6ea8508c0007..4dd1a85a21c22df885137202e3e076cd859df769 100644 (file)
@@ -120,7 +120,6 @@ struct {
        {"remount", MS_REMOUNT},  // action flag
 };
 
-#define VECTOR_SIZE(v) (sizeof(v) / sizeof((v)[0]))
 
 /* Append mount options to string */
 static void append_mount_options(char **oldopts, const char *newopts)
@@ -168,7 +167,7 @@ static int parse_mount_options(char *options, char **unrecognized)
                if (comma) *comma = 0;
 
                // Find this option in mount_options
-               for (i = 0; i < VECTOR_SIZE(mount_options); i++) {
+               for (i = 0; i < ARRAY_SIZE(mount_options); i++) {
                        if (!strcasecmp(mount_options[i].name, options)) {
                                long fl = mount_options[i].flags;
                                if (fl < 0) flags &= fl;
@@ -177,7 +176,7 @@ static int parse_mount_options(char *options, char **unrecognized)
                        }
                }
                // If unrecognized not NULL, append unrecognized mount options */
-               if (unrecognized && i == VECTOR_SIZE(mount_options)) {
+               if (unrecognized && i == ARRAY_SIZE(mount_options)) {
                        // Add it to strflags, to pass on to kernel
                        i = *unrecognized ? strlen(*unrecognized) : 0;
                        *unrecognized = xrealloc(*unrecognized, i+strlen(options)+2);