Last change
on this file since 6888aa2 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago |
Imported original source code.
|
-
Property mode
set to
100755
|
File size:
1.2 KB
|
Rev | Line | |
---|
[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | rdline.c -- read a line into a buffer
|
---|
| 4 | Version 1 -- 1988-12-29 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stdio.h"
|
---|
| 9 | #include "stddefs.h"
|
---|
| 10 |
|
---|
| 11 | /*
|
---|
| 12 | =============================================================================
|
---|
| 13 | rdline(fp, buf, maxc) -- read a line from a file into a buffer
|
---|
| 14 |
|
---|
| 15 | fp FILE pointer
|
---|
| 16 | buf buffer pointer
|
---|
| 17 | maxc maximum line length (not counting the terminating zero)
|
---|
| 18 |
|
---|
| 19 | The buffer must have room for maxc + 1 bytes. The final byte will be
|
---|
| 20 | a terminating zero.
|
---|
| 21 |
|
---|
| 22 | returns:
|
---|
| 23 | 0 success line read - complete with LF
|
---|
| 24 | -1 failure immediate EOF - no data read
|
---|
| 25 | 1 failure read to EOF - missing LF at end
|
---|
| 26 | 2 failure buffer full - missing LF at end
|
---|
| 27 | =============================================================================
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | short
|
---|
| 31 | rdline(fp, buf, maxc)
|
---|
| 32 | register FILE *fp;
|
---|
| 33 | register char *buf;
|
---|
| 34 | register short maxc;
|
---|
| 35 | {
|
---|
| 36 | register short c, i;
|
---|
| 37 |
|
---|
| 38 | *buf = '\0';
|
---|
| 39 |
|
---|
| 40 | for (i = 0; i < maxc; i++) {
|
---|
| 41 |
|
---|
| 42 | if (EOF EQ (c = fgetc(fp)))
|
---|
| 43 | return(i ? 1 : -1);
|
---|
| 44 |
|
---|
| 45 | *buf++ = c;
|
---|
| 46 | *buf = '\0';
|
---|
| 47 |
|
---|
| 48 | if (c EQ '\n')
|
---|
| 49 | return(0);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | return(2);
|
---|
| 53 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.