common BUFSIZ BSS buffer, small reduce code, data and bss

This commit is contained in:
"Vladimir N. Oleynik" 2005-10-15 10:23:55 +00:00
parent 84e7511607
commit 6f347ef9dc
11 changed files with 34 additions and 33 deletions

View File

@ -44,12 +44,13 @@
* to pick a random letter to add to out temporary file. */ * to pick a random letter to add to out temporary file. */
typedef unsigned long int bb_uint64_t; typedef unsigned long int bb_uint64_t;
#define tempFn bb_common_bufsiz1
/* if fn is NULL then input is stdin and output is stdout */ /* if fn is NULL then input is stdin and output is stdout */
static int convert(char *fn, int ConvType) static int convert(char *fn, int ConvType)
{ {
int c, fd; int c, fd;
struct timeval tv; struct timeval tv;
RESERVE_CONFIG_BUFFER(tempFn, BUFSIZ);
static bb_uint64_t value=0; static bb_uint64_t value=0;
FILE *in, *out; FILE *in, *out;

View File

@ -39,7 +39,7 @@ int tee_main(int argc, char **argv)
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
#ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO
ssize_t c; ssize_t c;
RESERVE_CONFIG_BUFFER(buf, BUFSIZ); # define buf bb_common_bufsiz1
#else #else
int c; int c;
#endif #endif
@ -88,10 +88,6 @@ int tee_main(int argc, char **argv)
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
} }
#ifdef CONFIG_FEATURE_CLEAN_UP
RELEASE_CONFIG_BUFFER(buf);
#endif
#else #else
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
while ((c = getchar()) != EOF) { while ((c = getchar()) != EOF) {

View File

@ -38,10 +38,11 @@
static char com_fl, del_fl, sq_fl; static char com_fl, del_fl, sq_fl;
static short in_index, out_index; static short in_index, out_index;
/* these last are pointers to static buffers declared in tr_main */ /* these last are pointers to static buffers declared in tr_main */
static unsigned char *poutput, *pinput; static unsigned char *poutput;
static unsigned char *pvector; static unsigned char *pvector;
static char *pinvec, *poutvec; static char *pinvec, *poutvec;
#define input bb_common_bufsiz1
static void convert(void) static void convert(void)
{ {
@ -51,14 +52,14 @@ static void convert(void)
for (;;) { for (;;) {
if (in_index == read_chars) { if (in_index == read_chars) {
if ((read_chars = read(0, (char *) pinput, BUFSIZ)) <= 0) { if ((read_chars = read(0, input, BUFSIZ)) <= 0) {
if (write(1, (char *) poutput, out_index) != out_index) if (write(1, (char *) poutput, out_index) != out_index)
bb_error_msg(bb_msg_write_error); bb_error_msg(bb_msg_write_error);
exit(0); exit(0);
} }
in_index = 0; in_index = 0;
} }
c = pinput[in_index++]; c = input[in_index++];
coded = pvector[c]; coded = pvector[c];
if (del_fl && pinvec[c]) if (del_fl && pinvec[c])
continue; continue;
@ -208,14 +209,12 @@ extern int tr_main(int argc, char **argv)
int idx = 1; int idx = 1;
int i; int i;
RESERVE_CONFIG_BUFFER(output, BUFSIZ); RESERVE_CONFIG_BUFFER(output, BUFSIZ);
RESERVE_CONFIG_BUFFER(input, BUFSIZ);
RESERVE_CONFIG_UBUFFER(vector, ASCII+1); RESERVE_CONFIG_UBUFFER(vector, ASCII+1);
RESERVE_CONFIG_BUFFER(invec, ASCII+1); RESERVE_CONFIG_BUFFER(invec, ASCII+1);
RESERVE_CONFIG_BUFFER(outvec, ASCII+1); RESERVE_CONFIG_BUFFER(outvec, ASCII+1);
/* ... but make them available globally */ /* ... but make them available globally */
poutput = output; poutput = output;
pinput = input;
pvector = vector; pvector = vector;
pinvec = invec; pinvec = invec;
poutvec = outvec; poutvec = outvec;

View File

@ -2226,7 +2226,8 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds
return (FD_ISSET(0, &rfds)); return (FD_ISSET(0, &rfds));
} }
static Byte readbuffer[BUFSIZ]; #define readbuffer bb_common_bufsiz1
static int readed_for_parse; static int readed_for_parse;
//----- IO Routines -------------------------------------------- //----- IO Routines --------------------------------------------

View File

@ -333,6 +333,12 @@ extern const char * const bb_path_group_file;
extern const char * const bb_path_securetty_file; extern const char * const bb_path_securetty_file;
extern const char * const bb_path_motd_file; extern const char * const bb_path_motd_file;
extern const char * const bb_dev_null; extern const char * const bb_dev_null;
#ifndef BUFSIZ
#define BUFSIZ 4096
#endif
extern char bb_common_bufsiz1[BUFSIZ+1];
/* /*
* You can change LIBBB_DEFAULT_LOGIN_SHELL, but don`t use, * You can change LIBBB_DEFAULT_LOGIN_SHELL, but don`t use,
* use bb_default_login_shell and next defines, * use bb_default_login_shell and next defines,

View File

@ -47,7 +47,8 @@ LIBBB_MOBJ0:=full_version.o \
can_not_create_raw_socket.o perm_denied_are_you_root.o \ can_not_create_raw_socket.o perm_denied_are_you_root.o \
shadow_file.o passwd_file.o group_file.o gshadow_file.o nologin_file.o \ shadow_file.o passwd_file.o group_file.o gshadow_file.o nologin_file.o \
securetty_file.o motd_file.o \ securetty_file.o motd_file.o \
msg_standard_input.o msg_standard_output.o shell_file.o bb_dev_null.o msg_standard_input.o msg_standard_output.o shell_file.o \
bb_dev_null.o bb_common_bufsiz1.o
LIBBB_MSRC1:=$(srcdir)/xfuncs.c LIBBB_MSRC1:=$(srcdir)/xfuncs.c
LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \ LIBBB_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \

View File

@ -101,3 +101,6 @@ const char * const bb_default_login_shell = LIBBB_DEFAULT_LOGIN_SHELL;
const char * const bb_dev_null = "/dev/null"; const char * const bb_dev_null = "/dev/null";
#endif #endif
#ifdef L_bb_common_bufsiz1
char bb_common_bufsiz1[BUFSIZ+1];
#endif

View File

@ -110,15 +110,6 @@ extern void updwtmp(const char *filename, const struct utmp *ut);
#define TCGETA TCGETS #define TCGETA TCGETS
#define TCSETA TCSETS #define TCSETA TCSETS
#define TCSETAW TCSETSW #define TCSETAW TCSETSW
#endif
/*
* This program tries to not use the standard-i/o library. This keeps the
* executable small on systems that do not have shared libraries (System V
* Release <3).
*/
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif #endif
/* /*
@ -744,12 +735,12 @@ static void next_speed(struct termio *tp, struct options *op)
/* return NULL on failure, logname on success */ /* return NULL on failure, logname on success */
static char *get_logname(struct options *op, struct chardata *cp, struct termio *tp) static char *get_logname(struct options *op, struct chardata *cp, struct termio *tp)
{ {
static char logname[BUFSIZ]; #define logname bb_common_bufsiz1
char *bp; char *bp;
char c; /* input character, full eight bits */ char c; /* input character, full eight bits */
char ascval; /* low 7 bits of input character */ char ascval; /* low 7 bits of input character */
int bits; /* # of "1" bits per character */ int bits; /* # of "1" bits per character */
int mask; /* mask with 1 bit up */ int mask; /* mask with 1 bit up */
static char *erase[] = { /* backspace-space-backspace */ static char *erase[] = { /* backspace-space-backspace */
"\010\040\010", /* space parity */ "\010\040\010", /* space parity */
"\010\040\010", /* odd parity */ "\010\040\010", /* odd parity */

View File

@ -21,7 +21,7 @@
#define SULOGIN_PROMPT "\nGive root password for system maintenance\n" \ #define SULOGIN_PROMPT "\nGive root password for system maintenance\n" \
"(or type Control-D for normal startup):" "(or type Control-D for normal startup):"
static const char *forbid[] = { static const char * const forbid[] = {
"ENV", "ENV",
"BASH_ENV", "BASH_ENV",
"HOME", "HOME",
@ -53,11 +53,13 @@ extern int sulogin_main(int argc, char **argv)
char *device = (char *) 0; char *device = (char *) 0;
const char *name = "root"; const char *name = "root";
int timeout = 0; int timeout = 0;
static char pass[BUFSIZ];
#define pass bb_common_bufsiz1
struct passwd pwent; struct passwd pwent;
struct passwd *pwd; struct passwd *pwd;
time_t start, now; time_t start, now;
const char **p; const char * const *p;
#ifdef CONFIG_FEATURE_SHADOWPASSWDS #ifdef CONFIG_FEATURE_SHADOWPASSWDS
struct spwd *spwd = NULL; struct spwd *spwd = NULL;
#endif /* CONFIG_FEATURE_SHADOWPASSWDS */ #endif /* CONFIG_FEATURE_SHADOWPASSWDS */

View File

@ -48,7 +48,9 @@ static void timeout(int signum)
int nc_main(int argc, char **argv) int nc_main(int argc, char **argv)
{ {
int do_listen = 0, lport = 0, delay = 0, wsecs = 0, tmpfd, opt, sfd, x; int do_listen = 0, lport = 0, delay = 0, wsecs = 0, tmpfd, opt, sfd, x;
char buf[BUFSIZ];
#define buf bb_common_bufsiz1
#ifdef CONFIG_NC_GAPING_SECURITY_HOLE #ifdef CONFIG_NC_GAPING_SECURITY_HOLE
char *pr00gie = NULL; char *pr00gie = NULL;
#endif #endif

View File

@ -568,7 +568,7 @@ struct parsefile {
}; };
static struct parsefile basepf; /* top level input file */ static struct parsefile basepf; /* top level input file */
static char basebuf[IBUFSIZ]; /* buffer for top level input file */ #define basebuf bb_common_bufsiz1 /* buffer for top level input file */
static struct parsefile *parsefile = &basepf; /* current input file */ static struct parsefile *parsefile = &basepf; /* current input file */
@ -5939,7 +5939,6 @@ varunset(const char *end, const char *var, const char *umsg, int varflags)
*/ */
#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ #define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
#define IBUFSIZ (BUFSIZ + 1)
static void pushfile(void); static void pushfile(void);