summaryrefslogtreecommitdiff
path: root/src/stdio/fgets.c
blob: 8606fdea8f872c17802e9139f9525a56d637f6c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#if 0

#include <stdio.h>
#include "_stdio.h"

/** read a string of characters from a file stream **/

char * fgets(char * restrict s, int n, FILE * restrict stream)
{
	int i = 0;
	if (feof(stream)) {
		return NULL;
	}

	flockfile(stream);
	for (i = 0; i < n-1; i++) {
		s[i] = fgetc(stream);
		if (s[i] == '\n') {
			s[i+1] = '\0';
			break;
		} else if (s[i] == EOF) {
			s[i] = '\0';
			break;
		}
	}
	funlockfile(stream);

	/*
	RETURN_SUCCESS(ARGUMENT(s));
	RETURN_FAILURE(CONSTANT(NULL));
	*/
	if (s[0] == '\0') {
		return NULL;
	}

	return s;
}

/***
reads a string of characters from ARGUMENT(stream). Up to
ARGUMENT(n)-1 characters will be read into the array at ARGUMENT(s).

If a newline is read, it will be appended to ARGUMENT(s) and THIS() will return.

If end-of-file is reached, THIS() will return.

A CHAR(\0) will be written immediately after the final character is read.

If end-of-file is reached before any characters are read, the contents of
ARGUMENT(s) will be unchanged.

If an error occurs, the contents of ARGUMENT(s) are indeterminite.
***/

/*
STDC(1)
*/


#endif