mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Added fgets(3).
This commit is contained in:
parent
6bcb3d7384
commit
065ceae509
2 changed files with 21 additions and 1 deletions
|
@ -225,3 +225,23 @@ int fputs(const char* str, FILE* fp)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* fgets(char* dest, int size, FILE* fp)
|
||||||
|
{
|
||||||
|
if ( size <= 0 ) { errno = EINVAL; return NULL; }
|
||||||
|
int i;
|
||||||
|
for ( i = 0; i < size-1; i++ )
|
||||||
|
{
|
||||||
|
int c = getc(fp);
|
||||||
|
if ( c == EOF )
|
||||||
|
{
|
||||||
|
if ( ferror(fp) ) { return NULL; }
|
||||||
|
else { i++; break; } /* EOF */
|
||||||
|
}
|
||||||
|
dest[i] = c;
|
||||||
|
if ( c == '\n' ) { i++; break; }
|
||||||
|
}
|
||||||
|
|
||||||
|
dest[i] = '\0';
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ extern int ferror(FILE* stream);
|
||||||
extern int fflush(FILE* stream);
|
extern int fflush(FILE* stream);
|
||||||
extern int fileno(FILE* stream);
|
extern int fileno(FILE* stream);
|
||||||
extern int fgetc(FILE* stream);
|
extern int fgetc(FILE* stream);
|
||||||
|
extern char* fgets(char* restrict s, int n, FILE* restrict stream);
|
||||||
extern FILE* fopen(const char* restrict filename, const char* restrict mode);
|
extern FILE* fopen(const char* restrict filename, const char* restrict mode);
|
||||||
extern int fprintf(FILE* restrict stream, const char* restrict format, ...);
|
extern int fprintf(FILE* restrict stream, const char* restrict format, ...);
|
||||||
extern int fputc(int c, FILE* stream);
|
extern int fputc(int c, FILE* stream);
|
||||||
|
@ -111,7 +112,6 @@ extern int vsprintf(char* restrict s, const char* restrict format, va_list ap);
|
||||||
/* TODO: These are not implemented in libmaxsi/sortix yet. */
|
/* TODO: These are not implemented in libmaxsi/sortix yet. */
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||||
extern char* ctermid(char* s);
|
extern char* ctermid(char* s);
|
||||||
extern char* fgets(char* restrict s, int n, FILE* restrict stream);
|
|
||||||
extern FILE *fmemopen(void* restrict buf, size_t size, const char* restrict mode);
|
extern FILE *fmemopen(void* restrict buf, size_t size, const char* restrict mode);
|
||||||
extern FILE* freopen(const char* restrict filename, const char *restrict mode, FILE* restrict stream);
|
extern FILE* freopen(const char* restrict filename, const char *restrict mode, FILE* restrict stream);
|
||||||
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
||||||
|
|
Loading…
Add table
Reference in a new issue