From 6f347ef9dc540aaea025c0575e586817cd85cc8e Mon Sep 17 00:00:00 2001 From: "\"Vladimir N. Oleynik\"" Date: Sat, 15 Oct 2005 10:23:55 +0000 Subject: [PATCH] common BUFSIZ BSS buffer, small reduce code, data and bss --- coreutils/dos2unix.c | 3 ++- coreutils/tee.c | 6 +----- coreutils/tr.c | 9 ++++----- editors/vi.c | 3 ++- include/libbb.h | 6 ++++++ libbb/Makefile.in | 3 ++- libbb/messages.c | 3 +++ loginutils/getty.c | 19 +++++-------------- loginutils/sulogin.c | 8 +++++--- networking/nc.c | 4 +++- shell/ash.c | 3 +-- 11 files changed, 34 insertions(+), 33 deletions(-) diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index 0c419aca7..0464df76f 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c @@ -44,12 +44,13 @@ * to pick a random letter to add to out temporary file. */ typedef unsigned long int bb_uint64_t; +#define tempFn bb_common_bufsiz1 + /* if fn is NULL then input is stdin and output is stdout */ static int convert(char *fn, int ConvType) { int c, fd; struct timeval tv; - RESERVE_CONFIG_BUFFER(tempFn, BUFSIZ); static bb_uint64_t value=0; FILE *in, *out; diff --git a/coreutils/tee.c b/coreutils/tee.c index ba2e10f90..1160fc9dd 100644 --- a/coreutils/tee.c +++ b/coreutils/tee.c @@ -39,7 +39,7 @@ int tee_main(int argc, char **argv) int retval = EXIT_SUCCESS; #ifdef CONFIG_FEATURE_TEE_USE_BLOCK_IO ssize_t c; - RESERVE_CONFIG_BUFFER(buf, BUFSIZ); +# define buf bb_common_bufsiz1 #else int c; #endif @@ -88,10 +88,6 @@ int tee_main(int argc, char **argv) retval = EXIT_FAILURE; } -#ifdef CONFIG_FEATURE_CLEAN_UP - RELEASE_CONFIG_BUFFER(buf); -#endif - #else setvbuf(stdout, NULL, _IONBF, 0); while ((c = getchar()) != EOF) { diff --git a/coreutils/tr.c b/coreutils/tr.c index 6e3f97b36..e9eca4c60 100644 --- a/coreutils/tr.c +++ b/coreutils/tr.c @@ -38,10 +38,11 @@ static char com_fl, del_fl, sq_fl; static short in_index, out_index; /* 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 char *pinvec, *poutvec; +#define input bb_common_bufsiz1 static void convert(void) { @@ -51,14 +52,14 @@ static void convert(void) for (;;) { 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) bb_error_msg(bb_msg_write_error); exit(0); } in_index = 0; } - c = pinput[in_index++]; + c = input[in_index++]; coded = pvector[c]; if (del_fl && pinvec[c]) continue; @@ -208,14 +209,12 @@ extern int tr_main(int argc, char **argv) int idx = 1; int i; RESERVE_CONFIG_BUFFER(output, BUFSIZ); - RESERVE_CONFIG_BUFFER(input, BUFSIZ); RESERVE_CONFIG_UBUFFER(vector, ASCII+1); RESERVE_CONFIG_BUFFER(invec, ASCII+1); RESERVE_CONFIG_BUFFER(outvec, ASCII+1); /* ... but make them available globally */ poutput = output; - pinput = input; pvector = vector; pinvec = invec; poutvec = outvec; diff --git a/editors/vi.c b/editors/vi.c index 1cc127036..e6c87560d 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -2226,7 +2226,8 @@ static int mysleep(int hund) // sleep for 'h' 1/100 seconds return (FD_ISSET(0, &rfds)); } -static Byte readbuffer[BUFSIZ]; +#define readbuffer bb_common_bufsiz1 + static int readed_for_parse; //----- IO Routines -------------------------------------------- diff --git a/include/libbb.h b/include/libbb.h index e3087db18..b7dd48775 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -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_motd_file; 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, * use bb_default_login_shell and next defines, diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 69f8779d2..fb4910018 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in @@ -47,7 +47,8 @@ LIBBB_MOBJ0:=full_version.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 \ 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_MOBJ1:=xmalloc.o xrealloc.o xcalloc.o xstrdup.o xstrndup.o \ diff --git a/libbb/messages.c b/libbb/messages.c index 9a77aa64b..e11dddc50 100644 --- a/libbb/messages.c +++ b/libbb/messages.c @@ -101,3 +101,6 @@ const char * const bb_default_login_shell = LIBBB_DEFAULT_LOGIN_SHELL; const char * const bb_dev_null = "/dev/null"; #endif +#ifdef L_bb_common_bufsiz1 +char bb_common_bufsiz1[BUFSIZ+1]; +#endif diff --git a/loginutils/getty.c b/loginutils/getty.c index db9a150e0..e8643ef93 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c @@ -110,15 +110,6 @@ extern void updwtmp(const char *filename, const struct utmp *ut); #define TCGETA TCGETS #define TCSETA TCSETS #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 /* @@ -744,12 +735,12 @@ static void next_speed(struct termio *tp, struct options *op) /* return NULL on failure, logname on success */ 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 c; /* input character, full eight bits */ - char ascval; /* low 7 bits of input character */ - int bits; /* # of "1" bits per character */ - int mask; /* mask with 1 bit up */ + char c; /* input character, full eight bits */ + char ascval; /* low 7 bits of input character */ + int bits; /* # of "1" bits per character */ + int mask; /* mask with 1 bit up */ static char *erase[] = { /* backspace-space-backspace */ "\010\040\010", /* space parity */ "\010\040\010", /* odd parity */ diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c index a458b6ed7..4e689ad68 100644 --- a/loginutils/sulogin.c +++ b/loginutils/sulogin.c @@ -21,7 +21,7 @@ #define SULOGIN_PROMPT "\nGive root password for system maintenance\n" \ "(or type Control-D for normal startup):" -static const char *forbid[] = { +static const char * const forbid[] = { "ENV", "BASH_ENV", "HOME", @@ -53,11 +53,13 @@ extern int sulogin_main(int argc, char **argv) char *device = (char *) 0; const char *name = "root"; int timeout = 0; - static char pass[BUFSIZ]; + +#define pass bb_common_bufsiz1 + struct passwd pwent; struct passwd *pwd; time_t start, now; - const char **p; + const char * const *p; #ifdef CONFIG_FEATURE_SHADOWPASSWDS struct spwd *spwd = NULL; #endif /* CONFIG_FEATURE_SHADOWPASSWDS */ diff --git a/networking/nc.c b/networking/nc.c index 8f641ae4f..fda1fb8f6 100644 --- a/networking/nc.c +++ b/networking/nc.c @@ -48,7 +48,9 @@ static void timeout(int signum) int nc_main(int argc, char **argv) { 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 char *pr00gie = NULL; #endif diff --git a/shell/ash.c b/shell/ash.c index 559238c3f..6edc48421 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -568,7 +568,7 @@ struct parsefile { }; 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 */ @@ -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 IBUFSIZ (BUFSIZ + 1) static void pushfile(void);