meta: move photon/libc to root
This commit is contained in:
32
libc/stdio/fgets.c
Normal file
32
libc/stdio/fgets.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char *fgets(char *restrict str, int count, FILE *restrict fp)
|
||||
{
|
||||
if (count < 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (count == 1) {
|
||||
str[0] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
int r = 0;
|
||||
|
||||
while (1) {
|
||||
int c = fgetc(fp);
|
||||
if (c == EOF) {
|
||||
str[r] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
str[r++] = c;
|
||||
|
||||
if (r == count - 1 || c == '\n') {
|
||||
str[r] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return r > 0 ? str : NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user