Add support for ferror(), feof(), and clearerr()

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5290 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2012-11-01 15:00:26 +00:00
parent 3ceeb8f9f0
commit a5b189950e
8 changed files with 307 additions and 21 deletions
+28 -3
View File
@@ -187,7 +187,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
/* We are at the end of the file */
/* We are at the end of the file. But we may already
* have buffered data. In that case, we will report
* the EOF indication later.
*/
goto shortread;
}
@@ -232,7 +235,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
/* We are at the end of the file */
/* We are at the end of the file. But we may already
* have buffered data. In that case, we will report
* the EOF indication later.
*/
goto shortread;
}
@@ -261,6 +267,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
else if (bytes_read == 0)
{
/* We are at the end of the file. But we may already
* have buffered data. In that case, we will report
* the EOF indication later.
*/
break;
}
else
@@ -270,12 +281,26 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
}
}
#endif
/* Here after a successful (but perhaps short) read */
/* Here after a successful (but perhaps short) read */
#if CONFIG_STDIO_BUFFER_SIZE > 0
shortread:
#endif
bytes_read = dest - (unsigned char*)ptr;
/* Set or clear the EOF indicator. If we get here because of a
* short read and the total number of* bytes read is zero, then
* we must be at the end-of-file.
*/
if (bytes_read > 0)
{
stream->fs_flags &= ~__FS_FLAG_EOF;
}
else
{
stream->fs_flags |= __FS_FLAG_EOF;
}
}
lib_give_semaphore(stream);