1 /* $Id: readin.c 6394 2003-07-12 19:13:14Z rra $
15 ** Read a big amount, looping until it is all done. Return true if
18 int xread(int fd, char *p, off_t i)
22 for ( ; i; p += count, i -= count) {
24 count = read(fd, p, i);
25 } while (count == -1 && errno == EINTR);
34 ** Read an already-open file into memory.
36 char *ReadInDescriptor(int fd, struct stat *Sbp)
45 /* Get the size, and enough memory. */
46 if (fstat(fd, Sbp) < 0) {
52 p = xmalloc(Sbp->st_size + 1);
55 if (xread(fd, p, Sbp->st_size) < 0) {
63 /* Terminate the string; terminate the routine. */
64 p[Sbp->st_size] = '\0';
70 ** Read a file into allocated memory. Optionally fill in the stat(2) data.
71 ** Return a pointer to the file contents, or NULL on error.
73 char *ReadInFile(const char *name, struct stat *Sbp)
78 if ((fd = open(name, O_RDONLY)) < 0)
81 p = ReadInDescriptor(fd, Sbp);