|
|
1.1 ! root 1: #include <stdio.h> ! 2: ! 3: /* ! 4: * getstr - read a line into buf from file fd. At most max characters ! 5: * are read. getstr returns the length of the line, not counting ! 6: * the newline. Note that if a file doesn't end in a newline, the ! 7: * characters between the last newline and the end of the file ! 8: * are never seen. ! 9: */ ! 10: ! 11: getstr(buf, max, fd) ! 12: register char *buf; ! 13: int max; ! 14: FILE *fd; ! 15: { ! 16: register int c, l; ! 17: ! 18: l = 0; ! 19: while ((c = getc(fd)) != '\n') { ! 20: if (c == EOF) ! 21: return -1; ! 22: *buf++ = c; ! 23: if (++l >= max) ! 24: break; ! 25: } ! 26: return l; ! 27: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.