Minor fixes to lib_fgets() typing

This commit is contained in:
Gregory Nutt 2014-01-08 11:24:28 -06:00
parent 0bdee120a1
commit a0808e7b6d
5 changed files with 15 additions and 5 deletions

View File

@ -186,7 +186,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
/* Defined in lib_libfgets.c */ /* Defined in lib_libfgets.c */
FAR char *lib_fgets(FAR char *buf, int buflen, FILE *stream, FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream,
bool keepnl, bool consume); bool keepnl, bool consume);
/* Defined in lib_libfflush.c */ /* Defined in lib_libfflush.c */

View File

@ -69,7 +69,17 @@
char *fgets(FAR char *buf, int buflen, FILE *stream) char *fgets(FAR char *buf, int buflen, FILE *stream)
{ {
/* Handle negative buffer size */
if (buflen < 0)
{
return NULL;
}
/* Let lib_fgets() do the heavy lifting */ /* Let lib_fgets() do the heavy lifting */
return lib_fgets(buf, buflen, stream, true, false); else
{
return lib_fgets(buf, (size_t)buflen, stream, true, false);
}
} }

View File

@ -73,5 +73,5 @@ FAR char *gets(FAR char *s)
{ {
/* Let lib_fgets() do the heavy lifting */ /* Let lib_fgets() do the heavy lifting */
return lib_fgets(s, RSIZE_MAX, stdin, false, false); return lib_fgets(s, (size_t)INT_MAX, stdin, false, false);
} }

View File

@ -92,5 +92,5 @@ FAR char *gets_s(FAR char *s, rsize_t n)
/* Then let lib_fgets() do the heavy lifting */ /* Then let lib_fgets() do the heavy lifting */
return lib_fgets(s, n, stdin, false, true); return lib_fgets(s, (size_t)n, stdin, false, true);
} }

View File

@ -139,7 +139,7 @@ static void consume_eol(FILE *stream, bool consume)
* *
**************************************************************************/ **************************************************************************/
FAR char *lib_fgets(FAR char *buf, int buflen, FILE *stream, FAR char *lib_fgets(FAR char *buf, size_t buflen, FILE *stream,
bool keepnl, bool consume) bool keepnl, bool consume)
{ {
int nch = 0; int nch = 0;