mess822x 1.23
mess822x
Loading...
Searching...
No Matches
leapsecs_read.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <unistd.h>
3#include <sys/types.h>
4#include <sys/stat.h>
5#include <fcntl.h>
6#include "tai.h"
7#include "leapsecs.h"
8#include "error.h"
9
10extern int errno;
11struct tai *leapsecs = 0;
13
15{
16 int fd;
17 struct stat st;
18 struct tai *t;
19 int n;
20 int i;
21 struct tai u;
22
23 fd = open("/etc/leapsecs.dat",O_RDONLY | O_NDELAY);
24 if (fd == -1) {
25 if (errno != ENOENT) return -1;
26 if (leapsecs) free(leapsecs);
27 leapsecs = 0;
28 leapsecs_num = 0;
29 return 0;
30 }
31
32 if (fstat(fd,&st) == -1) { close(fd); return -1; }
33
34 t = (struct tai *) malloc(st.st_size);
35 if (!t) { close(fd); return -1; }
36
37 n = read(fd,(char *) t,st.st_size);
38 close(fd);
39 if (n != st.st_size) { free(t); return -1; }
40
41 n /= sizeof(struct tai);
42
43 for (i = 0; i < n; ++i) {
44 tai_unpack((char *) &t[i],&u);
45 t[i] = u;
46 }
47
48 if (leapsecs) free(leapsecs);
49
50 leapsecs = t;
51 leapsecs_num = n;
52
53 return 1;
54}
mess822_time t
Definition: 822date.c:19
int leapsecs_num
Definition: leapsecs_read.c:12
int leapsecs_read(void)
Definition: leapsecs_read.c:14
int errno
struct tai * leapsecs
Definition: leapsecs_read.c:11