|
|
1.1 ! root 1: /* ! 2: * $Source: /mit/kerberos/src/lib/krb/RCS/fgetst.c,v $ ! 3: * $Author: jtkohl $ ! 4: * ! 5: * Copyright 1987, 1988 by the Massachusetts Institute of Technology. ! 6: * ! 7: * For copying and distribution information, please see the file ! 8: * <mit-copyright.h>. ! 9: */ ! 10: ! 11: #ifndef lint ! 12: static char rcsid_fgetst_c[] = ! 13: "$Header: fgetst.c,v 4.0 89/01/23 10:08:31 jtkohl Exp $"; ! 14: #endif /* lint */ ! 15: ! 16: #include <mit-copyright.h> ! 17: #include <stdio.h> ! 18: ! 19: /* ! 20: * fgetst takes a file descriptor, a character pointer, and a count. ! 21: * It reads from the file it has either read "count" characters, or ! 22: * until it reads a null byte. When finished, what has been read exists ! 23: * in "s". If "count" characters were actually read, the last is changed ! 24: * to a null, so the returned string is always null-terminated. fgetst ! 25: * returns the number of characters read, including the null terminator. ! 26: */ ! 27: ! 28: fgetst(f, s, n) ! 29: FILE *f; ! 30: register char *s; ! 31: int n; ! 32: { ! 33: register count = n; ! 34: int ch; /* NOT char; otherwise you don't see EOF */ ! 35: ! 36: while ((ch = getc(f)) != EOF && ch && --count) { ! 37: *s++ = ch; ! 38: } ! 39: *s = '\0'; ! 40: return (n - count); ! 41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.