ack/lang/cem/libcc.ansi/core/stdio/fgets.c
David Given 3131dc9915 Partially working port of stdio to CP/M. I'm not sure this will work; it's
getting way too complicated (stdio is horribly subtle). I think I need to
rethink things.
2019-06-15 22:22:01 +02:00

37 lines
451 B
C

/*
* fgets.c - get a string from a file
*/
/* $Id$ */
#include <stdio.h>
#if ACKCONF_WANT_STDIO
char* fgets(char* s, register int n, register FILE* stream)
{
register int ch;
register char* ptr;
ptr = s;
while (--n > 0 && (ch = getc(stream)) != EOF)
{
*ptr++ = ch;
if (ch == '\n')
break;
}
if (ch == EOF)
{
if (feof(stream))
{
if (ptr == s)
return NULL;
}
else
return NULL;
}
*ptr = '\0';
return s;
}
#endif