kolibrios/programs/develop/ktcc/trunk/libc/stdio/fgets.c
turbocat e08c6968ef ktcc: rollback to r9529
git-svn-id: svn://kolibrios.org@9558 a494cfbc-eb01-0410-851d-a64ba20cac60
2022-01-02 12:16:17 +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;
}
}