1
/* file.c - Functions to read the status file for deborphan.
2
Copyright (C) 2000 Cris van Pelt
4
Distributed under the terms of the Artistic License.
13
#include <sys/types.h>
17
#include <deborphan.h>
21
/* Be nice. This uses a little more memory than the longest line in your
22
* status file (which probably means some 100 bytes).
24
* This is more or less how everything was handled before version 0.1.20.
27
statusopen(const char *file)
43
s = xmalloc (i * sizeof(char));
49
while (!strchr(s, '\n')) {
50
if (!fgets(t, 31, *fp))
52
s = xrealloc(s, i+=32);
55
*(strchr(s, '\n')) = '\0';
61
/* Don't be nice. This uses up as much memory as your status file (near a
62
* megabyte). It is considerably faster, though.
65
statusopen(const char *file)
71
fd = open(file, O_RDONLY);
76
buf = (char *) xmalloc(statbuf.st_size + 1 * sizeof(char));
78
if (read(fd, buf, statbuf.st_size) < statbuf.st_size) {
83
*(buf + statbuf.st_size + 1) = '\0';
88
/* This function is similar to strsep(s, "\n"), but I have the feeling this
89
* is faster, because it only checks for '\n'. Well, that, and I just like
90
* writing this *(s+1) stuff.
100
for (n = *s; *n && *n != '\n'; n++);
110
#endif /* ! LOW_MEM */