From 0a7c8ef6e220b5f8fff4f2cb0af630255a2a6a58 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 22 Feb 2006 17:01:00 +0000 Subject: [PATCH] Patch from Denis Vlasenko to constify things and fix a few typos. --- archival/dpkg.c | 7 +++- archival/unzip.c | 2 +- coreutils/env.c | 3 +- coreutils/stat.c | 5 +-- init/halt.c | 6 ++- miscutils/devfsd.c | 69 +++++++++++++++++-------------- miscutils/hdparm.c | 4 +- networking/libiproute/ipaddress.c | 23 +++++++---- networking/udhcp/packet.c | 7 ++-- 9 files changed, 73 insertions(+), 53 deletions(-) diff --git a/archival/dpkg.c b/archival/dpkg.c index 7ed17d711..70eaefb94 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c @@ -552,9 +552,12 @@ static void free_package(common_node_t *node) static unsigned int fill_package_struct(char *control_buffer) { + static const char *const field_names[] = { "Package", "Version", + "Pre-Depends", "Depends","Replaces", "Provides", + "Conflicts", "Suggests", "Recommends", "Enhances", 0 + }; + common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t)); - const char *field_names[] = { "Package", "Version", "Pre-Depends", "Depends", - "Replaces", "Provides", "Conflicts", "Suggests", "Recommends", "Enhances", 0}; char *field_name; char *field_value; int field_start = 0; diff --git a/archival/unzip.c b/archival/unzip.c index f602db12d..ff2b1a266 100644 --- a/archival/unzip.c +++ b/archival/unzip.c @@ -220,7 +220,7 @@ extern int unzip_main(int argc, char **argv) overwrite = (overwrite == o_prompt) ? o_never : overwrite; } else { - char *extn[] = {"", ".zip", ".ZIP"}; + static const char *const extn[] = {"", ".zip", ".ZIP"}; int orig_src_fn_len = strlen(src_fn); for(i = 0; (i < 3) && (src_fd == -1); i++) { strcpy(src_fn + orig_src_fn_len, extn[i]); diff --git a/coreutils/env.c b/coreutils/env.c index d59e738f1..156f4e77d 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -59,8 +59,9 @@ static const struct option env_long_options[] = { extern int env_main(int argc, char** argv) { + static char *cleanenv[1] = { NULL }; + char **ep, *p; - char *cleanenv[1] = { NULL }; unsigned long opt; llist_t *unset_env = NULL; extern char **environ; diff --git a/coreutils/stat.c b/coreutils/stat.c index 44289fbaa..c845a2aa7 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -120,12 +120,11 @@ static char const *human_fstype(long f_type) { 0x858458f6, "romfs" }, { 0x73717368, "squashfs" }, { 0x62656572, "sysfs" }, - { 0, "UNKNOWN" }, - { 0, NULL } + { 0, "UNKNOWN" } }; for (i=0; humantypes[i].type; ++i) if (humantypes[i].type == f_type) - return humantypes[i].fs; + break; return humantypes[i].fs; } diff --git a/init/halt.c b/init/halt.c index 34479742e..38ca38222 100644 --- a/init/halt.c +++ b/init/halt.c @@ -15,9 +15,11 @@ int halt_main(int argc, char *argv[]) { + static const int magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT}; + static const int signals[] = {SIGUSR1, SIGUSR2, SIGTERM}; + char *delay = "hpr"; - int which, flags, magic[] = {RB_HALT_SYSTEM, RB_POWER_OFF, RB_AUTOBOOT}, - signals[] = {SIGUSR1, SIGUSR2, SIGTERM}, rc = 1; + int which, flags, rc = 1; /* Figure out which applet we're running */ for(which=0;delay[which]!=*bb_applet_name;which++); diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index fd5f54763..f99a94628 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -606,17 +606,18 @@ static void process_config_line (const char *line, unsigned long *event_mask) char name[STRING_LENGTH]; char * msg=""; char *ptr; + int i; /* !!!! Only Uppercase Keywords in devsfd.conf */ - const char *options[] = { "CLEAR_CONFIG", "INCLUDE", "OPTIONAL_INCLUDE", "RESTORE", - "PERMISSIONS", "MODLOAD", "EXECUTE", "COPY", "IGNORE", - "MKOLDCOMPAT", "MKNEWCOMPAT","RMOLDCOMPAT", "RMNEWCOMPAT", 0 }; - - int i; + static const char *const options[] = { + "CLEAR_CONFIG", "INCLUDE", "OPTIONAL_INCLUDE", + "RESTORE", "PERMISSIONS", "MODLOAD", "EXECUTE", + "COPY", "IGNORE", "MKOLDCOMPAT", "MKNEWCOMPAT", + "RMOLDCOMPAT", "RMNEWCOMPAT", 0 + }; debug_msg_logger(LOG_INFO, __FUNCTION__); - for (count = 0; count < MAX_ARGS; ++count) p[count][0] = '\0'; num_args = sscanf (line, "%s %s %s %s %s %s %s %s %s %s", when, name, what, @@ -678,7 +679,7 @@ static void process_config_line (const char *line, unsigned long *event_mask) if ( ( ptr = strchr (p[0], '.') ) == NULL ) { msg="UID.GID"; - goto process_config_line_err; /*"missing '.' in UID.GID */ + goto process_config_line_err; /*"missing '.' in UID.GID"*/ } *ptr++ = '\0'; @@ -993,17 +994,19 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int unsigned int i; char rewind_; /* 1 to 5 "scsi/" , 6 to 9 "ide/host" */ - const char *fmt[] = { NULL , - "sg/c%db%dt%du%d", /* scsi/generic */ - "sd/c%db%dt%du%d", /* scsi/disc */ - "sr/c%db%dt%du%d", /* scsi/cd */ - "sd/c%db%dt%du%dp%d", /* scsi/part */ - "st/c%db%dt%du%dm%d%c", /* scsi/mt */ - "ide/hd/c%db%dt%du%d", /* ide/host/disc */ - "ide/cd/c%db%dt%du%d", /* ide/host/cd */ - "ide/hd/c%db%dt%du%dp%d", /* ide/host/part */ - "ide/mt/c%db%dt%du%d%s", /* ide/host/mt */ - NULL }; + static const char *const fmt[] = { + NULL , + "sg/c%db%dt%du%d", /* scsi/generic */ + "sd/c%db%dt%du%d", /* scsi/disc */ + "sr/c%db%dt%du%d", /* scsi/cd */ + "sd/c%db%dt%du%dp%d", /* scsi/part */ + "st/c%db%dt%du%dm%d%c", /* scsi/mt */ + "ide/hd/c%db%dt%du%d", /* ide/host/disc */ + "ide/cd/c%db%dt%du%d", /* ide/host/cd */ + "ide/hd/c%db%dt%du%dp%d", /* ide/host/part */ + "ide/mt/c%db%dt%du%d%s", /* ide/host/mt */ + NULL + }; /* First construct compatibility name */ switch (action) @@ -1596,20 +1599,22 @@ const char *get_old_name (const char *devname, unsigned int namelen, const char *pty2; size_t len; /* 1 to 5 "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */ - const char *fmt[] = { NULL , - "sg%u", /* scsi/generic */ - NULL, /* scsi/disc */ - "sr%u", /* scsi/cd */ - NULL, /* scsi/part */ - "nst%u%c", /* scsi/mt */ - "hd%c" , /* ide/host/disc */ - "hd%c" , /* ide/host/cd */ - "hd%c%s", /* ide/host/part */ - "%sht%d", /* ide/host/mt */ - "sbpcd%u", /* sbp/ */ - "vcs%s", /* vcc/ */ - "%cty%c%c", /* pty/ */ - NULL }; + static const char *const fmt[] = { + NULL , + "sg%u", /* scsi/generic */ + NULL, /* scsi/disc */ + "sr%u", /* scsi/cd */ + NULL, /* scsi/part */ + "nst%u%c", /* scsi/mt */ + "hd%c" , /* ide/host/disc */ + "hd%c" , /* ide/host/cd */ + "hd%c%s", /* ide/host/part */ + "%sht%d", /* ide/host/mt */ + "sbpcd%u", /* sbp/ */ + "vcs%s", /* vcc/ */ + "%cty%c%c", /* pty/ */ + NULL + }; debug_msg_logger(LOG_INFO, __FUNCTION__); diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index 750cb499b..e733c9172 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -1305,10 +1305,12 @@ static const char * const BuffType[] = {"unknown", "1Sect", "DualPort", "DualPor static void dump_identity (const struct hd_driveid *id) { int i; - char pmodes[64] = {0,}, dmodes[128]={0,}, umodes[128]={0,}; + char pmodes[64], dmodes[128], umodes[128]; const unsigned short int *id_regs= (const void*) id; unsigned long capacity; + pmodes[0] = dmodes[0] = umodes[0] = '\0'; + printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={", id->model, id->fw_rev, id->serial_no); for (i=0; i<=15; i++) diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 9db79eacb..d7a0c5177 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -416,7 +416,8 @@ static void ipaddr_reset_filter(int _oneline) extern int ipaddr_list_or_flush(int argc, char **argv, int flush) { - const char *option[] = { "to", "scope", "up", "label", "dev", 0 }; + static const char *const option[] = { "to", "scope", "up", "label", "dev", 0 }; + struct nlmsg_list *linfo = NULL; struct nlmsg_list *ainfo = NULL; struct nlmsg_list *l; @@ -499,7 +500,7 @@ extern int ipaddr_list_or_flush(int argc, char **argv, int flush) if (filter_dev) { filter.ifindex = ll_name_to_index(filter_dev); if (filter.ifindex <= 0) { - bb_error_msg("Device \"%s\" does not exist.", filter_dev); + bb_error_msg("Device \"%s\" does not exist", filter_dev); return -1; } } @@ -631,8 +632,11 @@ static int default_scope(inet_prefix *lcl) static int ipaddr_modify(int cmd, int argc, char **argv) { - const char *option[] = { "peer", "remote", "broadcast", "brd", - "anycast", "scope", "dev", "label", "local", 0 }; + static const char *const option[] = { + "peer", "remote", "broadcast", "brd", + "anycast", "scope", "dev", "label", "local", 0 + }; + struct rtnl_handle rth; struct { struct nlmsghdr n; @@ -716,7 +720,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv) uint32_t scope = 0; NEXT_ARG(); if (rtnl_rtscope_a2n(&scope, *argv)) { - invarg(*argv, "invalid scope value."); + invarg(*argv, "invalid scope value"); } req.ifa.ifa_scope = scope; scoped = 1; @@ -749,11 +753,11 @@ static int ipaddr_modify(int cmd, int argc, char **argv) } if (d == NULL) { - bb_error_msg("Not enough information: \"dev\" argument is required."); + bb_error_msg("Not enough information: \"dev\" argument is required"); return -1; } if (l && matches(d, l) != 0) { - bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s).", d, l); + bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); } if (peer_len == 0 && local_len && cmd != RTM_DELADDR) { @@ -803,7 +807,10 @@ static int ipaddr_modify(int cmd, int argc, char **argv) extern int do_ipaddr(int argc, char **argv) { - const char *commands[] = { "add", "delete", "list", "show", "lst", "flush", 0 }; + static const char *const commands[] = { + "add", "delete", "list", "show", "lst", "flush", 0 + }; + int command_num = 2; if (*argv) { diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 222dd24e0..fe74b828f 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c @@ -46,12 +46,13 @@ void init_header(struct dhcpMessage *packet, char type) /* read a packet from socket fd, return -1 on read error, -2 on packet error */ int get_packet(struct dhcpMessage *packet, int fd) { - int bytes; - int i; - const char broken_vendors[][8] = { + static const char broken_vendors[][8] = { "MSFT 98", "" }; + + int bytes; + int i; char unsigned *vendor; memset(packet, 0, sizeof(struct dhcpMessage)); -- 2.25.1