summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-08 22:03:51 +0200
committerAustin Foxley <austinf@cetoncorp.com>2009-09-18 11:42:45 -0700
commit36975dc0b01bdc191e3d3efdd41d0ff00194fffc (patch)
tree1ea89907d5737d1e38967a795f819ed33ba89109 /libc
parentba93584833773453b184e984cd91ed8357641a33 (diff)
downloaduClibc-alpine-36975dc0b01bdc191e3d3efdd41d0ff00194fffc.tar.bz2
uClibc-alpine-36975dc0b01bdc191e3d3efdd41d0ff00194fffc.tar.xz
simpler and shorter read_TZ_file() helper
text data bss dec hex filename - 1109 8 76 1193 4a9 libc/misc/time/tzset.o + 1095 8 76 1179 49b libc/misc/time/tzset.o Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/misc/time/time.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/libc/misc/time/time.c b/libc/misc/time/time.c
index 45ec131b7..168655b00 100644
--- a/libc/misc/time/time.c
+++ b/libc/misc/time/time.c
@@ -1835,30 +1835,43 @@ static smallint TZ_file_read; /* Let BSS initialization set this to 0. */
static char *read_TZ_file(char *buf)
{
int fd;
- ssize_t r;
- size_t todo;
char *p = NULL;
- if ((fd = open(__UCLIBC_TZ_FILE_PATH__, O_RDONLY)) >= 0) {
- todo = TZ_BUFLEN;
+ fd = open(__UCLIBC_TZ_FILE_PATH__, O_RDONLY);
+ if (fd >= 0) {
+ ssize_t r;
+#if 0
+ /* TZ are small *files*. On files, short reads
+ * only occur on EOF (unlike, say, pipes).
+ * The code below is pedanticallly more correct,
+ * but this way we always read at least twice:
+ * 1st read is short, 2nd one is zero bytes.
+ */
+ size_t todo = TZ_BUFLEN;
p = buf;
do {
- if ((r = read(fd, p, todo)) < 0) {
+ r = read(fd, p, todo);
+ if (r < 0)
goto ERROR;
- }
- if (r == 0) {
+ if (r == 0)
break;
- }
p += r;
todo -= r;
} while (todo);
+#else
+ /* Shorter, and does one less read syscall */
+ r = read(fd, buf, TZ_BUFLEN);
+ if (r < 0)
+ goto ERROR;
+ p = buf + r;
+#endif
- if ((p > buf) && (p[-1] == '\n')) { /* Must end with newline. */
+ if ((p > buf) && (p[-1] == '\n')) { /* Must end with newline */
p[-1] = 0;
p = buf;
#ifndef __UCLIBC_HAS_TZ_FILE_READ_MANY__
TZ_file_read = 1;
-#endif /* __UCLIBC_HAS_TZ_FILE_READ_MANY__ */
+#endif
} else {
ERROR:
p = NULL;