From 3fa5621448d11fbe8ad3bbb80e3daa7cb9c943f9 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 20 Dec 2008 15:25:51 +0000 Subject: Deal with a few data fields which may be made constant. text data bss dec hex filename - 1237 9 28 1274 4fa libc/inet/rpc/getrpcent.os + 1246 0 28 1274 4fa libc/inet/rpc/getrpcent.os - 773 24 0 797 31d libc/misc/time/_time_localtime_tzi.os + 772 16 0 788 314 libc/misc/time/_time_localtime_tzi.os --- libc/inet/rpc/getrpcent.c | 2 +- libc/misc/time/time.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) (limited to 'libc') diff --git a/libc/inet/rpc/getrpcent.c b/libc/inet/rpc/getrpcent.c index 2a98544f1..7ba4e65c5 100644 --- a/libc/inet/rpc/getrpcent.c +++ b/libc/inet/rpc/getrpcent.c @@ -70,7 +70,7 @@ static struct rpcdata { char *domain; } *rpcdata; -static char RPCDB[] = "/etc/rpc"; +static const char RPCDB[] = "/etc/rpc"; static struct rpcdata *_rpcdata(void) { diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c index ae800e1ca..45ec131b7 100644 --- a/libc/misc/time/time.c +++ b/libc/misc/time/time.c @@ -618,43 +618,48 @@ libc_hidden_def(localtime_r) #ifdef __UCLIBC_HAS_TM_EXTENSIONS__ -/* Experimentally off - libc_hidden_proto(strnlen) */ - struct ll_tzname_item; typedef struct ll_tzname_item { struct ll_tzname_item *next; - char tzname[TZNAME_MAX+1]; + char tzname[1]; } ll_tzname_item_t; -static ll_tzname_item_t ll_tzname[] = { - { ll_tzname + 1, "UTC" }, /* Always 1st. */ - { NULL, "???" } /* Always 2nd. (invalid or out-of-memory) */ -}; +/* Structures form a list "UTC" -> "???" -> "tzname1" -> "tzname2"... */ +struct { + struct ll_tzname_item *next; + char tzname[4]; +} ll_tzname_UNKNOWN = { NULL, "???" }; +const struct { + struct ll_tzname_item *next; + char tzname[4]; +} ll_tzname_UTC = { (void*)&ll_tzname_UNKNOWN, "UTC" }; static const char *lookup_tzname(const char *key) { - ll_tzname_item_t *p; + int len; + ll_tzname_item_t *p = (void*) &ll_tzname_UTC; - for (p=ll_tzname ; p ; p=p->next) { - if (!strcmp(p->tzname, key)) { + do { + if (strcmp(p->tzname, key) == 0) return p->tzname; - } - } + p = p->next; + } while (p != NULL); /* Hmm... a new name. */ - if (strnlen(key, TZNAME_MAX+1) < TZNAME_MAX+1) { /* Verify legal length */ - if ((p = malloc(sizeof(ll_tzname_item_t))) != NULL) { + len = strnlen(key, TZNAME_MAX+1); + if (len < TZNAME_MAX+1) { /* Verify legal length */ + p = malloc(sizeof(ll_tzname_item_t) + len); + if (p != NULL) { /* Insert as 3rd item in the list. */ - p->next = ll_tzname[1].next; - ll_tzname[1].next = p; - strcpy(p->tzname, key); - return p->tzname; + p->next = ll_tzname_UNKNOWN.next; + ll_tzname_UNKNOWN.next = p; + return strcpy(p->tzname, key); } } /* Either invalid or couldn't alloc. */ - return ll_tzname[1].tzname; + return ll_tzname_UNKNOWN.tzname; } #endif /* __UCLIBC_HAS_TM_EXTENSIONS__ */ -- cgit v1.2.3