mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
libc: Skip close stdin/stdout/stderr in fclose
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
committed by
Brennan Ashton
parent
b69c587dc9
commit
2b9282d5ee
@@ -81,6 +81,23 @@ int fclose(FAR FILE *stream)
|
|||||||
|
|
||||||
if (stream)
|
if (stream)
|
||||||
{
|
{
|
||||||
|
ret = OK;
|
||||||
|
|
||||||
|
/* If the stream was opened for writing, then flush the stream */
|
||||||
|
|
||||||
|
if ((stream->fs_oflags & O_WROK) != 0)
|
||||||
|
{
|
||||||
|
ret = lib_fflush(stream, true);
|
||||||
|
errcode = get_errno();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Skip close the builtin streams(stdin, stdout and stderr) */
|
||||||
|
|
||||||
|
if (stream == stdin || stream == stdout || stream == stderr)
|
||||||
|
{
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove FILE structure from the stream list */
|
/* Remove FILE structure from the stream list */
|
||||||
|
|
||||||
slist = nxsched_get_streams();
|
slist = nxsched_get_streams();
|
||||||
@@ -114,17 +131,8 @@ int fclose(FAR FILE *stream)
|
|||||||
* file.
|
* file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = OK;
|
|
||||||
if (stream->fs_fd >= 0)
|
if (stream->fs_fd >= 0)
|
||||||
{
|
{
|
||||||
/* If the stream was opened for writing, then flush the stream */
|
|
||||||
|
|
||||||
if ((stream->fs_oflags & O_WROK) != 0)
|
|
||||||
{
|
|
||||||
ret = lib_fflush(stream, true);
|
|
||||||
errcode = get_errno();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Close the file descriptor and save the return status */
|
/* Close the file descriptor and save the return status */
|
||||||
|
|
||||||
status = close(stream->fs_fd);
|
status = close(stream->fs_fd);
|
||||||
@@ -157,6 +165,7 @@ int fclose(FAR FILE *stream)
|
|||||||
lib_free(stream);
|
lib_free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
/* On an error, reset the errno to the first error encountered and return
|
/* On an error, reset the errno to the first error encountered and return
|
||||||
* EOF.
|
* EOF.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user