source: buchla-68k/libcio/fgets.c@ 6099cac

Last change on this file since 6099cac was 8973acd, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in libcio.

  • Property mode set to 100644
File size: 1.1 KB
Line 
1/*
2 =============================================================================
3 fgets.c -- get a string from an ASCII stream file
4 Version 2 -- 1987-07-09 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10#define EATCHAR '\n' /* character to be "eaten" on input */
11
12int16_t agetc(FILE *ptr)
13{
14 register int16_t c;
15
16top:
17 if ((c = getc(ptr)) NE EOF) {
18
19 switch (c &= 0x7F) {
20
21 case 0x1a: /* {x}DOS EOF */
22 --ptr->_bp;
23 return(EOF);
24
25 case EATCHAR: /* CR or LF */
26 case 0: /* NUL */
27 goto top;
28 }
29 }
30
31 return(c);
32}
33
34int8_t *gets(int8_t *line)
35{
36 register int8_t *cp;
37 register int16_t i;
38
39 cp = line;
40
41 while ((i = getchar()) NE EOF AND i NE '\n')
42 *cp++ = (int8_t)i;
43
44 *cp = 0; /* terminate the line */
45
46 if ((i EQ EOF) AND (cp EQ line))
47 return(NULL);
48
49 return(line);
50}
51
52int8_t *fgets(int8_t *s, int16_t n, FILE *fp)
53{
54 register int16_t c;
55 register int8_t *cp;
56
57 c = 0;
58 cp = s;
59
60 while (--n > 0 AND (c = agetc(fp)) NE EOF) {
61
62 *cp++ = (int8_t)c;
63
64 if (c EQ '\n')
65 break;
66 }
67
68 *cp = 0;
69
70 if (c EQ EOF AND cp EQ s)
71 return(NULL);
72
73 return(s);
74}
75
76
Note: See TracBrowser for help on using the repository browser.