/* 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;
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);
}
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;
};
enum {
- NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0]))
+ NUM_mode_info = ARRAY_SIZE(mode_info)
};
/* Control character settings */
};
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 */
{ ")" , RPAREN , PAREN },
};
-enum { NUM_OPS = sizeof(ops) / sizeof(ops[0]) };
#if ENABLE_FEATURE_TEST_64
typedef int64_t arith_t;
return op->op_num;
}
op++;
- } while (op < ops + NUM_OPS);
+ } while (op < ops + ARRAY_SIZE(ops));
return OPERAND;
}
/* 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
unsigned newsize, i, idx;
hash_item **newitems, *hi, *thi;
- if (hash->nprime == NPRIMES)
+ if (hash->nprime == ARRAY_SIZE(PRIMES))
return;
newsize = PRIMES[hash->nprime++];
{"[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);
#include <dmalloc.h>
#endif
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
#endif /* __LIBBUSYBOX_H__ */
#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)
{
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;
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];
}
#include "libbb.h"
#include <sys/syslog.h>
-#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
#ifndef CRONTABS
#define CRONTABS "/var/spool/cron/crontabs"
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;
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;
}
#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_" */
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;
}
/* 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;
static const struct address_family_t addr_inet6 = {
"inet6",
- sizeof(methods6) / sizeof(struct method_t),
+ ARRAY_SIZE(methods6),
methods6
};
#endif /* FEATURE_IFUPDOWN_IPV6 */
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);
}
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);
}
static const struct address_family_t addr_inet = {
"inet",
- sizeof(methods) / sizeof(methods[0]),
+ ARRAY_SIZE(methods),
methods
};
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;
}
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;
#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;
}
"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);
#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"
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];
}
#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];
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;
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);
}
/*
{ BUILTIN_REGULAR "wait", waitcmd },
};
-#define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0]))
#define COMMANDCMD (builtintab + 5 + \
2 * ENABLE_ASH_BUILTIN_TEST + \
struct builtincmd *bp;
bp = bsearch(
- name, builtintab, NUMBUILTINS, sizeof(builtintab[0]),
+ name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]),
pstrcmp
);
return bp;
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) {
{ "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);
/* 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) */
"Terminated",
};
-#define NSIGNAL (sizeof(signame)/sizeof(signame[0]))
+
struct res {
const char *r_name;
} else {
rv = WAITSIG(s);
if (rv != 0) {
- if (rv < NSIGNAL) {
+ if (rv < ARRAY_SIZE(signame)) {
if (signame[rv] != NULL) {
if (pid != lastpid) {
prn(pid);
}
if (WAITCORE(s))
prs(" - core dumped");
- if (rv >= NSIGNAL || signame[rv])
+ if (rv >= ARRAY_SIZE(signame) || signame[rv])
prs("\n");
rv = -1;
} else
# 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 */
"floppy",
0
};
-#define BSD_DKMAXTYPES (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)
+
/*
* Filesystem type and version.
"\x10" "AdvFS", /* BSD_FS_ADVFS */
NULL
};
-#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
/*
#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);
);
}
- 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);
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))
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) ? " " : "",
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;
}
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");
{"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)
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;
}
}
// 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);