summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-20 15:25:51 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-20 15:25:51 +0000
commit3fa5621448d11fbe8ad3bbb80e3daa7cb9c943f9 (patch)
treecd4513f75239c6da650554923898165220ff5d07
parent7dd438230613f3a29babf22543ee9ed89b8828d1 (diff)
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
-rw-r--r--libc/inet/rpc/getrpcent.c2
-rw-r--r--libc/misc/time/time.c43
2 files changed, 25 insertions, 20 deletions
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__ */