mirror of
https://github.com/sheumann/hush.git
synced 2024-10-11 10:23:41 +00:00
Consolidate ARRAY_SIZE macro; remove one unneeded global var (walter harms <wharms@bfs.de>)
This commit is contained in:
parent
1399282b47
commit
80b8b39899
@ -47,7 +47,6 @@ static const char usage_messages[] = ""
|
|||||||
/* Define struct bb_applet applets[] */
|
/* Define struct bb_applet applets[] */
|
||||||
#include "applets.h"
|
#include "applets.h"
|
||||||
/* The -1 arises because of the {0,NULL,0,-1} entry. */
|
/* 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 struct bb_applet *current_applet;
|
||||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
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)
|
const struct bb_applet *find_applet_by_name(const char *name)
|
||||||
{
|
{
|
||||||
/* Do a binary search to find the applet entry given the 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);
|
applet_name_compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ static const signed char width_bytes[] = {
|
|||||||
initializer in the width_bytes array. */
|
initializer in the width_bytes array. */
|
||||||
struct dummy {
|
struct dummy {
|
||||||
int assert_width_bytes_matches_size_spec_decl
|
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;
|
static size_t string_min;
|
||||||
|
@ -319,7 +319,7 @@ static const struct mode_info mode_info[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NUM_mode_info = (sizeof(mode_info) / sizeof(mode_info[0]))
|
NUM_mode_info = ARRAY_SIZE(mode_info)
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Control character settings */
|
/* Control character settings */
|
||||||
@ -371,7 +371,7 @@ static const struct control_info control_info[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
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 */
|
/* The width of the screen, for output wrapping */
|
||||||
|
@ -146,7 +146,6 @@ static const struct t_op {
|
|||||||
{ ")" , RPAREN , PAREN },
|
{ ")" , RPAREN , PAREN },
|
||||||
};
|
};
|
||||||
|
|
||||||
enum { NUM_OPS = sizeof(ops) / sizeof(ops[0]) };
|
|
||||||
|
|
||||||
#if ENABLE_FEATURE_TEST_64
|
#if ENABLE_FEATURE_TEST_64
|
||||||
typedef int64_t arith_t;
|
typedef int64_t arith_t;
|
||||||
@ -471,7 +470,7 @@ static enum token t_lex(char *s)
|
|||||||
return op->op_num;
|
return op->op_num;
|
||||||
}
|
}
|
||||||
op++;
|
op++;
|
||||||
} while (op < ops + NUM_OPS);
|
} while (op < ops + ARRAY_SIZE(ops));
|
||||||
|
|
||||||
return OPERAND;
|
return OPERAND;
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ static const char vValues[] =
|
|||||||
/* hash size may grow to these values */
|
/* hash size may grow to these values */
|
||||||
#define FIRST_PRIME 61;
|
#define FIRST_PRIME 61;
|
||||||
static const unsigned PRIMES[] = { 251, 1021, 4093, 16381, 65521 };
|
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
|
/* 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;
|
unsigned newsize, i, idx;
|
||||||
hash_item **newitems, *hi, *thi;
|
hash_item **newitems, *hi, *thi;
|
||||||
|
|
||||||
if (hash->nprime == NPRIMES)
|
if (hash->nprime == ARRAY_SIZE(PRIMES))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
newsize = PRIMES[hash->nprime++];
|
newsize = PRIMES[hash->nprime++];
|
||||||
|
@ -2230,8 +2230,7 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
{"[13~", VI_K_FUN3}, // Function Key F3
|
{"[13~", VI_K_FUN3}, // Function Key F3
|
||||||
{"[14~", VI_K_FUN4}, // Function Key F4
|
{"[14~", VI_K_FUN4}, // Function Key F4
|
||||||
};
|
};
|
||||||
|
enum { ESCCMDS_COUNT = ARRAY_SIZE(esccmds) };
|
||||||
#define ESCCMDS_COUNT (sizeof(esccmds)/sizeof(struct esc_cmds))
|
|
||||||
|
|
||||||
alarm(0); // turn alarm OFF while we wait for input
|
alarm(0); // turn alarm OFF while we wait for input
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -1071,4 +1071,7 @@ extern const char bb_default_login_shell[];
|
|||||||
#include <dmalloc.h>
|
#include <dmalloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
#endif /* __LIBBUSYBOX_H__ */
|
#endif /* __LIBBUSYBOX_H__ */
|
||||||
|
@ -54,7 +54,7 @@ static const struct speed_map speeds[] = {
|
|||||||
#endif
|
#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)
|
unsigned int tty_baud_to_value(speed_t speed)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +127,7 @@ int get_signum(const char *name)
|
|||||||
return i;
|
return i;
|
||||||
if (strncasecmp(name, "SIG", 3) == 0)
|
if (strncasecmp(name, "SIG", 3) == 0)
|
||||||
name += 3;
|
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)
|
if (strcasecmp(name, signals[i]) == 0)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ int get_signum(const char *name)
|
|||||||
|
|
||||||
const char *get_signame(int number)
|
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 */
|
if (signals[number][0]) /* if it's not an empty str */
|
||||||
return signals[number];
|
return signals[number];
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
|
||||||
#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
|
|
||||||
|
|
||||||
#ifndef CRONTABS
|
#ifndef CRONTABS
|
||||||
#define CRONTABS "/var/spool/cron/crontabs"
|
#define CRONTABS "/var/spool/cron/crontabs"
|
||||||
@ -468,13 +467,13 @@ static void FixDayDow(CronLine * line)
|
|||||||
int weekUsed = 0;
|
int weekUsed = 0;
|
||||||
int daysUsed = 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) {
|
if (line->cl_Dow[i] == 0) {
|
||||||
weekUsed = 1;
|
weekUsed = 1;
|
||||||
break;
|
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) {
|
if (line->cl_Days[i] == 0) {
|
||||||
daysUsed = 1;
|
daysUsed = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -3632,7 +3632,7 @@ static int obj_gpl_license(struct obj_file *f, const char **license)
|
|||||||
int i;
|
int i;
|
||||||
if (license)
|
if (license)
|
||||||
*license = value+1;
|
*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)
|
if (strcmp(value+1, gpl_licenses[i]) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3833,7 +3833,7 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
|
|||||||
#endif /* _NOT_SUPPORTED_ */
|
#endif /* _NOT_SUPPORTED_ */
|
||||||
/* tag the desired sections if size is non-zero */
|
/* 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]);
|
sec = obj_find_section(f, section_names[i]);
|
||||||
if (sec && sec->header.sh_size) {
|
if (sec && sec->header.sh_size) {
|
||||||
l = sizeof(symprefix)+ /* "__insmod_" */
|
l = sizeof(symprefix)+ /* "__insmod_" */
|
||||||
|
@ -878,11 +878,8 @@ static int sendHeaders(HttpResponseNum responseNum)
|
|||||||
time_t timer = time(0);
|
time_t timer = time(0);
|
||||||
char timeStr[80];
|
char timeStr[80];
|
||||||
int len;
|
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) {
|
if (httpResponseNames[i].type == responseNum) {
|
||||||
responseString = httpResponseNames[i].name;
|
responseString = httpResponseNames[i].name;
|
||||||
infoString = httpResponseNames[i].info;
|
infoString = httpResponseNames[i].info;
|
||||||
|
@ -337,7 +337,7 @@ int ifconfig_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We fell through, so treat as possible hostname. */
|
/* 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;
|
mask = op->arg_flags;
|
||||||
goto HOSTNAME;
|
goto HOSTNAME;
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ static const struct method_t methods6[] = {
|
|||||||
|
|
||||||
static const struct address_family_t addr_inet6 = {
|
static const struct address_family_t addr_inet6 = {
|
||||||
"inet6",
|
"inet6",
|
||||||
sizeof(methods6) / sizeof(struct method_t),
|
ARRAY_SIZE(methods6),
|
||||||
methods6
|
methods6
|
||||||
};
|
};
|
||||||
#endif /* FEATURE_IFUPDOWN_IPV6 */
|
#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)
|
static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
|
||||||
{
|
{
|
||||||
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
||||||
int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
|
int i ;
|
||||||
for (i = 0; i < nclients; i++) {
|
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||||
if (exists_execable(ext_dhcp_clients[i].name))
|
if (exists_execable(ext_dhcp_clients[i].name))
|
||||||
return execute(ext_dhcp_clients[i].startcmd, ifd, exec);
|
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)
|
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
||||||
{
|
{
|
||||||
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
#if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP
|
||||||
int i, nclients = sizeof(ext_dhcp_clients) / sizeof(ext_dhcp_clients[0]);
|
int i ;
|
||||||
for (i = 0; i < nclients; i++) {
|
for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) {
|
||||||
if (exists_execable(ext_dhcp_clients[i].name))
|
if (exists_execable(ext_dhcp_clients[i].name))
|
||||||
return execute(ext_dhcp_clients[i].stopcmd, ifd, exec);
|
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 = {
|
static const struct address_family_t addr_inet = {
|
||||||
"inet",
|
"inet",
|
||||||
sizeof(methods) / sizeof(methods[0]),
|
ARRAY_SIZE(methods),
|
||||||
methods
|
methods
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ const char * ll_proto_n2a(unsigned short id, char *buf, int len)
|
|||||||
|
|
||||||
id = ntohs(id);
|
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)
|
if (llproto_names[i].id == id)
|
||||||
return llproto_names[i].name;
|
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 ll_proto_a2n(unsigned short *id, char *buf)
|
||||||
{
|
{
|
||||||
int i;
|
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) {
|
if (strcasecmp(llproto_names[i].name, buf) == 0) {
|
||||||
*id = htons(llproto_names[i].id);
|
*id = htons(llproto_names[i].id);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -108,7 +108,7 @@ __PF(VOID,void)
|
|||||||
#undef __PF
|
#undef __PF
|
||||||
|
|
||||||
int i;
|
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)
|
if (arphrd_names[i].type == type)
|
||||||
return arphrd_names[i].name;
|
return arphrd_names[i].name;
|
||||||
}
|
}
|
||||||
|
@ -280,13 +280,13 @@ static int tftp( USE_GETPUT(const int cmd,)
|
|||||||
"no such user",
|
"no such user",
|
||||||
"bad option",
|
"bad option",
|
||||||
};
|
};
|
||||||
enum { NUM_ERRCODE = sizeof(errcode_str) / sizeof(errcode_str[0]) };
|
|
||||||
const char *msg = "";
|
const char *msg = "";
|
||||||
|
|
||||||
if (rbuf[4] != '\0') {
|
if (rbuf[4] != '\0') {
|
||||||
msg = &rbuf[4];
|
msg = &rbuf[4];
|
||||||
rbuf[tftp_bufsize - 1] = '\0';
|
rbuf[tftp_bufsize - 1] = '\0';
|
||||||
} else if (recv_blk < NUM_ERRCODE) {
|
} else if (recv_blk < ARRAY_SIZE(errcode_str)) {
|
||||||
msg = errcode_str[recv_blk];
|
msg = errcode_str[recv_blk];
|
||||||
}
|
}
|
||||||
bb_error_msg("server error: (%u) %s", recv_blk, msg);
|
bb_error_msg("server error: (%u) %s", recv_blk, msg);
|
||||||
|
@ -134,8 +134,6 @@ static const ps_out_t out_spec[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) )
|
|
||||||
|
|
||||||
#if ENABLE_SELINUX
|
#if ENABLE_SELINUX
|
||||||
#define SELINIX_O_PREFIX "label,"
|
#define SELINIX_O_PREFIX "label,"
|
||||||
#define DEFAULT_O_STR SELINIX_O_PREFIX "pid,user" /* TODO: ,vsz,stat */ ",args"
|
#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)
|
static const ps_out_t* find_out_spec(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
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))
|
if (!strcmp(name, out_spec[i].name))
|
||||||
return &out_spec[i];
|
return &out_spec[i];
|
||||||
}
|
}
|
||||||
|
13
shell/ash.c
13
shell/ash.c
@ -101,7 +101,7 @@ static const char *const optletters_optnames[] = {
|
|||||||
#define optletters(n) optletters_optnames[(n)][0]
|
#define optletters(n) optletters_optnames[(n)][0]
|
||||||
#define optnames(n) (&optletters_optnames[(n)][1])
|
#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];
|
static char optlist[NOPTS];
|
||||||
|
|
||||||
@ -1837,7 +1837,7 @@ initvar(void)
|
|||||||
vps1.text = "PS1=# ";
|
vps1.text = "PS1=# ";
|
||||||
#endif
|
#endif
|
||||||
vp = varinit;
|
vp = varinit;
|
||||||
end = vp + sizeof(varinit) / sizeof(varinit[0]);
|
end = vp + ARRAY_SIZE(varinit);
|
||||||
do {
|
do {
|
||||||
vpp = hashvar(vp->text);
|
vpp = hashvar(vp->text);
|
||||||
vp->next = *vpp;
|
vp->next = *vpp;
|
||||||
@ -6876,8 +6876,8 @@ static const char *const *
|
|||||||
findkwd(const char *s)
|
findkwd(const char *s)
|
||||||
{
|
{
|
||||||
return bsearch(s, tokname_array + KWDOFFSET,
|
return bsearch(s, tokname_array + KWDOFFSET,
|
||||||
(sizeof(tokname_array) / sizeof(char *)) - KWDOFFSET,
|
ARRAY_SIZE(tokname_array) - KWDOFFSET,
|
||||||
sizeof(char *), pstrcmp);
|
sizeof(tokname_array[0]), pstrcmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -8094,7 +8094,6 @@ static const struct builtincmd builtintab[] = {
|
|||||||
{ BUILTIN_REGULAR "wait", waitcmd },
|
{ BUILTIN_REGULAR "wait", waitcmd },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUMBUILTINS (sizeof(builtintab) / sizeof(builtintab[0]))
|
|
||||||
|
|
||||||
#define COMMANDCMD (builtintab + 5 + \
|
#define COMMANDCMD (builtintab + 5 + \
|
||||||
2 * ENABLE_ASH_BUILTIN_TEST + \
|
2 * ENABLE_ASH_BUILTIN_TEST + \
|
||||||
@ -8116,7 +8115,7 @@ find_builtin(const char *name)
|
|||||||
struct builtincmd *bp;
|
struct builtincmd *bp;
|
||||||
|
|
||||||
bp = bsearch(
|
bp = bsearch(
|
||||||
name, builtintab, NUMBUILTINS, sizeof(builtintab[0]),
|
name, builtintab, ARRAY_SIZE(builtintab), sizeof(builtintab[0]),
|
||||||
pstrcmp
|
pstrcmp
|
||||||
);
|
);
|
||||||
return bp;
|
return bp;
|
||||||
@ -11255,7 +11254,7 @@ helpcmd(int argc, char **argv)
|
|||||||
int col, i;
|
int col, i;
|
||||||
|
|
||||||
out1fmt("\nBuilt-in commands:\n-------------------\n");
|
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' : ' '),
|
col += out1fmt("%c%s", ((col == 0) ? '\t' : ' '),
|
||||||
builtintab[i].name + 1);
|
builtintab[i].name + 1);
|
||||||
if (col > 60) {
|
if (col > 60) {
|
||||||
|
@ -2889,10 +2889,10 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
|
|||||||
{ "done", RES_DONE, FLAG_END }
|
{ "done", RES_DONE, FLAG_END }
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) };
|
|
||||||
const struct reserved_combo *r;
|
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)
|
if (strcmp(dest->data, r->literal) != 0)
|
||||||
continue;
|
continue;
|
||||||
debug_printf("found reserved word %s, code %d\n", r->literal, r->code);
|
debug_printf("found reserved word %s, code %d\n", r->literal, r->code);
|
||||||
|
@ -146,8 +146,8 @@ static const struct built_in_command bltins[] = {
|
|||||||
/* to do: add ulimit */
|
/* 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) */
|
static int shell_context; /* Type prompt trigger (PS1 or PS2) */
|
||||||
|
@ -596,7 +596,7 @@ static const char * const signame[] = {
|
|||||||
"Terminated",
|
"Terminated",
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NSIGNAL (sizeof(signame)/sizeof(signame[0]))
|
|
||||||
|
|
||||||
struct res {
|
struct res {
|
||||||
const char *r_name;
|
const char *r_name;
|
||||||
@ -2997,7 +2997,7 @@ static int waitfor(int lastpid, int canintr)
|
|||||||
} else {
|
} else {
|
||||||
rv = WAITSIG(s);
|
rv = WAITSIG(s);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
if (rv < NSIGNAL) {
|
if (rv < ARRAY_SIZE(signame)) {
|
||||||
if (signame[rv] != NULL) {
|
if (signame[rv] != NULL) {
|
||||||
if (pid != lastpid) {
|
if (pid != lastpid) {
|
||||||
prn(pid);
|
prn(pid);
|
||||||
@ -3016,7 +3016,7 @@ static int waitfor(int lastpid, int canintr)
|
|||||||
}
|
}
|
||||||
if (WAITCORE(s))
|
if (WAITCORE(s))
|
||||||
prs(" - core dumped");
|
prs(" - core dumped");
|
||||||
if (rv >= NSIGNAL || signame[rv])
|
if (rv >= ARRAY_SIZE(signame) || signame[rv])
|
||||||
prs("\n");
|
prs("\n");
|
||||||
rv = -1;
|
rv = -1;
|
||||||
} else
|
} else
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
# define USE_FEATURE_FDISK_BLKSIZE(a)
|
# define USE_FEATURE_FDISK_BLKSIZE(a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
|
||||||
|
|
||||||
#define DEFAULT_SECTOR_SIZE 512
|
#define DEFAULT_SECTOR_SIZE 512
|
||||||
#define MAX_SECTOR_SIZE 2048
|
#define MAX_SECTOR_SIZE 2048
|
||||||
#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
|
#define SECTOR_SIZE 512 /* still used in osf/sgi/sun code */
|
||||||
|
@ -163,7 +163,7 @@ static const char * const xbsd_dktypenames[] = {
|
|||||||
"floppy",
|
"floppy",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
#define BSD_DKMAXTYPES (sizeof(xbsd_dktypenames) / sizeof(xbsd_dktypenames[0]) - 1)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Filesystem type and version.
|
* Filesystem type and version.
|
||||||
@ -219,7 +219,6 @@ static const char *const xbsd_fstypes[] = {
|
|||||||
"\x10" "AdvFS", /* BSD_FS_ADVFS */
|
"\x10" "AdvFS", /* BSD_FS_ADVFS */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#define BSD_FSMAXTYPES (SIZE(xbsd_fstypes)-1)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -509,7 +508,7 @@ xbsd_print_disklabel(int show_all)
|
|||||||
#else
|
#else
|
||||||
printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
|
printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0));
|
||||||
#endif
|
#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]);
|
printf("type: %s\n", xbsd_dktypenames[lp->d_type]);
|
||||||
else
|
else
|
||||||
printf("type: %d\n", lp->d_type);
|
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]);
|
printf("%8.8s", xbsd_fstypes[pp->p_fstype]);
|
||||||
else
|
else
|
||||||
printf("%8x", pp->p_fstype);
|
printf("%8x", pp->p_fstype);
|
||||||
|
@ -207,7 +207,7 @@ sun_autoconfigure_scsi(void)
|
|||||||
if (!q)
|
if (!q)
|
||||||
break;
|
break;
|
||||||
*q = '\0';
|
*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))
|
if (*sun_drives[i].vendor && strcasecmp(sun_drives[i].vendor, vendor))
|
||||||
continue;
|
continue;
|
||||||
if (!strstr(model, sun_drives[i].model))
|
if (!strstr(model, sun_drives[i].model))
|
||||||
@ -244,7 +244,7 @@ create_sunlabel(void)
|
|||||||
puts("Drive type\n"
|
puts("Drive type\n"
|
||||||
" ? auto configure\n"
|
" ? auto configure\n"
|
||||||
" 0 custom (with hardware detected defaults)");
|
" 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",
|
printf(" %c %s%s%s\n",
|
||||||
i + 'a', sun_drives[i].vendor,
|
i + 'a', sun_drives[i].vendor,
|
||||||
(*sun_drives[i].vendor) ? " " : "",
|
(*sun_drives[i].vendor) ? " " : "",
|
||||||
@ -255,11 +255,11 @@ create_sunlabel(void)
|
|||||||
if (c == '0') {
|
if (c == '0') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c >= 'a' && c < 'a' + SIZE(sun_drives)) {
|
if (c >= 'a' && c < 'a' + ARRAY_SIZE(sun_drives)) {
|
||||||
p = sun_drives + c - 'a';
|
p = sun_drives + c - 'a';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c >= 'A' && c < 'A' + SIZE(sun_drives)) {
|
if (c >= 'A' && c < 'A' + ARRAY_SIZE(sun_drives)) {
|
||||||
p = sun_drives + c - 'A';
|
p = sun_drives + c - 'A';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -446,7 +446,7 @@ verify_sun(void)
|
|||||||
else
|
else
|
||||||
array[i] = -1;
|
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);
|
(int (*)(const void *,const void *)) verify_sun_cmp);
|
||||||
if (array[0] == -1) {
|
if (array[0] == -1) {
|
||||||
printf("No partitions defined\n");
|
printf("No partitions defined\n");
|
||||||
|
@ -120,7 +120,6 @@ struct {
|
|||||||
{"remount", MS_REMOUNT}, // action flag
|
{"remount", MS_REMOUNT}, // action flag
|
||||||
};
|
};
|
||||||
|
|
||||||
#define VECTOR_SIZE(v) (sizeof(v) / sizeof((v)[0]))
|
|
||||||
|
|
||||||
/* Append mount options to string */
|
/* Append mount options to string */
|
||||||
static void append_mount_options(char **oldopts, const char *newopts)
|
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;
|
if (comma) *comma = 0;
|
||||||
|
|
||||||
// Find this option in mount_options
|
// 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)) {
|
if (!strcasecmp(mount_options[i].name, options)) {
|
||||||
long fl = mount_options[i].flags;
|
long fl = mount_options[i].flags;
|
||||||
if (fl < 0) flags &= fl;
|
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 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
|
// Add it to strflags, to pass on to kernel
|
||||||
i = *unrecognized ? strlen(*unrecognized) : 0;
|
i = *unrecognized ? strlen(*unrecognized) : 0;
|
||||||
*unrecognized = xrealloc(*unrecognized, i+strlen(options)+2);
|
*unrecognized = xrealloc(*unrecognized, i+strlen(options)+2);
|
||||||
|
Loading…
Reference in New Issue
Block a user