diff --git a/posixtz.c b/posixtz.c index 141cca1..604a53d 100644 --- a/posixtz-0.3/posixtz.c +++ b/posixtz-0.3/posixtz.c @@ -25,18 +25,19 @@ char *posix_tz(const char *filename) { - int fd, r; + FILE *f; + size_t r; static char buf[TZ_BUFLEN]; char *p = NULL; - fd = open(filename, O_RDONLY); - if (fd < 0) + f = fopen(filename, "r"); + if (f == NULL) return NULL; - r = read(fd, buf, TZ_BUFLEN); + r = fread(buf, 1, TZ_BUFLEN, f); if (r != TZ_BUFLEN || strncmp(buf, "TZif", 4) != 0 || (unsigned char)buf[4] < 2 - || lseek(fd, -TZ_BUFLEN, SEEK_END) < 0 + || fseek(f, -TZ_BUFLEN, SEEK_END) < 0 ) goto ERROR; @@ -50,7 +51,7 @@ char *posix_tz(const char *filename) ** (with nothing between the newlines if there is no POSIX representation for ** such instants). */ - r = read(fd, buf, TZ_BUFLEN); + r = fread(buf, 1, TZ_BUFLEN, f); if (r <= 0 || buf[--r] != '\n') goto ERROR; buf[r] = 0; @@ -61,7 +62,7 @@ char *posix_tz(const char *filename) } } /* else ('\n' not found): p remains NULL */ ERROR: - close(fd); + fclose(f); return p; }