10 static int file_size(int fd
)
17 static int xread(int fd
, char *buf
, int len
)
21 int cr
= read(fd
, buf
+ nr
, len
- nr
);
29 struct uidl
*uidl_read(char *filename
)
31 struct uidl
*uidl
= malloc(sizeof(*uidl
));
33 uidl
->fd
= open(filename
, O_RDWR
| O_CREAT
, 0600);
34 len
= file_size(uidl
->fd
);
35 lseek(uidl
->fd
, 0, SEEK_SET
);
36 uidl
->txt
= malloc(len
+ 1);
37 xread(uidl
->fd
, uidl
->txt
, len
);
38 uidl
->txt
[len
] = '\0';
39 lseek(uidl
->fd
, 0, SEEK_END
);
43 int uidl_find(struct uidl
*uidl
, char *id
)
46 snprintf(kw
, sizeof(kw
), "%s\n", id
);
47 return !!strstr(uidl
->txt
, kw
);
50 void uidl_add(struct uidl
*uidl
, char *id
)
53 snprintf(kw
, sizeof(kw
), "%s\n", id
);
54 write(uidl
->fd
, kw
, strlen(kw
));
57 void uidl_save(struct uidl
*uidl
)