kolibrios/programs/develop/ktcc/trunk/libc/stdio/fgets.c
siemargl ace23ebbe2 libc testsuite + fixes
git-svn-id: svn://kolibrios.org@6433 a494cfbc-eb01-0410-851d-a64ba20cac60
2016-05-19 12:15:22 +00:00

35 lines
473 B
C

#include <stdio.h>
char * fgets ( char * str, int num, FILE * file )
// need to ignore \r\n in text mode
{
int rd = 0;
char c;
if(!file || !str)
{
errno = E_INVALIDPTR;
return NULL;
}
while (rd < num - 1)
{
c = fgetc(file);
if (EOF == c) break;
if ('\n' == c)
{
str[rd++] = c;
break;
}
else
str[rd++] = c;
}
if (0 == rd) return NULL;
else
{
str[rd] = '\0';
return str;
}
}