summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-01-08 11:24:28 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-01-08 11:24:28 -0600
commit2ff750fb0fafdfa1fa2ea674ef962f70e40e402b (patch)
treec5f4a170a18be5906e7a9dc208e5b059bfb1b342
parenteaaec3ec0947c82d1d94039fb25c57fa33134b87 (diff)
downloadnuttx-2ff750fb0fafdfa1fa2ea674ef962f70e40e402b.tar.gz
nuttx-2ff750fb0fafdfa1fa2ea674ef962f70e40e402b.tar.bz2
nuttx-2ff750fb0fafdfa1fa2ea674ef962f70e40e402b.zip
Minor fixes to lib_fgets() typing
-rw-r--r--nuttx/libc/lib_internal.h2
-rw-r--r--nuttx/libc/stdio/lib_fgets.c12
-rw-r--r--nuttx/libc/stdio/lib_gets.c2
-rw-r--r--nuttx/libc/stdio/lib_gets_s.c2
-rw-r--r--nuttx/libc/stdio/lib_libfgets.c2
5 files changed, 15 insertions, 5 deletions
diff --git a/nuttx/libc/lib_internal.h b/nuttx/libc/lib_internal.h
index bf73b72a4..1b7f232c5 100644
--- a/nuttx/libc/lib_internal.h
+++ b/nuttx/libc/lib_internal.h
@@ -186,7 +186,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream);
/* 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);
/* Defined in lib_libfflush.c */
diff --git a/nuttx/libc/stdio/lib_fgets.c b/nuttx/libc/stdio/lib_fgets.c
index 3aff54db9..47f35597c 100644
--- a/nuttx/libc/stdio/lib_fgets.c
+++ b/nuttx/libc/stdio/lib_fgets.c
@@ -69,7 +69,17 @@
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 */
- return lib_fgets(buf, buflen, stream, true, false);
+ else
+ {
+ return lib_fgets(buf, (size_t)buflen, stream, true, false);
+ }
}
diff --git a/nuttx/libc/stdio/lib_gets.c b/nuttx/libc/stdio/lib_gets.c
index e9e36987b..d15c8bd08 100644
--- a/nuttx/libc/stdio/lib_gets.c
+++ b/nuttx/libc/stdio/lib_gets.c
@@ -73,5 +73,5 @@ FAR char *gets(FAR char *s)
{
/* 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);
}
diff --git a/nuttx/libc/stdio/lib_gets_s.c b/nuttx/libc/stdio/lib_gets_s.c
index 3f9ecc0cb..54f8891f9 100644
--- a/nuttx/libc/stdio/lib_gets_s.c
+++ b/nuttx/libc/stdio/lib_gets_s.c
@@ -92,5 +92,5 @@ FAR char *gets_s(FAR char *s, rsize_t n)
/* 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);
}
diff --git a/nuttx/libc/stdio/lib_libfgets.c b/nuttx/libc/stdio/lib_libfgets.c
index 6a8cdeb44..bc41d94e5 100644
--- a/nuttx/libc/stdio/lib_libfgets.c
+++ b/nuttx/libc/stdio/lib_libfgets.c
@@ -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)
{
int nch = 0;