9 static int file_size(int fd
)
16 static int xread(int fd
, char *buf
, int len
)
20 int cr
= read(fd
, buf
+ nr
, len
- nr
);
28 struct uidl
*uidl_read(char *filename
)
30 struct uidl
*uidl
= malloc(sizeof(*uidl
));
32 uidl
->fd
= open(filename
, O_RDWR
| O_CREAT
, 0600);
33 len
= file_size(uidl
->fd
);
34 lseek(uidl
->fd
, 0, SEEK_SET
);
35 uidl
->txt
= malloc(len
+ 1);
36 xread(uidl
->fd
, uidl
->txt
, len
);
37 uidl
->txt
[len
] = '\0';
38 lseek(uidl
->fd
, 0, SEEK_END
);
42 static char *putnl(char *dst
, char *src
)
51 int uidl_find(struct uidl
*uidl
, char *id
)
55 return !!strstr(uidl
->txt
, kw
);
58 void uidl_add(struct uidl
*uidl
, char *id
)
61 int len
= putnl(kw
, id
) - kw
;
62 write(uidl
->fd
, kw
, len
);
65 void uidl_save(struct uidl
*uidl
)