use auto_string() where appropriate to kill a few statics
Custom linker script 'busybox_ldscript' found, using it function old new delta static.str 4 - -4 static.passwd 4 0 -4 bb_ask 322 311 -11 ether_print 63 47 -16 UNSPEC_print 82 66 -16 INET_sprint 59 38 -21 INET6_sprint 54 30 -24 make_human_readable_str 292 235 -57 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/7 up/down: 0/-153) Total: -153 bytes text data bss dec hex filename 939880 992 17480 958352 e9f90 busybox_old 939736 992 17456 958184 e9ee8 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e52da5570e
commit
02859aaeb2
@ -1,7 +1,6 @@
|
|||||||
/* vi: set sw=4 ts=4: */
|
/* vi: set sw=4 ts=4: */
|
||||||
/*
|
/*
|
||||||
* Ask for a password
|
* Ask for a password
|
||||||
* I use a static buffer in this function. Plan accordingly.
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||||
*
|
*
|
||||||
@ -23,8 +22,8 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
|||||||
{
|
{
|
||||||
/* Was static char[BIGNUM] */
|
/* Was static char[BIGNUM] */
|
||||||
enum { sizeof_passwd = 128 };
|
enum { sizeof_passwd = 128 };
|
||||||
static char *passwd;
|
|
||||||
|
|
||||||
|
char *passwd;
|
||||||
char *ret;
|
char *ret;
|
||||||
int i;
|
int i;
|
||||||
struct sigaction sa, oldsa;
|
struct sigaction sa, oldsa;
|
||||||
@ -62,8 +61,7 @@ char* FAST_FUNC bb_ask(const int fd, int timeout, const char *prompt)
|
|||||||
alarm(timeout);
|
alarm(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passwd)
|
passwd = auto_string(xmalloc(sizeof_passwd));
|
||||||
passwd = xmalloc(sizeof_passwd);
|
|
||||||
ret = passwd;
|
ret = passwd;
|
||||||
i = 0;
|
i = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -37,8 +37,6 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val,
|
|||||||
'\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
|
'\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *str;
|
|
||||||
|
|
||||||
unsigned frac; /* 0..9 - the fractional digit */
|
unsigned frac; /* 0..9 - the fractional digit */
|
||||||
const char *u;
|
const char *u;
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
@ -81,12 +79,7 @@ const char* FAST_FUNC make_human_readable_str(unsigned long long val,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str) {
|
return auto_string(xasprintf(fmt, val, frac, *u));
|
||||||
/* sufficient for any width of val */
|
|
||||||
str = xmalloc(sizeof(val)*3 + 2 + 3);
|
|
||||||
}
|
|
||||||
sprintf(str, fmt, val, frac, *u);
|
|
||||||
return str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1142,19 +1142,19 @@ static void signal_handler(int sig)
|
|||||||
|
|
||||||
static const char *get_variable(const char *variable, void *info)
|
static const char *get_variable(const char *variable, void *info)
|
||||||
{
|
{
|
||||||
static char sbuf[sizeof(int)*3 + 2]; /* sign and NUL */
|
|
||||||
static char *hostname;
|
static char *hostname;
|
||||||
|
|
||||||
struct get_variable_info *gv_info = info;
|
struct get_variable_info *gv_info = info;
|
||||||
const char *field_names[] = {
|
const char *field_names[] = {
|
||||||
"hostname", "mntpt", "devpath", "devname",
|
"hostname", "mntpt", "devpath", "devname", "uid", "gid", "mode",
|
||||||
"uid", "gid", "mode", hostname, mount_point,
|
NULL, mount_point, gv_info->devpath, gv_info->devname, NULL
|
||||||
gv_info->devpath, gv_info->devname, NULL
|
|
||||||
};
|
};
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!hostname)
|
if (!hostname)
|
||||||
hostname = safe_gethostname();
|
hostname = safe_gethostname();
|
||||||
|
field_names[7] = hostname;
|
||||||
|
|
||||||
/* index_in_str_array returns i>=0 */
|
/* index_in_str_array returns i>=0 */
|
||||||
i = index_in_str_array(field_names, variable);
|
i = index_in_str_array(field_names, variable);
|
||||||
|
|
||||||
@ -1164,12 +1164,11 @@ static const char *get_variable(const char *variable, void *info)
|
|||||||
return field_names[i + 7];
|
return field_names[i + 7];
|
||||||
|
|
||||||
if (i == 4)
|
if (i == 4)
|
||||||
sprintf(sbuf, "%u", gv_info->info->uid);
|
return auto_string(xasprintf("%u", gv_info->info->uid));
|
||||||
else if (i == 5)
|
if (i == 5)
|
||||||
sprintf(sbuf, "%u", gv_info->info->gid);
|
return auto_string(xasprintf("%u", gv_info->info->gid));
|
||||||
else if (i == 6)
|
/* i == 6 */
|
||||||
sprintf(sbuf, "%o", gv_info->info->mode);
|
return auto_string(xasprintf("%o", gv_info->info->mode));
|
||||||
return sbuf;
|
|
||||||
} /* End Function get_variable */
|
} /* End Function get_variable */
|
||||||
|
|
||||||
static void service(struct stat statbuf, char *path)
|
static void service(struct stat statbuf, char *path)
|
||||||
|
@ -89,13 +89,9 @@ struct in6_ifreq {
|
|||||||
/* Display an Internet socket address. */
|
/* Display an Internet socket address. */
|
||||||
static const char* FAST_FUNC INET_sprint(struct sockaddr *sap, int numeric)
|
static const char* FAST_FUNC INET_sprint(struct sockaddr *sap, int numeric)
|
||||||
{
|
{
|
||||||
static char *buff; /* defaults to NULL */
|
|
||||||
|
|
||||||
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
|
||||||
return "[NONE SET]";
|
return "[NONE SET]";
|
||||||
free(buff);
|
return auto_string(INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00));
|
||||||
buff = INET_rresolve((struct sockaddr_in *) sap, numeric, 0xffffff00);
|
|
||||||
return buff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNUSED_AND_BUGGY
|
#ifdef UNUSED_AND_BUGGY
|
||||||
@ -171,13 +167,9 @@ static const struct aftype inet_aftype = {
|
|||||||
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
|
/* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */
|
||||||
static const char* FAST_FUNC INET6_sprint(struct sockaddr *sap, int numeric)
|
static const char* FAST_FUNC INET6_sprint(struct sockaddr *sap, int numeric)
|
||||||
{
|
{
|
||||||
static char *buff;
|
|
||||||
|
|
||||||
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
|
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
|
||||||
return "[NONE SET]";
|
return "[NONE SET]";
|
||||||
free(buff);
|
return auto_string(INET6_rresolve((struct sockaddr_in6 *) sap, numeric));
|
||||||
buff = INET6_rresolve((struct sockaddr_in6 *) sap, numeric);
|
|
||||||
return buff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNUSED
|
#ifdef UNUSED
|
||||||
@ -223,13 +215,11 @@ static const struct aftype inet6_aftype = {
|
|||||||
/* Display an UNSPEC address. */
|
/* Display an UNSPEC address. */
|
||||||
static char* FAST_FUNC UNSPEC_print(unsigned char *ptr)
|
static char* FAST_FUNC UNSPEC_print(unsigned char *ptr)
|
||||||
{
|
{
|
||||||
static char *buff;
|
char *buff;
|
||||||
|
|
||||||
char *pos;
|
char *pos;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (!buff)
|
buff = auto_string(xmalloc(sizeof(struct sockaddr) * 3 + 1));
|
||||||
buff = xmalloc(sizeof(struct sockaddr) * 3 + 1);
|
|
||||||
pos = buff;
|
pos = buff;
|
||||||
for (i = 0; i < sizeof(struct sockaddr); i++) {
|
for (i = 0; i < sizeof(struct sockaddr); i++) {
|
||||||
/* careful -- not every libc's sprintf returns # bytes written */
|
/* careful -- not every libc's sprintf returns # bytes written */
|
||||||
@ -712,14 +702,12 @@ static const struct hwtype loop_hwtype = {
|
|||||||
/* Display an Ethernet address in readable format. */
|
/* Display an Ethernet address in readable format. */
|
||||||
static char* FAST_FUNC ether_print(unsigned char *ptr)
|
static char* FAST_FUNC ether_print(unsigned char *ptr)
|
||||||
{
|
{
|
||||||
static char *buff;
|
char *buff;
|
||||||
|
|
||||||
free(buff);
|
|
||||||
buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X",
|
buff = xasprintf("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
|
(ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
|
||||||
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
|
(ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
|
||||||
);
|
);
|
||||||
return buff;
|
return auto_string(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct hwtype ether_hwtype = {
|
static const struct hwtype ether_hwtype = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user