浏览代码

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
Denis Vlasenko 16 年之前
父节点
当前提交
3fa5621448
共有 2 个文件被更改,包括 25 次插入20 次删除
  1. 1 1
      libc/inet/rpc/getrpcent.c
  2. 24 19
      libc/misc/time/time.c

+ 1 - 1
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)
 {

+ 24 - 19
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__ */