Fix some places in library where semaphore is not released on error conditions
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5071 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
435dbaacd8
commit
d67c617009
12
ChangeLog
12
ChangeLog
@ -3224,4 +3224,14 @@
|
|||||||
* sched/os_bring.c, configs/*/defconfig, tools/mkconfig.c, and others: Added
|
* sched/os_bring.c, configs/*/defconfig, tools/mkconfig.c, and others: Added
|
||||||
configuration variable CONFIG_USER_ENTRYPOINT that may be used to change
|
configuration variable CONFIG_USER_ENTRYPOINT that may be used to change
|
||||||
the default entry from user_start to some other symbol. Contributed by
|
the default entry from user_start to some other symbol. Contributed by
|
||||||
Kate.
|
Kate. NOTE: This change does introduce a minor backward incompatibility.
|
||||||
|
For example, if your application uses NSH as its start-up program, then your
|
||||||
|
code will not fail because it will be unable to find "user_start". The fix
|
||||||
|
for this link failure is to add the following to your configuration file:
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main".
|
||||||
|
* libs/stdio/lib_libfread.c and lib_*flush*.c: Correct a couple of
|
||||||
|
error cases where the lib semaphore was not be released on error
|
||||||
|
exits (thanks Ronen Vainish). Also, improved some error reporting:
|
||||||
|
the generic ERROR was being used instead of the specific errno
|
||||||
|
value; the errno variable was not always set correctly.
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fflush.c
|
* lib/stdio/lib_fflush.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -97,22 +97,36 @@
|
|||||||
|
|
||||||
int fflush(FAR FILE *stream)
|
int fflush(FAR FILE *stream)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Is the stream argument NULL? */
|
/* Is the stream argument NULL? */
|
||||||
|
|
||||||
if (!stream)
|
if (!stream)
|
||||||
{
|
{
|
||||||
/* Yes... then this is a request to flush all streams */
|
/* Yes... then this is a request to flush all streams */
|
||||||
|
|
||||||
return lib_flushall(sched_getstreams());
|
ret = lib_flushall(sched_getstreams());
|
||||||
}
|
}
|
||||||
else if (lib_fflush(stream, true) != 0)
|
else
|
||||||
{
|
{
|
||||||
/* An error occurred during the flush AND/OR we were unable to flush all
|
ret = lib_fflush(stream, true);
|
||||||
* of the buffered write data. Return EOF on failure.
|
}
|
||||||
|
|
||||||
|
/* Check the return value */
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
/* An error occurred during the flush AND/OR we were unable to flush
|
||||||
|
* all of the buffered write data. Set the errno value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
set_errno(-ret);
|
||||||
|
|
||||||
|
/* And return EOF on failure. */
|
||||||
|
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fgetc.c
|
* lib/stdio/lib_fgetc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fgetpos.c
|
* lib/stdio/lib_fgetpos.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fileno.c
|
* lib/stdio/lib_fileno.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fread.c
|
* lib/stdio/lib_fread.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fseek.c
|
* lib/stdio/lib_fseek.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fsetpos.c
|
* lib/stdio/lib_fsetpos.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_ftell.c
|
* lib/stdio/lib_ftell.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_fwrite.c
|
* lib/stdio/lib_fwrite.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -98,8 +98,8 @@
|
|||||||
* bforce - flush must be complete.
|
* bforce - flush must be complete.
|
||||||
*
|
*
|
||||||
* Return:
|
* Return:
|
||||||
* ERROR on failure, otherwise the number of bytes remaining in the buffer.
|
* A negated errno value on failure, otherwise the number of bytes remaining
|
||||||
* If bforce is set, then only the values ERROR and 0 will be returned.
|
* in the buffer.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@ -109,13 +109,13 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
|||||||
FAR const unsigned char *src;
|
FAR const unsigned char *src;
|
||||||
ssize_t bytes_written;
|
ssize_t bytes_written;
|
||||||
ssize_t nbuffer;
|
ssize_t nbuffer;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Return EBADF if the file is not opened for writing */
|
/* Return EBADF if the file is not opened for writing */
|
||||||
|
|
||||||
if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0)
|
if (stream->fs_filedes < 0 || (stream->fs_oflags & O_WROK) == 0)
|
||||||
{
|
{
|
||||||
set_errno(EBADF);
|
return -EBADF;
|
||||||
return ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure that we have exclusive access to the stream */
|
/* Make sure that we have exclusive access to the stream */
|
||||||
@ -132,8 +132,11 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
|||||||
|
|
||||||
if (stream->fs_bufread != stream->fs_bufstart)
|
if (stream->fs_bufread != stream->fs_bufstart)
|
||||||
{
|
{
|
||||||
/* The buffer holds read data... just return zero */
|
/* The buffer holds read data... just return zero meaning "no bytes
|
||||||
|
* remaining in the buffer."
|
||||||
|
*/
|
||||||
|
|
||||||
|
lib_give_semaphore(stream);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +154,12 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
|||||||
bytes_written = write(stream->fs_filedes, src, nbuffer);
|
bytes_written = write(stream->fs_filedes, src, nbuffer);
|
||||||
if (bytes_written < 0)
|
if (bytes_written < 0)
|
||||||
{
|
{
|
||||||
|
/* Write failed. The cause of the failure is in 'errno'.
|
||||||
|
* returned the negated errno value.
|
||||||
|
*/
|
||||||
|
|
||||||
lib_give_semaphore(stream);
|
lib_give_semaphore(stream);
|
||||||
return ERROR;
|
return -get_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle partial writes. fflush() must either return with
|
/* Handle partial writes. fflush() must either return with
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_libflushall.c
|
* lib/stdio/lib_libflushall.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -91,7 +91,7 @@
|
|||||||
int lib_flushall(FAR struct streamlist *list)
|
int lib_flushall(FAR struct streamlist *list)
|
||||||
{
|
{
|
||||||
int lasterrno = OK;
|
int lasterrno = OK;
|
||||||
int ret = OK;
|
int ret;
|
||||||
|
|
||||||
/* Make sure that there are streams associated with this thread */
|
/* Make sure that there are streams associated with this thread */
|
||||||
|
|
||||||
@ -115,25 +115,23 @@ int lib_flushall(FAR struct streamlist *list)
|
|||||||
{
|
{
|
||||||
/* Flush the writable FILE */
|
/* Flush the writable FILE */
|
||||||
|
|
||||||
if (lib_fflush(stream, true) != 0)
|
ret = lib_fflush(stream, true);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* An error occurred during the flush AND/OR we were unable
|
/* An error occurred during the flush AND/OR we were unable
|
||||||
* to flush all of the buffered write data. Return EOF on failure.
|
* to flush all of the buffered write data. Remember the
|
||||||
|
* last errcode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
lasterrno = get_errno();
|
lasterrno = ret;
|
||||||
ret = ERROR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_semgive(list);
|
stream_semgive(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If any flush failed, return that last failed flush */
|
/* If any flush failed, return the errorcode of the last failed flush */
|
||||||
|
|
||||||
if (ret != OK)
|
return lasterrno;
|
||||||
{
|
|
||||||
set_errno(lasterrno);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_libfread.c
|
* lib/stdio/lib_libfread.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -88,6 +88,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
{
|
{
|
||||||
unsigned char *dest = (unsigned char*)ptr;
|
unsigned char *dest = (unsigned char*)ptr;
|
||||||
ssize_t bytes_read;
|
ssize_t bytes_read;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Make sure that reading from this stream is allowed */
|
/* Make sure that reading from this stream is allowed */
|
||||||
|
|
||||||
@ -127,9 +128,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
* buffered read/write access.
|
* buffered read/write access.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (lib_wrflush(stream) != 0)
|
ret = lib_wrflush(stream);
|
||||||
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ERROR;
|
lib_give_semaphore(stream);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now get any other needed chars from the buffer or the file. */
|
/* Now get any other needed chars from the buffer or the file. */
|
||||||
@ -176,15 +179,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
bytes_read = read(stream->fs_filedes, dest, count);
|
bytes_read = read(stream->fs_filedes, dest, count);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
/* An error occurred on the read */
|
/* An error occurred on the read. The error code is
|
||||||
|
* in the 'errno' variable.
|
||||||
|
*/
|
||||||
|
|
||||||
goto err_out;
|
goto errout_with_errno;
|
||||||
}
|
}
|
||||||
else if (bytes_read == 0)
|
else if (bytes_read == 0)
|
||||||
{
|
{
|
||||||
/* We are at the end of the file */
|
/* We are at the end of the file */
|
||||||
|
|
||||||
goto short_read;
|
goto shortread;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -198,7 +203,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
{
|
{
|
||||||
/* No. We must be at the end of file. */
|
/* No. We must be at the end of file. */
|
||||||
|
|
||||||
goto short_read;
|
goto shortread;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -219,15 +224,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
bytes_read = read(stream->fs_filedes, stream->fs_bufread, buffer_available);
|
bytes_read = read(stream->fs_filedes, stream->fs_bufread, buffer_available);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
/* An error occurred on the read */
|
/* An error occurred on the read. The error code is
|
||||||
|
* in the 'errno' variable.
|
||||||
|
*/
|
||||||
|
|
||||||
goto err_out;
|
goto errout_with_errno;
|
||||||
}
|
}
|
||||||
else if (bytes_read == 0)
|
else if (bytes_read == 0)
|
||||||
{
|
{
|
||||||
/* We are at the end of the file */
|
/* We are at the end of the file */
|
||||||
|
|
||||||
goto short_read;
|
goto shortread;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -246,7 +253,11 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
bytes_read = read(stream->fs_filedes, dest, count);
|
bytes_read = read(stream->fs_filedes, dest, count);
|
||||||
if (bytes_read < 0)
|
if (bytes_read < 0)
|
||||||
{
|
{
|
||||||
goto err_out;
|
/* An error occurred on the read. The error code is
|
||||||
|
* in the 'errno' variable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
goto errout_with_errno;
|
||||||
}
|
}
|
||||||
else if (bytes_read == 0)
|
else if (bytes_read == 0)
|
||||||
{
|
{
|
||||||
@ -259,13 +270,21 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* Here after a successful (but perhaps short) read */
|
||||||
|
|
||||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||||
short_read:
|
shortread:
|
||||||
#endif
|
#endif
|
||||||
bytes_read = dest - (unsigned char*)ptr;
|
bytes_read = dest - (unsigned char*)ptr;
|
||||||
err_out:
|
|
||||||
lib_give_semaphore(stream);
|
|
||||||
}
|
}
|
||||||
return bytes_read;
|
|
||||||
|
lib_give_semaphore(stream);
|
||||||
|
return bytes_read;
|
||||||
|
|
||||||
|
/* Error exits */
|
||||||
|
|
||||||
|
errout_with_errno:
|
||||||
|
lib_give_semaphore(stream);
|
||||||
|
return -get_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_libsprintf.c
|
* lib/stdio/lib_libsprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_rdflush.c
|
* lib/stdio/lib_rdflush.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_snprintf.c
|
* lib/stdio/lib_snprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_sprintf.c
|
* lib/stdio/lib_sprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_sscanf.c
|
* lib/stdio/lib_sscanf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_syslogstream.c
|
* lib/stdio/lib_syslogstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_ungetc.c
|
* lib/stdio/lib_ungetc.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_vfprintf.c
|
* lib/stdio/lib_vfprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_vprintf.c
|
* lib/stdio/lib_vprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_vsnprintf.c
|
* lib/stdio/lib_vsnprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_vsprintf.c
|
* lib/stdio/lib_vsprintf.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/stdio/lib_wrflush.c
|
* lib/stdio/lib_wrflush.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -88,29 +88,49 @@
|
|||||||
|
|
||||||
int lib_wrflush(FAR FILE *stream)
|
int lib_wrflush(FAR FILE *stream)
|
||||||
{
|
{
|
||||||
|
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Verify that we were passed a valid (i.e., non-NULL) stream */
|
/* Verify that we were passed a valid (i.e., non-NULL) stream */
|
||||||
|
|
||||||
#if CONFIG_STDIO_BUFFER_SIZE > 0
|
#ifdef CONFIG_DEBUG
|
||||||
if (stream)
|
if (!stream)
|
||||||
{
|
{
|
||||||
/* Verify that the stream is opened for writing... lib_fflush will
|
return -EINVAL;
|
||||||
* return an error if it is called for a stream that is not opened for
|
}
|
||||||
* writing.
|
#endif
|
||||||
|
|
||||||
|
/* Verify that the stream is opened for writing... lib_fflush will
|
||||||
|
* return an error if it is called for a stream that is not opened for
|
||||||
|
* writing. Check that first so that this function will not fail in
|
||||||
|
* that case.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((stream->fs_oflags & O_WROK) == 0)
|
||||||
|
{
|
||||||
|
/* Report that the success was successful if we attempt to flush a
|
||||||
|
* read-only stream.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ((stream->fs_oflags & O_WROK) == 0 ||
|
return OK;
|
||||||
lib_fflush(stream, true) == 0)
|
|
||||||
{
|
|
||||||
/* Return success if there is no buffered write data -- i.e., that
|
|
||||||
* the stream is not opened for writing or, if it is, that all of
|
|
||||||
* the buffered write data was successfully flushed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ERROR;
|
|
||||||
|
/* Flush the stream. Return success if there is no buffered write data
|
||||||
|
* -- i.e., that the stream is opened for writing and that all of the
|
||||||
|
* buffered write data was successfully flushed by lib_fflush().
|
||||||
|
*/
|
||||||
|
|
||||||
|
return lib_fflush(stream, true);
|
||||||
#else
|
#else
|
||||||
return stream ? OK : ERROR;
|
/* Verify that we were passed a valid (i.e., non-NULL) stream */
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG
|
||||||
|
if (!stream)
|
||||||
|
{
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* lib/stdio/lib_zeroinstream.c
|
* lib/stdio/lib_zeroinstream.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
|
Loading…
Reference in New Issue
Block a user