1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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;
}
|