diff options
author | Denis Vlasenko | 2008-07-21 23:05:26 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-07-21 23:05:26 +0000 |
commit | 5415c856eaccd1bc5d064022770a288f43b2e94f (patch) | |
tree | 5973db4e6f81b5e311e8944700ded5db1083d440 /networking | |
parent | b74a2dba571d1c5a6127c683fb50923336d9c59f (diff) | |
download | busybox-5415c856eaccd1bc5d064022770a288f43b2e94f.zip busybox-5415c856eaccd1bc5d064022770a288f43b2e94f.tar.gz |
libbb: [x]fopen_for_{read,write} introduced and used.
(by Valdimir)
function old new delta
config_open2 - 41 +41
config_read 507 542 +35
find_pair 169 187 +18
fopen_for_write - 14 +14
fopen_for_read - 14 +14
find_main 406 418 +12
xfopen_for_write - 10 +10
xfopen_for_read - 10 +10
popstring 134 140 +6
parse_inittab 396 401 +5
next_token 923 928 +5
pack_gzip 1659 1661 +2
bb__parsespent 117 119 +2
fallbackSort 1719 1717 -2
evalvar 1376 1374 -2
qrealloc 36 33 -3
...
...
...
...
singlemount 4579 4569 -10
process_stdin 443 433 -10
patch_main 1111 1101 -10
ifupdown_main 2175 2165 -10
file_action_grep 90 80 -10
uuidcache_init 649 637 -12
hush_main 797 785 -12
read_config 230 217 -13
dpkg_main 3835 3820 -15
read_line_input 3134 3110 -24
sysctl_main 232 203 -29
config_open 40 10 -30
WARN_BAD_LINE 44 - -44
login_main 1714 1575 -139
------------------------------------------------------------------------------
(add/remove: 5/1 grow/shrink: 8/74 up/down: 174/-737) Total: -563 bytes
Diffstat (limited to 'networking')
-rw-r--r-- | networking/arp.c | 2 | ||||
-rw-r--r-- | networking/dnsd.c | 5 | ||||
-rw-r--r-- | networking/hostname.c | 29 | ||||
-rw-r--r-- | networking/httpd.c | 2 | ||||
-rw-r--r-- | networking/ifupdown.c | 6 | ||||
-rw-r--r-- | networking/interface.c | 2 | ||||
-rw-r--r-- | networking/libiproute/iproute.c | 2 | ||||
-rw-r--r-- | networking/libiproute/rt_names.c | 2 | ||||
-rw-r--r-- | networking/nameif.c | 2 | ||||
-rw-r--r-- | networking/netstat.c | 2 | ||||
-rw-r--r-- | networking/route.c | 4 | ||||
-rw-r--r-- | networking/traceroute.c | 2 | ||||
-rw-r--r-- | networking/udhcp/files.c | 4 |
13 files changed, 27 insertions, 37 deletions
diff --git a/networking/arp.c b/networking/arp.c index ac8c870..620f7c0 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -382,7 +382,7 @@ static int arp_show(char *name) } host = xstrdup(ap->sprint(&sa, 1)); } - fp = xfopen("/proc/net/arp", "r"); + fp = xfopen_for_read("/proc/net/arp"); /* Bypass header -- read one line */ fgets(line, sizeof(line), fp); diff --git a/networking/dnsd.c b/networking/dnsd.c index 0047a84..efb5cfb 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c @@ -113,7 +113,7 @@ static void dnsentryinit(void) parser = config_open(fileconf); if (parser) { char *token[2]; - while (config_read(parser, token, 2, 0, "# \t", 0)) { + while (config_read(parser, token, 2, 2, "# \t", 0)) { unsigned int a,b,c,d; /* * Assumes all host names are lower case only @@ -121,7 +121,8 @@ static void dnsentryinit(void) * Presently the dot is copied into name without * converting to a length/string substring for that label. */ - if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) +// if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) + if (sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) continue; m = xzalloc(sizeof(*m)); diff --git a/networking/hostname.c b/networking/hostname.c index 93cbc96..dd2a206 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -16,28 +16,19 @@ static void do_sethostname(char *s, int isfile) { - FILE *f; - if (!s) return; - if (!isfile) { - if (sethostname(s, strlen(s)) < 0) { - if (errno == EPERM) - bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); - bb_perror_msg_and_die("sethostname"); - } - } else { - f = xfopen(s, "r"); -#define strbuf bb_common_bufsiz1 - while (fgets(strbuf, sizeof(strbuf), f) != NULL) { - if (strbuf[0] == '#') { - continue; - } - chomp(strbuf); - do_sethostname(strbuf, 0); + if (isfile) { + parser_t *parser = config_open2(s, xfopen_for_read); + while (config_read(parser, &s, 1, 1, "# \t", 0)) { + do_sethostname(s, 0); } if (ENABLE_FEATURE_CLEAN_UP) - fclose(f); + config_close(parser); + } else if (sethostname(s, strlen(s)) < 0) { + if (errno == EPERM) + bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); + bb_perror_msg_and_die("sethostname"); } } @@ -98,5 +89,5 @@ int hostname_main(int argc, char **argv) } if (ENABLE_FEATURE_CLEAN_UP) free(buf); - return 0; + return EXIT_SUCCESS; } diff --git a/networking/httpd.c b/networking/httpd.c index 8c4242e..82891f1 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -518,7 +518,7 @@ static void parse_conf(const char *path, int flag) sprintf((char *)filename, "%s/%s", path, httpd_conf); } - while ((f = fopen(filename, "r")) == NULL) { + while ((f = fopen_for_read(filename)) == NULL) { if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) { /* config file not found, no changes to config */ return; diff --git a/networking/ifupdown.c b/networking/ifupdown.c index cb937ca..c0e9e81 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c @@ -692,7 +692,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) enum { NONE, IFACE, MAPPING } currently_processing = NONE; defn = xzalloc(sizeof(*defn)); - f = xfopen(filename, "r"); + f = xfopen_for_read(filename); while ((buf = xmalloc_fgetline(f)) != NULL) { #if ENABLE_DESKTOP @@ -1090,7 +1090,7 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface) static llist_t *read_iface_state(void) { llist_t *state_list = NULL; - FILE *state_fp = fopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "r"); + FILE *state_fp = fopen_for_read(CONFIG_IFUPDOWN_IFSTATE_PATH); if (state_fp) { char *start, *end_ptr; @@ -1256,7 +1256,7 @@ int ifupdown_main(int argc, char **argv) } /* Actually write the new state */ - state_fp = xfopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "w"); + state_fp = xfopen_for_write(CONFIG_IFUPDOWN_IFSTATE_PATH); state = state_list; while (state) { if (state->data) { diff --git a/networking/interface.c b/networking/interface.c index 83b24f1..065b4ba 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -990,7 +990,7 @@ static void ife_print(struct interface *ptr) #define IPV6_ADDR_MAPPED 0x1000U #define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ - f = fopen(_PATH_PROCNET_IFINET6, "r"); + f = fopen_for_read(_PATH_PROCNET_IFINET6); if (f != NULL) { while (fscanf (f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 17af41f..bdccad6 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c @@ -64,7 +64,7 @@ static unsigned get_hz(void) if (hz_internal) return hz_internal; - fp = fopen("/proc/net/psched", "r"); + fp = fopen_for_read("/proc/net/psched"); if (fp) { unsigned nom, denom; diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c index 797c83b..b22df9c 100644 --- a/networking/libiproute/rt_names.c +++ b/networking/libiproute/rt_names.c @@ -18,7 +18,7 @@ static void rtnl_tab_initialize(const char *file, const char **tab, int size) char buf[512]; FILE *fp; - fp = fopen(file, "r"); + fp = fopen_for_read(file); if (!fp) return; while (fgets(buf, sizeof(buf), fp)) { diff --git a/networking/nameif.c b/networking/nameif.c index 76a8cb7..5a3bd60 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -170,7 +170,7 @@ int nameif_main(int argc, char **argv) } ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); - ifh = xfopen("/proc/net/dev", "r"); + ifh = xfopen_for_read("/proc/net/dev"); linenum = 0; while (clist) { diff --git a/networking/netstat.c b/networking/netstat.c index 24b2654..46510ac 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -466,7 +466,7 @@ static void do_info(const char *file, const char *name, int (*proc)(int, char *) FILE *procinfo; char *buffer; - procinfo = fopen(file, "r"); + procinfo = fopen_for_read(file); if (procinfo == NULL) { if (errno != ENOENT) { bb_simple_perror_msg(file); diff --git a/networking/route.c b/networking/route.c index 7b6d4f4..2bc2f92 100644 --- a/networking/route.c +++ b/networking/route.c @@ -484,7 +484,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) struct sockaddr_in s_addr; struct in_addr mask; - FILE *fp = xfopen("/proc/net/route", "r"); + FILE *fp = xfopen_for_read("/proc/net/route"); printf("Kernel IP routing table\n" "Destination Gateway Genmask Flags %s Iface\n", @@ -552,7 +552,7 @@ static void INET6_displayroutes(void) int iflags, metric, refcnt, use, prefix_len, slen; struct sockaddr_in6 snaddr6; - FILE *fp = xfopen("/proc/net/ipv6_route", "r"); + FILE *fp = xfopen_for_read("/proc/net/ipv6_route"); printf("Kernel IPv6 routing table\n%-44s%-40s" "Flags Metric Ref Use Iface\n", diff --git a/networking/traceroute.c b/networking/traceroute.c index f16fc79..4e6ca2d 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -508,7 +508,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) struct IFADDRLIST *al; char buf[256], tdevice[256], device[256]; - f = xfopen("/proc/net/route", "r"); + f = xfopen_for_read("/proc/net/route"); /* Find the appropriate interface */ n = 0; diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index fe6bff4..264a988 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c @@ -321,9 +321,7 @@ void read_config(const char *file) if (!parser) return; - while (config_read(parser, token, 2, 0, "# \t", PARSE_LAST_IS_GREEDY)) { - if (!token[1]) - continue; + while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) { for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { if (!strcasecmp(token[0], k->keyword)) { if (!k->handler(token[1], k->var)) { |