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
RevLine 
[f40a309]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
[b28a12e]8#include "ram.h"
[f40a309]9
10#define EATCHAR '\n' /* character to be "eaten" on input */
11
[7258c6a]12int16_t agetc(FILE *ptr)
[f40a309]13{
[7258c6a]14 register int16_t c;
[f40a309]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
[7258c6a]34int8_t *gets(int8_t *line)
[f40a309]35{
[7258c6a]36 register int8_t *cp;
37 register int16_t i;
[f40a309]38
39 cp = line;
40
41 while ((i = getchar()) NE EOF AND i NE '\n')
[8973acd]42 *cp++ = (int8_t)i;
[f40a309]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
[7258c6a]52int8_t *fgets(int8_t *s, int16_t n, FILE *fp)
[f40a309]53{
[7258c6a]54 register int16_t c;
55 register int8_t *cp;
[f40a309]56
[8973acd]57 c = 0;
[f40a309]58 cp = s;
59
60 while (--n > 0 AND (c = agetc(fp)) NE EOF) {
61
[8973acd]62 *cp++ = (int8_t)c;
[f40a309]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
[6262b5c]76
Note: See TracBrowser for help on using the repository browser.