which scans thru "abc\0def\0123\0\0" type strings. Saves 250 bytes.
text data bss dec hex filename
781266 1328 11844 794438 c1f46 busybox_old
781010 1328 11844 794182 c1e46 busybox_unstripped
static unsigned fill_package_struct(char *control_buffer)
{
- static const char *const field_names[] = { "Package", "Version",
- "Pre-Depends", "Depends","Replaces", "Provides",
- "Conflicts", "Suggests", "Recommends", "Enhances", NULL
- };
+ static const char field_names[] = "Package\0""Version\0"
+ "Pre-Depends\0""Depends\0""Replaces\0""Provides\0"
+ "Conflicts\0""Suggests\0""Recommends\0""Enhances\0";
common_node_t *new_node = xzalloc(sizeof(common_node_t));
char *field_name;
&field_name, &field_value);
if (field_name == NULL) {
- goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
+ goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement! */
}
- field_num = index_in_str_array(field_names, field_name);
+ field_num = index_in_strings(field_names, field_name);
switch (field_num) {
case 0: /* Package */
new_node->name = search_name_hashtable(field_value);
# if ENABLE_FEATURE_TAR_FROM
"exclude\0" Required_argument "\xff"
# endif
- "\0";
+ ;
#endif
int tar_main(int argc, char **argv);
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
static const char setconsole_longopts[] =
"reset\0" No_argument "r"
- "\0";
+ ;
#endif
#define OPT_SETCONS_RESET 1
}
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
- const char * const filename)
+ const char *filename)
{
ssize_t n = full_write_or_warn(fd, buf, len, filename);
if (n < 0)
TRUNC_FLAG = 1 << 2,
TWOBUFS_FLAG = 1 << 3,
};
- static const char * const keywords[] = {
- "bs=", "count=", "seek=", "skip=", "if=", "of=",
+ static const char keywords[] =
+ "bs=\0""count=\0""seek=\0""skip=\0""if=\0""of=\0"
#if ENABLE_FEATURE_DD_IBS_OBS
- "ibs=", "obs=", "conv=", "notrunc", "sync", "noerror",
+ "ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0"
#endif
- NULL
- };
+ ;
enum {
OP_bs = 1,
OP_count,
bb_show_usage();
key_len = key - arg + 1;
key = xstrndup(arg, key_len);
- what = index_in_str_array(keywords, key) + 1;
+ what = index_in_strings(keywords, key) + 1;
if (ENABLE_FEATURE_CLEAN_UP)
free(key);
if (what == 0)
if (what == OP_conv) {
while (1) {
/* find ',', replace them with nil so we can use arg for
- * index_in_str_array without copying.
+ * index_in_strings() without copying.
* We rely on arg being non-null, else strchr would fault.
*/
key = strchr(arg, ',');
if (key)
*key = '\0';
- what = index_in_str_array(keywords, arg) + 1;
+ what = index_in_strings(keywords, arg) + 1;
if (what < OP_conv_notrunc)
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
if (what == OP_conv_notrunc)
G.out_part++;
}
if (close(ifd) < 0) {
-die_infile:
+ die_infile:
bb_perror_msg_and_die("%s", infile);
}
if (close(ofd) < 0) {
-die_outfile:
+ die_outfile:
bb_perror_msg_and_die("%s", outfile);
}
-out_status:
+ out_status:
dd_output_status(0);
return EXIT_SUCCESS;
static const char env_longopts[] =
"ignore-environment\0" No_argument "i"
"unset\0" Required_argument "u"
- "\0";
+ ;
#endif
int env_main(int argc, char** argv);
static VALUE *eval6(void)
{
- static const char * const keywords[] = {
- "quote", "length", "match", "index", "substr", NULL
- };
+ static const char keywords[] =
+ "quote\0""length\0""match\0""index\0""substr\0";
VALUE *r, *i1, *i2;
VALUE *l = l; /* silence gcc */
VALUE *v = v; /* silence gcc */
- int key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0;
+ int key = *G.args ? index_in_strings(keywords, *G.args) + 1 : 0;
if (key == 0) /* not a keyword */
return eval7();
"preserve_context\0" No_argument "\xff"
"preserve-context\0" No_argument "\xff"
#endif
- "\0";
+ ;
#endif
* equivalent */
static const char ls_color_opt[] =
"color\0" Optional_argument "\xff" /* no short equivalent */
- "\0";
+ ;
#else
enum { show_color = 0 };
#endif
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
- "\0";
+ ;
#endif
int mkdir_main(int argc, char **argv);
static const char mv_longopts[] =
"interactive\0" No_argument "i"
"force\0" No_argument "f"
- "\0";
+ ;
#endif
#define OPT_FILEUTILS_FORCE 1
"strings\0" Optional_argument "S"
"width\0" Optional_argument "w"
"traditional\0" No_argument "\xff"
- "\0";
+ ;
#endif
char *str_A, *str_N, *str_j, *str_S;
char *str_w = NULL;
static int find_param(const char * const name)
{
- static const char * const params[] = {
- "line", /* 1 */
- "rows", /* 2 */
- "cols", /* 3 */
- "columns", /* 4 */
- "size", /* 5 */
- "ispeed"+1, /* 6 */
- "ispeed",
- "ospeed",
- NULL
- };
- int i = index_in_str_array(params, name) + 1;
+ static const char params[] =
+ "line\0" /* 1 */
+ "rows\0" /* 2 */
+ "cols\0" /* 3 */
+ "columns\0" /* 4 */
+ "size\0" /* 5 */
+ "speed\0" /* 6 */
+ "ispeed\0"
+ "ospeed\0";
+ int i = index_in_strings(params, name) + 1;
if (i == 0)
return 0;
if (i != 5 && i != 6)
char *buffer_start = buffer;
unsigned i; /* XXX: FIXME: use unsigned char? */
unsigned char ac;
-#define CLO ":]"
- static const char * const classes[] = {
- "alpha"CLO, "alnum"CLO, "digit"CLO, "lower"CLO, "upper"CLO, "space"CLO,
- "blank"CLO, "punct"CLO, "cntrl"CLO, NULL
- };
+#define CLO ":]\0"
+ static const char classes[] =
+ "alpha"CLO "alnum"CLO "digit"CLO "lower"CLO "upper"CLO "space"CLO
+ "blank"CLO "punct"CLO "cntrl"CLO;
#define CLASS_invalid 0 /* we increment the retval */
#define CLASS_alpha 1
#define CLASS_alnum 2
smalluint j;
{ /* not really pretty.. */
char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7
- j = index_in_str_array(classes, tmp) + 1;
+ j = index_in_strings(classes, tmp) + 1;
free(tmp);
}
if (j == CLASS_alnum || j == CLASS_digit) {
//TODO: "reverse\0" No_argument "r"
//TODO: "verbose\0" No_argument "v"
#endif
- "\0";
+ ;
#endif
struct globals {
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
"retry\0" Required_argument "R"
#endif
- "\0";
+ ;
#endif
enum {
char *base_device; /* /dev/hda for /dev/hdaN etc */
};
-static const char *const ignored_types[] = {
- "ignore",
- "iso9660",
- "nfs",
- "proc",
- "sw",
- "swap",
- "tmpfs",
- "devpts",
- NULL
-};
+static const char ignored_types[] =
+ "ignore\0"
+ "iso9660\0"
+ "nfs\0"
+ "proc\0"
+ "sw\0"
+ "swap\0"
+ "tmpfs\0"
+ "devpts\0";
#if 0
-static const char *const really_wanted[] = {
- "minix",
- "ext2",
- "ext3",
- "jfs",
- "reiserfs",
- "xiafs",
- "xfs",
- NULL
-};
+static const char really_wanted[] =
+ "minix\0"
+ "ext2\0"
+ "ext3\0"
+ "jfs\0"
+ "reiserfs\0"
+ "xiafs\0"
+ "xfs\0";
#endif
#define BASE_MD "/dev/md"
return 1;
/* Are we ignoring this type? */
- if (index_in_str_array(ignored_types, fs->type) >= 0)
+ if (index_in_strings(ignored_types, fs->type) >= 0)
return 1;
/* We can and want to check this file system type. */
USE_FEATURE_FIND_CONTEXT(PARM_context ,)
};
- static const char *const params[] = {
- "-a" ,
- "-o" ,
- USE_FEATURE_FIND_NOT( "!" ,)
+ static const char params[] =
+ "-a\0"
+ "-o\0"
+ USE_FEATURE_FIND_NOT( "!\0" )
#if ENABLE_DESKTOP
- "-and" ,
- "-or" ,
- USE_FEATURE_FIND_NOT( "-not" ,)
-#endif
- "-print" ,
- USE_FEATURE_FIND_PRINT0( "-print0" ,)
- USE_FEATURE_FIND_DEPTH( "-depth" ,)
- USE_FEATURE_FIND_PRUNE( "-prune" ,)
- USE_FEATURE_FIND_DELETE( "-delete" ,)
- USE_FEATURE_FIND_EXEC( "-exec" ,)
- USE_FEATURE_FIND_PAREN( "(" ,)
+ "-and\0"
+ "-or\0"
+ USE_FEATURE_FIND_NOT( "-not\0" )
+#endif
+ "-print\0"
+ USE_FEATURE_FIND_PRINT0( "-print0\0" )
+ USE_FEATURE_FIND_DEPTH( "-depth\0" )
+ USE_FEATURE_FIND_PRUNE( "-prune\0" )
+ USE_FEATURE_FIND_DELETE( "-delete\0" )
+ USE_FEATURE_FIND_EXEC( "-exec\0" )
+ USE_FEATURE_FIND_PAREN( "(\0" )
/* All options starting from here require argument */
- "-name" ,
- USE_FEATURE_FIND_PATH( "-path" ,)
- USE_FEATURE_FIND_REGEX( "-regex" ,)
- USE_FEATURE_FIND_TYPE( "-type" ,)
- USE_FEATURE_FIND_PERM( "-perm" ,)
- USE_FEATURE_FIND_MTIME( "-mtime" ,)
- USE_FEATURE_FIND_MMIN( "-mmin" ,)
- USE_FEATURE_FIND_NEWER( "-newer" ,)
- USE_FEATURE_FIND_INUM( "-inum" ,)
- USE_FEATURE_FIND_USER( "-user" ,)
- USE_FEATURE_FIND_GROUP( "-group" ,)
- USE_FEATURE_FIND_SIZE( "-size" ,)
- USE_FEATURE_FIND_CONTEXT("-context",)
- NULL
- };
+ "-name\0"
+ USE_FEATURE_FIND_PATH( "-path\0" )
+ USE_FEATURE_FIND_REGEX( "-regex\0" )
+ USE_FEATURE_FIND_TYPE( "-type\0" )
+ USE_FEATURE_FIND_PERM( "-perm\0" )
+ USE_FEATURE_FIND_MTIME( "-mtime\0" )
+ USE_FEATURE_FIND_MMIN( "-mmin\0" )
+ USE_FEATURE_FIND_NEWER( "-newer\0" )
+ USE_FEATURE_FIND_INUM( "-inum\0" )
+ USE_FEATURE_FIND_USER( "-user\0" )
+ USE_FEATURE_FIND_GROUP( "-group\0" )
+ USE_FEATURE_FIND_SIZE( "-size\0" )
+ USE_FEATURE_FIND_CONTEXT("-context\0")
+ ;
action*** appp;
unsigned cur_group = 0;
*/
while (*argv) {
const char *arg = argv[0];
- int parm = index_in_str_array(params, arg);
+ int parm = index_in_strings(params, arg);
const char *arg1 = argv[1];
if (parm >= PARM_name) {
int find_main(int argc, char **argv);
int find_main(int argc, char **argv)
{
- static const char *const options[] = {
- "-follow",
-USE_FEATURE_FIND_XDEV( "-xdev" ,)
-USE_FEATURE_FIND_MAXDEPTH("-maxdepth",)
- NULL
- };
+ static const char options[] =
+ "-follow\0"
+USE_FEATURE_FIND_XDEV( "-xdev\0" )
+USE_FEATURE_FIND_MAXDEPTH("-maxdepth\0")
+ ;
enum {
- OPT_FOLLOW,
+ OPT_FOLLOW,
USE_FEATURE_FIND_XDEV( OPT_XDEV ,)
USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,)
};
/* (-a will be ignored by recursive parser later) */
argp = &argv[firstopt];
while ((arg = argp[0])) {
- int opt = index_in_str_array(options, arg);
+ int opt = index_in_strings(options, arg);
if (opt == OPT_FOLLOW) {
recurse_flags |= ACTION_FOLLOWLINKS;
argp[0] = (char*)"-a";
/* Returns a ptr to static storage */
extern char *pw_encrypt(const char *clear, const char *salt);
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
-extern int index_in_str_array(const char * const string_array[], const char *key);
-extern int index_in_substr_array(const char * const string_array[], const char *key);
+extern int index_in_str_array(const char *const string_array[], const char *key);
+extern int index_in_strings(const char *strings, const char *key);
+extern int index_in_substr_array(const char *const string_array[], const char *key);
+extern int index_in_substrings(const char *strings, const char *key);
extern void print_login_issue(const char *issue_file, const char *tty);
extern void print_login_prompt(void);
return -1;
}
+int index_in_strings(const char *strings, const char *key)
+{
+ int idx = 0;
+
+ while (strings[0]) {
+ if (strcmp(strings, key) == 0) {
+ return idx;
+ }
+ strings += strlen(strings) + 1; /* skip NUL */
+ idx++;
+ }
+ return -1;
+}
+
/* returns the array index of the string, even if it matches only a beginning */
/* (index of first match is returned, or -1) */
+#ifdef UNUSED
int index_in_substr_array(const char * const string_array[], const char *key)
{
int i;
}
return -1;
}
+#endif
+
+int index_in_substrings(const char *strings, const char *key)
+{
+ int len = strlen(key);
+
+ if (len) {
+ int idx = 0;
+ while (strings[0]) {
+ if (strncmp(strings, key, len) == 0) {
+ return idx;
+ }
+ strings += strlen(strings) + 1; /* skip NUL */
+ idx++;
+ }
+ }
+ return -1;
+}
"\r\\r\0"
"\t\\t\0"
"\v\\v\0"
- "\0";
+ ;
static void conv_c(PR * pr, unsigned char * p)
static const char applet_longopts[] =
//"name\0" has_arg val
"verbose\0" No_argument "v"
- "\0";
+ ;
applet_long_options = applet_longopts;
The last member of struct option (val) typically is set to
static const char chpasswd_longopts[] =
"encrypted\0" No_argument "e"
"md5\0" No_argument "m"
- "\0";
+ ;
#endif
#define OPT_ENC 1
int i;
/* !!!! Only Uppercase Keywords in devsfd.conf */
- static const char *const options[] = {
- "CLEAR_CONFIG", "INCLUDE", "OPTIONAL_INCLUDE",
- "RESTORE", "PERMISSIONS", "MODLOAD", "EXECUTE",
- "COPY", "IGNORE", "MKOLDCOMPAT", "MKNEWCOMPAT",
- "RMOLDCOMPAT", "RMNEWCOMPAT", 0
- };
+ static const char options[] =
+ "CLEAR_CONFIG\0""INCLUDE\0""OPTIONAL_INCLUDE\0"
+ "RESTORE\0""PERMISSIONS\0""MODLOAD\0""EXECUTE\0"
+ "COPY\0""IGNORE\0""MKOLDCOMPAT\0""MKNEWCOMPAT\0"
+ "RMOLDCOMPAT\0""RMNEWCOMPAT\0";
for (count = 0; count < MAX_ARGS; ++count)
p[count][0] = '\0';
when, name, what,
p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
- i = index_in_str_array(options, when);
+ i = index_in_strings(options, when);
- /*"CLEAR_CONFIG"*/
+ /* "CLEAR_CONFIG" */
if (i == 0) {
free_config();
*event_mask = 0;
goto process_config_line_err;
}
- i = index_in_str_array(options, what);
+ i = index_in_strings(options, what);
switch (i) {
case 4: /* "PERMISSIONS" */
static const char *get_variable(const char *variable, void *info)
{
+ static char sbuf[sizeof(int)*3 + 2]; /* sign and NUL */
+
+ char hostname[STRING_LENGTH];
struct get_variable_info *gv_info = info;
- static char hostname[STRING_LENGTH], sbuf[STRING_LENGTH];
- const char *field_names[] = { "hostname", "mntpt", "devpath", "devname",
- "uid", "gid", "mode", hostname, mount_point,
- gv_info->devpath, gv_info->devname, 0 };
+ const char *field_names[] = {
+ "hostname", "mntpt", "devpath", "devname",
+ "uid", "gid", "mode", hostname, mount_point,
+ gv_info->devpath, gv_info->devname, NULL
+ };
int i;
if (gethostname(hostname, STRING_LENGTH - 1) != 0)
+ /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
error_logger_and_die(LOG_ERR, "gethostname");
- /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
- hostname[STRING_LENGTH - 1] = '\0';
+ hostname[STRING_LENGTH - 1] = '\0';
/* index_in_str_array returns i>=0 */
i = index_in_str_array(field_names, variable);
if (i > 6 || i < 0 || (i > 1 && gv_info == NULL))
- return NULL;
- if (i >= 0 && i <= 3) {
+ return NULL;
+ if (i >= 0 && i <= 3)
return field_names[i + 7];
- }
if (i == 4)
sprintf(sbuf, "%u", gv_info->info->uid);
static smallint hw_set; /* flag if hw-type was set (-H) */
static const char *device = ""; /* current device */
-static const char *const options[] = {
- "pub",
- "priv",
- "temp",
- "trail",
- "dontpub",
- "auto",
- "dev",
- "netmask",
- NULL
-};
+static const char options[] =
+ "pub\0"
+ "priv\0"
+ "temp\0"
+ "trail\0"
+ "dontpub\0"
+ "auto\0"
+ "dev\0"
+ "netmask\0";
/* Delete an entry from the ARP cache. */
/* Called only from main, once */
req.arp_flags = ATF_PERM;
args++;
while (*args != NULL) {
- switch (index_in_str_array(options, *args)) {
+ switch (index_in_strings(options, *args)) {
case 0: /* "pub" */
flags |= 1;
args++;
/* Check out any modifiers. */
flags = ATF_PERM | ATF_COM;
while (*args != NULL) {
- switch (index_in_str_array(options, *args)) {
+ switch (index_in_strings(options, *args)) {
case 0: /* "pub" */
flags |= ATF_PUBL;
args++;
"username\0" Required_argument "u"
"password\0" Required_argument "p"
"port\0" Required_argument "P"
- "\0";
+ ;
#endif
int ftpgetput_main(int argc, char **argv);
int ip_main(int argc, char **argv);
int ip_main(int argc, char **argv)
{
- const char * const keywords[] = {
- USE_FEATURE_IP_ADDRESS("address",)
- USE_FEATURE_IP_ROUTE("route",)
- USE_FEATURE_IP_LINK("link",)
- USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
- USE_FEATURE_IP_RULE("rule",)
- NULL
- };
+ static const char keywords[] =
+ USE_FEATURE_IP_ADDRESS("address\0")
+ USE_FEATURE_IP_ROUTE("route\0")
+ USE_FEATURE_IP_LINK("link\0")
+ USE_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0")
+ USE_FEATURE_IP_RULE("rule\0")
+ ;
enum {
USE_FEATURE_IP_ADDRESS(IP_addr,)
USE_FEATURE_IP_ROUTE(IP_route,)
ip_parse_common_args(&argc, &argv);
if (argc > 1) {
- int key = index_in_substr_array(keywords, argv[1]);
+ int key = index_in_substrings(keywords, argv[1]);
argc -= 2;
argv += 2;
#if ENABLE_FEATURE_IP_ADDRESS
ip_func = do_iprule;
#endif
}
- return (ip_func(argc, argv));
+ return ip_func(argc, argv);
}
#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
"hostname\0" No_argument "h"
"silent\0" No_argument "s"
# endif
- "\0";
+ ;
#endif
int ipcalc_main(int argc, char **argv);
{
int argc = *argcp;
char **argv = *argvp;
- static const char * const ip_common_commands[] =
- {"-family", "inet", "inet6", "link",
- "-4", "-6", "-0", "-oneline", 0};
+ static const char ip_common_commands[] =
+ "-family\0""inet\0""inet6\0""link\0"
+ "-4\0""-6\0""-0\0""-oneline\0";
enum {
ARG_family = 1,
ARG_inet,
break;
if (opt[1] == '-')
opt++;
- arg = index_in_str_array(ip_common_commands, opt) + 1;
+ arg = index_in_strings(ip_common_commands, opt) + 1;
if (arg == ARG_family) {
argc--;
argv++;
if (!argv[1])
bb_show_usage();
- arg = index_in_str_array(ip_common_commands, argv[1]) + 1;
+ arg = index_in_strings(ip_common_commands, argv[1]) + 1;
if (arg == ARG_inet)
preferred_family = AF_INET;
else if (arg == ARG_inet6)
/* Return value becomes exitcode. It's okay to not return at all */
int ipaddr_list_or_flush(int argc, char **argv, int flush)
{
- static const char *const option[] = { "to", "scope", "up", "label", "dev", 0 };
+ static const char option[] = "to\0""scope\0""up\0""label\0""dev\0";
struct nlmsg_list *linfo = NULL;
struct nlmsg_list *ainfo = NULL;
}
while (argc > 0) {
- const int option_num = index_in_str_array(option, *argv);
+ const int option_num = index_in_strings(option, *argv);
switch (option_num) {
case 0: /* to */
NEXT_ARG();
/* Return value becomes exitcode. It's okay to not return at all */
static int ipaddr_modify(int cmd, int argc, char **argv)
{
- static const char *const option[] = {
- "peer", "remote", "broadcast", "brd",
- "anycast", "scope", "dev", "label", "local", 0
- };
+ static const char option[] =
+ "peer\0""remote\0""broadcast\0""brd\0"
+ "anycast\0""scope\0""dev\0""label\0""local\0";
struct rtnl_handle rth;
struct {
- struct nlmsghdr n;
- struct ifaddrmsg ifa;
- char buf[256];
+ struct nlmsghdr n;
+ struct ifaddrmsg ifa;
+ char buf[256];
} req;
- char *d = NULL;
- char *l = NULL;
+ char *d = NULL;
+ char *l = NULL;
inet_prefix lcl;
inet_prefix peer;
int local_len = 0;
req.ifa.ifa_family = preferred_family;
while (argc > 0) {
- const int option_num = index_in_str_array(option, *argv);
+ const int option_num = index_in_strings(option, *argv);
switch (option_num) {
case 0: /* peer */
case 1: /* remote */
/* Return value becomes exitcode. It's okay to not return at all */
int do_ipaddr(int argc, char **argv)
{
- static const char *const commands[] = {
- "add", "delete", "list", "show", "lst", "flush", 0
- };
+ static const char commands[] =
+ "add\0""delete\0""list\0""show\0""lst\0""flush\0";
int command_num = 2; /* default command is list */
if (*argv) {
- command_num = index_in_substr_array(commands, *argv);
+ command_num = index_in_substrings(commands, *argv);
}
if (command_num < 0 || command_num > 5)
bb_error_msg_and_die("unknown command %s", *argv);
struct ifreq ifr0, ifr1;
char *newname = NULL;
int htype, halen;
- static const char * const keywords[] = {
- "up", "down", "name", "mtu", "multicast", "arp", "addr", "dev",
- "on", "off", NULL
- };
+ static const char keywords[] =
+ "up\0""down\0""name\0""mtu\0""multicast\0""arp\0""addr\0""dev\0"
+ "on\0""off\0";
enum { ARG_up = 1, ARG_down, ARG_name, ARG_mtu, ARG_multicast, ARG_arp,
ARG_addr, ARG_dev, PARM_on, PARM_off };
smalluint key;
while (argc > 0) {
- key = index_in_str_array(keywords, *argv) + 1;
+ key = index_in_strings(keywords, *argv) + 1;
if (key == ARG_up) {
mask |= IFF_UP;
flags |= IFF_UP;
} else if (key == ARG_multicast) {
NEXT_ARG();
mask |= IFF_MULTICAST;
- key = index_in_str_array(keywords, *argv) + 1;
+ key = index_in_strings(keywords, *argv) + 1;
if (key == PARM_on) {
flags |= IFF_MULTICAST;
} else if (key == PARM_off) {
} else if (key == ARG_arp) {
NEXT_ARG();
mask |= IFF_NOARP;
- key = index_in_str_array(keywords, *argv) + 1;
+ key = index_in_strings(keywords, *argv) + 1;
if (key == PARM_on) {
flags &= ~IFF_NOARP;
} else if (key == PARM_off) {
/* Return value becomes exitcode. It's okay to not return at all */
int do_iplink(int argc, char **argv)
{
- static const char * const keywords[] = {
- "set", "show", "lst", "list", NULL
- };
+ static const char keywords[] =
+ "set\0""show\0""lst\0""list\0";
smalluint key;
if (argc <= 0)
return ipaddr_list_link(0, NULL);
- key = index_in_substr_array(keywords, *argv) + 1;
+ key = index_in_substrings(keywords, *argv) + 1;
if (key == 0)
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
argc--; argv++;
/* Return value becomes exitcode. It's okay to not return at all */
static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
{
+ static const char keywords[] =
+ "src\0""via\0""mtu\0""lock\0""protocol\0"USE_FEATURE_IP_RULE("table\0")
+ "dev\0""oif\0""to\0";
+ enum {
+ ARG_src,
+ ARG_via,
+ ARG_mtu, PARM_lock,
+ ARG_protocol,
+USE_FEATURE_IP_RULE(ARG_table,)
+ ARG_dev,
+ ARG_oif,
+ ARG_to
+ };
+ enum {
+ gw_ok = 1 << 0,
+ dst_ok = 1 << 1,
+ proto_ok = 1 << 2,
+ type_ok = 1 << 3
+ };
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
struct rtattr * mxrta = (void*)mxbuf;
unsigned mxlock = 0;
char *d = NULL;
- enum { gw_ok = 1<<0, dst_ok = 1<<1, proto_ok = 1<<2, type_ok = 1<<3};
smalluint ok = 0;
- static const char * const keywords[] = {
- "src", "via", "mtu", "lock", "protocol", USE_FEATURE_IP_RULE("table",)
- "dev", "oif", "to", NULL
- };
- enum {
- ARG_src,
- ARG_via,
- ARG_mtu, PARM_lock,
- ARG_protocol,
-USE_FEATURE_IP_RULE(ARG_table,)
- ARG_dev,
- ARG_oif,
- ARG_to
- };
int arg;
memset(&req, 0, sizeof(req));
mxrta->rta_len = RTA_LENGTH(0);
while (argc > 0) {
- arg = index_in_substr_array(keywords, *argv);
+ arg = index_in_substrings(keywords, *argv);
if (arg == ARG_src) {
inet_prefix addr;
NEXT_ARG();
} else if (arg == ARG_mtu) {
unsigned mtu;
NEXT_ARG();
- if (index_in_str_array(keywords, *argv) == PARM_lock) {
+ if (index_in_strings(keywords, *argv) == PARM_lock) {
mxlock |= (1<<RTAX_MTU);
NEXT_ARG();
}
struct rtnl_handle rth;
char *id = NULL;
char *od = NULL;
- static const char * const keywords[] = {
- "protocol", "all", "dev", "oif", "iif", "via", "table", "cache",/*all,*/
- "from", "root", "match", "exact", "to", /*root,match,exact*/ NULL
- };
+ static const char keywords[] =
+ "protocol\0""all\0""dev\0""oif\0""iif\0""via\0""table\0""cache\0" /*all*/
+ "from\0""root\0""match\0""exact\0""to\0"/*root match exact*/;
enum {
ARG_proto, PARM_all,
ARG_dev,
bb_error_msg_and_die(bb_msg_requires_arg, "\"ip route flush\"");
while (argc > 0) {
- arg = index_in_substr_array(keywords, *argv);
+ arg = index_in_substrings(keywords, *argv);
if (arg == ARG_proto) {
uint32_t prot = 0;
NEXT_ARG();
filter.protocolmask = -1;
if (rtnl_rtprot_a2n(&prot, *argv)) {
- if (index_in_str_array(keywords, *argv) != PARM_all)
+ if (index_in_strings(keywords, *argv) != PARM_all)
invarg(*argv, "protocol");
prot = 0;
filter.protocolmask = 0;
get_prefix(&filter.rvia, *argv, do_ipv6);
} else if (arg == ARG_table) {
NEXT_ARG();
- parm = index_in_substr_array(keywords, *argv);
+ parm = index_in_substrings(keywords, *argv);
if (parm == PARM_cache)
filter.tb = -1;
else if (parm == PARM_all)
invarg(*argv, "table");
} else if (arg == ARG_from) {
NEXT_ARG();
- parm = index_in_substr_array(keywords, *argv);
+ parm = index_in_substrings(keywords, *argv);
if (parm == PARM_root) {
NEXT_ARG();
get_prefix(&filter.rsrc, *argv, do_ipv6);
/* parm = arg; // would be more plausible, we reuse arg here */
if (arg == ARG_to) {
NEXT_ARG();
- arg = index_in_substr_array(keywords, *argv);
+ arg = index_in_substrings(keywords, *argv);
}
if (arg == PARM_root) {
NEXT_ARG();
xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE);
filter.flushed = 0;
xrtnl_dump_filter(&rth, print_route, stdout);
- if (filter.flushed == 0) {
+ if (filter.flushed == 0)
return 0;
- }
if (flush_update())
return 1;
}
if (filter.tb != -1) {
xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE);
- } else {
- if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
- bb_perror_msg_and_die("cannot send dump request");
- }
+ } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
+ bb_perror_msg_and_die("cannot send dump request");
}
xrtnl_dump_filter(&rth, print_route, stdout);
{
struct rtnl_handle rth;
struct {
- struct nlmsghdr n;
- struct rtmsg r;
- char buf[1024];
+ struct nlmsghdr n;
+ struct rtmsg r;
+ char buf[1024];
} req;
- char *idev = NULL;
- char *odev = NULL;
+ char *idev = NULL;
+ char *odev = NULL;
bool connected = 0;
bool from_ok = 0;
- static const char * const options[] =
- { "from", "iif", "oif", "dev", "notify", "connected", "to", 0 };
+ static const char options[] =
+ "from\0""iif\0""oif\0""dev\0""notify\0""connected\0""to\0";
memset(&req, 0, sizeof(req));
req.r.rtm_tos = 0;
while (argc > 0) {
- switch (index_in_str_array(options, *argv)) {
+ switch (index_in_strings(options, *argv)) {
case 0: /* from */
{
inet_prefix addr;
/* Return value becomes exitcode. It's okay to not return at all */
int do_iproute(int argc, char **argv)
{
- static const char * const ip_route_commands[] = {
- /*0-3*/ "add", "append", "change", "chg",
- /*4-7*/ "delete", "get", "list", "show",
- /*8..*/ "prepend", "replace", "test", "flush", 0
- };
+ static const char ip_route_commands[] =
+ /*0-3*/ "add\0""append\0""change\0""chg\0"
+ /*4-7*/ "delete\0""get\0""list\0""show\0"
+ /*8..*/ "prepend\0""replace\0""test\0""flush\0";
int command_num = 6;
- unsigned int flags = 0;
+ unsigned flags = 0;
int cmd = RTM_NEWROUTE;
/* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */
/* It probably means that it is using "first match" rule */
if (*argv) {
- command_num = index_in_substr_array(ip_route_commands, *argv);
+ command_num = index_in_substrings(ip_route_commands, *argv);
}
switch (command_num) {
case 0: /* add */
/* Return value becomes exitcode. It's okay to not return at all */
static int iprule_modify(int cmd, int argc, char **argv)
{
+ static const char keywords[] =
+ "from\0""to\0""preference\0""order\0""priority\0"
+ "tos\0""fwmark\0""realms\0""table\0""lookup\0""dev\0"
+ "iif\0""nat\0""map-to\0""type\0""help\0";
+ enum {
+ ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
+ ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
+ ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help
+ };
bool table_ok = 0;
struct rtnl_handle rth;
struct {
struct rtmsg r;
char buf[1024];
} req;
- static const char * const keywords[] =
- { "from", "to", "preference", "order", "priority", "tos", "fwmark",
- "realms", "table", "lookup", "dev", "iif", "nat", "map-to", "type",
- "help", NULL};
- enum { ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
- ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
- ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help };
smalluint key;
memset(&req, 0, sizeof(req));
}
while (argc > 0) {
- key = index_in_substr_array(keywords, *argv) + 1;
+ key = index_in_substrings(keywords, *argv) + 1;
if (key == 0) /* no match found in keywords array, bail out. */
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
if (key == ARG_from) {
/* Return value becomes exitcode. It's okay to not return at all */
int do_iprule(int argc, char **argv)
{
- static const char * const ip_rule_commands[] =
- {"add", "delete", "list", "show", 0};
+ static const char ip_rule_commands[] =
+ "add\0""delete\0""list\0""show\0";
int cmd = 2; /* list */
if (argc < 1)
return iprule_list(0, NULL);
if (*argv)
- cmd = index_in_substr_array(ip_rule_commands, *argv);
+ cmd = index_in_substrings(ip_rule_commands, *argv);
switch (cmd) {
case 0: /* add */
/* Dies on error */
static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
{
- int count = 0;
- char medium[IFNAMSIZ];
- static const char * const keywords[] = {
- "mode", "ipip", "ip/ip", "gre", "gre/ip", "sit", "ipv6/ip",
- "key", "ikey", "okey", "seq", "iseq", "oseq",
- "csum", "icsum", "ocsum", "nopmtudisc", "pmtudisc",
- "remote", "any", "local", "dev",
- "ttl", "inherit", "tos", "dsfield",
- "name", NULL
- };
+ static const char keywords[] =
+ "mode\0""ipip\0""ip/ip\0""gre\0""gre/ip\0""sit\0""ipv6/ip\0"
+ "key\0""ikey\0""okey\0""seq\0""iseq\0""oseq\0"
+ "csum\0""icsum\0""ocsum\0""nopmtudisc\0""pmtudisc\0"
+ "remote\0""any\0""local\0""dev\0"
+ "ttl\0""inherit\0""tos\0""dsfield\0"
+ "name\0";
enum {
ARG_mode, ARG_ipip, ARG_ip_ip, ARG_gre, ARG_gre_ip, ARG_sit, ARG_ip6_ip,
ARG_key, ARG_ikey, ARG_okey, ARG_seq, ARG_iseq, ARG_oseq,
ARG_ttl, ARG_inherit, ARG_tos, ARG_dsfield,
ARG_name
};
+ int count = 0;
+ char medium[IFNAMSIZ];
int key;
+
memset(p, 0, sizeof(*p));
memset(&medium, 0, sizeof(medium));
p->iph.version = 4;
p->iph.ihl = 5;
#ifndef IP_DF
-#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
+#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
#endif
p->iph.frag_off = htons(IP_DF);
while (argc > 0) {
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key == ARG_mode) {
NEXT_ARG();
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key == ARG_ipip ||
key == ARG_ip_ip) {
if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) {
p->iph.frag_off = htons(IP_DF);
} else if (key == ARG_remote) {
NEXT_ARG();
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key == ARG_any)
p->iph.daddr = get_addr32(*argv);
} else if (key == ARG_local) {
NEXT_ARG();
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key == ARG_any)
p->iph.saddr = get_addr32(*argv);
} else if (key == ARG_dev) {
} else if (key == ARG_ttl) {
unsigned uval;
NEXT_ARG();
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key != ARG_inherit) {
if (get_unsigned(&uval, *argv, 0))
invarg(*argv, "TTL");
key == ARG_dsfield) {
uint32_t uval;
NEXT_ARG();
- key = index_in_str_array(keywords, *argv);
+ key = index_in_strings(keywords, *argv);
if (key != ARG_inherit) {
if (rtnl_dsfield_a2n(&uval, *argv))
invarg(*argv, "TOS");
/* Return value becomes exitcode. It's okay to not return at all */
int do_iptunnel(int argc, char **argv)
{
- static const char *const keywords[] = {
- "add", "change", "delete", "show", "list", "lst", NULL
- };
+ static const char keywords[] =
+ "add\0""change\0""delete\0""show\0""list\0""lst\0";
enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
int key;
if (argc) {
- key = index_in_substr_array(keywords, *argv);
+ key = index_in_substrings(keywords, *argv);
if (key < 0)
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
--argc;
int rtnl_rtntype_a2n(int *id, char *arg)
{
- static const char * const keywords[] = {
- "local", "nat", "broadcast", "brd", "anycast",
- "multicast", "prohibit", "unreachable", "blackhole",
- "xresolve", "unicast", "throw", NULL
- };
- enum { ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast,
+ static const char keywords[] =
+ "local\0""nat\0""broadcast\0""brd\0""anycast\0"
+ "multicast\0""prohibit\0""unreachable\0""blackhole\0"
+ "xresolve\0""unicast\0""throw\0";
+ enum {
+ ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast,
ARG_multicast, ARG_prohibit, ARG_unreachable, ARG_blackhole,
ARG_xresolve, ARG_unicast, ARG_throw
};
- const smalluint key = index_in_substr_array(keywords, arg) + 1;
+ const smalluint key = index_in_substrings(keywords, arg) + 1;
char *end;
unsigned long res;
#include "libbb.h"
#include "libiproute/utils.h" /* invarg() */
-/* Line discipline code table */
-static const char *const proto_names[] = {
- "cslip"+1, /* 0 */
- "cslip", /* 1 */
- "cslip6"+1, /* 2 */
- "cslip6", /* 3 */
- "adaptive", /* 8 */
- NULL
-};
-
struct globals {
int handle;
int saved_disc;
int slattach_main(int argc, char **argv);
int slattach_main(int argc, char **argv)
{
+ /* Line discipline code table */
+ static const char proto_names[] =
+ "slip\0" /* 0 */
+ "cslip\0" /* 1 */
+ "slip6\0" /* 2 */
+ "cslip6\0" /* 3 */
+ "adaptive\0" /* 8 */
+ ;
+
int i, encap, opt;
struct termios state;
const char *proto = "cslip";
if (!*argv)
bb_show_usage();
- encap = index_in_str_array(proto_names, proto);
+ encap = index_in_strings(proto_names, proto);
if (encap < 0)
invarg(proto, "protocol");
"timeout\0" Required_argument "T"
"version\0" No_argument "v"
"retries\0" Required_argument "t"
- "\0";
+ ;
#endif
/* Default options. */
client_config.interface = "eth0";
"absolute\0" No_argument "a"
"remaining\0" No_argument "r"
"file\0" Required_argument "f"
- "\0";
+ ;
applet_long_options = dumpleases_longopts;
#endif
bool use_proxy = 1; /* Use proxies if env vars are set */
const char *proxy_flag = "on"; /* Use proxies if env vars are set */
const char *user_agent = "Wget";/* "User-Agent" header field */
- static const char * const keywords[] = {
- "content-length", "transfer-encoding", "chunked", "location", NULL
- };
+ static const char keywords[] =
+ "content-length\0""transfer-encoding\0""chunked\0""location\0";
enum {
KEY_content_length = 1, KEY_transfer_encoding, KEY_chunked, KEY_location
};
"user-agent\0" Required_argument "U"
"passive-ftp\0" No_argument "\xff"
"header\0" Required_argument "\xfe"
- "\0";
+ ;
applet_long_options = wget_longopts;
#endif
/* server.allocated = target.allocated = NULL; */
*/
while ((str = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
/* gethdr did already convert the "FOO:" string to lowercase */
- smalluint key = index_in_str_array(keywords, *&buf) + 1;
+ smalluint key = index_in_strings(keywords, *&buf) + 1;
if (key == KEY_content_length) {
content_len = BB_STRTOOFF(str, NULL, 10);
if (errno || content_len < 0) {
continue;
}
if (key == KEY_transfer_encoding) {
- if (index_in_str_array(keywords, str_tolower(str)) + 1 != KEY_chunked)
+ if (index_in_strings(keywords, str_tolower(str)) + 1 != KEY_chunked)
bb_error_msg_and_die("server wants to do %s transfer encoding", str);
chunked = got_clen = 1;
}
"range\0" Required_argument "l"
"verbose\0" No_argument "v"
"reference\0" Required_argument "\xff" /* no short option */
- "\0";
+ ;
#endif
int chcon_main(int argc, char **argv);
"range\0" Required_argument "l"
"compute\0" No_argument "c"
"help\0" No_argument "h"
- "\0";
+ ;
#endif
#define OPTS_ROLE (1<<0) /* r */
"unquoted\0" No_argument "u"
"alternative\0" No_argument "a"
"name\0" Required_argument "n"
- "\0";
+ ;
#endif
int getopt_main(int argc, char *argv[]);
"hctosys\0" No_argument "s"
"systohc\0" No_argument "w"
"file\0" Required_argument "f"
- "\0";
+ ;
applet_long_options = hwclock_longopts;
#endif
opt_complementary = "r--ws:w--rs:s--wr:l--u:u--l";
if (filteropts) for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) {
char *opteq = strchr(opt, '=');
if (opteq) {
- static const char *const options[] = {
- /* 0 */ "rsize",
- /* 1 */ "wsize",
- /* 2 */ "timeo",
- /* 3 */ "retrans",
- /* 4 */ "acregmin",
- /* 5 */ "acregmax",
- /* 6 */ "acdirmin",
- /* 7 */ "acdirmax",
- /* 8 */ "actimeo",
- /* 9 */ "retry",
- /* 10 */ "port",
- /* 11 */ "mountport",
- /* 12 */ "mounthost",
- /* 13 */ "mountprog",
- /* 14 */ "mountvers",
- /* 15 */ "nfsprog",
- /* 16 */ "nfsvers",
- /* 17 */ "vers",
- /* 18 */ "proto",
- /* 19 */ "namlen",
- /* 20 */ "addr",
- NULL
- };
+ static const char options[] =
+ /* 0 */ "rsize\0"
+ /* 1 */ "wsize\0"
+ /* 2 */ "timeo\0"
+ /* 3 */ "retrans\0"
+ /* 4 */ "acregmin\0"
+ /* 5 */ "acregmax\0"
+ /* 6 */ "acdirmin\0"
+ /* 7 */ "acdirmax\0"
+ /* 8 */ "actimeo\0"
+ /* 9 */ "retry\0"
+ /* 10 */ "port\0"
+ /* 11 */ "mountport\0"
+ /* 12 */ "mounthost\0"
+ /* 13 */ "mountprog\0"
+ /* 14 */ "mountvers\0"
+ /* 15 */ "nfsprog\0"
+ /* 16 */ "nfsvers\0"
+ /* 17 */ "vers\0"
+ /* 18 */ "proto\0"
+ /* 19 */ "namlen\0"
+ /* 20 */ "addr\0";
int val = xatoi_u(opteq + 1);
*opteq = '\0';
- switch (index_in_str_array(options, opt)) {
+ switch (index_in_strings(options, opt)) {
case 0: // "rsize"
data.rsize = val;
break;
}
}
else {
- static const char *const options[] = {
- "bg",
- "fg",
- "soft",
- "hard",
- "intr",
- "posix",
- "cto",
- "ac",
- "tcp",
- "udp",
- "lock",
- NULL
- };
+ static const char options[] =
+ "bg\0"
+ "fg\0"
+ "soft\0"
+ "hard\0"
+ "intr\0"
+ "posix\0"
+ "cto\0"
+ "ac\0"
+ "tcp\0"
+ "udp\0"
+ "lock\0";
int val = 1;
if (!strncmp(opt, "no", 2)) {
val = 0;
opt += 2;
}
- switch (index_in_str_array(options, opt)) {
+ switch (index_in_strings(options, opt)) {
case 0: // "bg"
bg = val;
break;