From 88483db112b15569aad4898d30a8ab7ea4deb96b Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 30 Jul 2007 17:02:06 +0000 Subject: make regex_old.c, ruserpass.c use __uc_malloc, replace "buf = malloc(BUFSIZ); if (!buf) abort();" by __uc_malloc elsewhere. With last 7 patches together uclibc has 3k of static data total with fairly big .config and with 2k being used for 2 x BUFSIZ stdio buffer: text data bss dec hex filename 114 132 2048 2294 8f6 _stdio.o (ex lib/libc.a) total data 593 total bss 3062 --- libc/inet/getnetent.c | 4 +--- libc/inet/getproto.c | 5 ++--- libc/inet/getservice.c | 5 ++--- libc/inet/rpc/ruserpass.c | 6 +++++- libc/misc/mntent/mntent.c | 5 ++--- libc/misc/regex/regex_old.c | 9 ++++++--- libc/misc/ttyent/getttyent.c | 5 ++--- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/libc/inet/getnetent.c b/libc/inet/getnetent.c index 58e679070..99d87a3df 100644 --- a/libc/inet/getnetent.c +++ b/libc/inet/getnetent.c @@ -111,9 +111,7 @@ struct netent *getnetent(void) again: if (!line) { - line = malloc(BUFSIZ + 1); - if (!line) - abort(); + line = __uc_malloc(BUFSIZ + 1); } p = fgets(line, BUFSIZ, netf); diff --git a/libc/inet/getproto.c b/libc/inet/getproto.c index c1292ed30..6367ccfce 100644 --- a/libc/inet/getproto.c +++ b/libc/inet/getproto.c @@ -59,6 +59,7 @@ #include #include #include +#include #include libc_hidden_proto(fopen) @@ -86,9 +87,7 @@ static int proto_stayopen; static void __initbuf(void) { if (!static_aliases) { - static_aliases = malloc(SBUFSIZE); - if (!static_aliases) - abort(); + static_aliases = __uc_malloc(SBUFSIZE); } } diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c index 5a94c9c69..9ea810be0 100644 --- a/libc/inet/getservice.c +++ b/libc/inet/getservice.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -89,9 +90,7 @@ static int serv_stayopen; static void __initbuf(void) { if (!servbuf) { - servbuf = malloc(SBUFSIZE); - if (!servbuf) - abort(); + servbuf = __uc_malloc(SBUFSIZE); } } diff --git a/libc/inet/rpc/ruserpass.c b/libc/inet/rpc/ruserpass.c index 0adcbf1d3..b18bbf5b7 100644 --- a/libc/inet/rpc/ruserpass.c +++ b/libc/inet/rpc/ruserpass.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -79,7 +80,7 @@ static FILE *cfile; #define ID 10 #define MACHINE 11 -static char tokval[100]; +static char *tokval; /* [100] */ static const char tokstr[] = { @@ -152,6 +153,9 @@ int ruserpass(const char *host, const char **aname, const char **apass) if (mydomain==NULL) { mydomain=myname + strlen(myname); } + + if (!tokval) + tokval = __uc_malloc(100); next: while ((t = token())) switch(t) { diff --git a/libc/misc/mntent/mntent.c b/libc/misc/mntent/mntent.c index a5db799dc..a9024be88 100644 --- a/libc/misc/mntent/mntent.c +++ b/libc/misc/mntent/mntent.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -84,9 +85,7 @@ struct mntent *getmntent(FILE * filep) __UCLIBC_MUTEX_LOCK(mylock); if (!buff) { - buff = malloc(BUFSIZ); - if (!buff) - abort(); + buff = __uc_malloc(BUFSIZ); } tmp = getmntent_r(filep, &mnt, buff, BUFSIZ); diff --git a/libc/misc/regex/regex_old.c b/libc/misc/regex/regex_old.c index cf5843ec5..997ee6f8b 100644 --- a/libc/misc/regex/regex_old.c +++ b/libc/misc/regex/regex_old.c @@ -35,6 +35,7 @@ #include #include #include +#include #include libc_hidden_proto(memset) @@ -306,7 +307,7 @@ extern char *re_syntax_table; # else /* not SYNTAX_TABLE */ -static char re_syntax_table[CHAR_SET_SIZE]; +static char *re_syntax_table; /* [CHAR_SET_SIZE] */ static void init_syntax_once PARAMS ((void)); @@ -314,11 +315,13 @@ static void init_syntax_once () { register int c; - static int done = 0; + static char done; if (done) return; - bzero (re_syntax_table, sizeof re_syntax_table); + + re_syntax_table = __uc_malloc(CHAR_SET_SIZE); + bzero (re_syntax_table, CHAR_SET_SIZE); for (c = 0; c < CHAR_SET_SIZE; ++c) if (ISALNUM (c)) diff --git a/libc/misc/ttyent/getttyent.c b/libc/misc/ttyent/getttyent.c index c9c68f1cc..e68eb8aa0 100644 --- a/libc/misc/ttyent/getttyent.c +++ b/libc/misc/ttyent/getttyent.c @@ -34,6 +34,7 @@ #include #include #include +#include #ifdef __UCLIBC_HAS_THREADS__ #include #endif @@ -132,9 +133,7 @@ struct ttyent * getttyent(void) return (NULL); if (!line) { - line = malloc(BUFSIZ); - if (!line) - abort(); + line = __uc_malloc(BUFSIZ); } __STDIO_ALWAYS_THREADLOCK(tf); -- cgit v1.2.3