Complete fragmentary support for ferror(). From Macs N
This commit is contained in:
parent
8772a4e104
commit
cd135fe3a8
@ -7089,4 +7089,6 @@
|
||||
return EOF if no values were converted (2014-3-30).
|
||||
* include/time.h and sched/clock_settime(): Add support for
|
||||
CLOCK_REALTIME. From Macs N (2014-3-31).
|
||||
|
||||
* libc/stdio/lib_ferror.c, lib_fread.c, lib_libfflush.c,
|
||||
lib_libfread.c, and lib_libfwrite.c: Finish incomplete support
|
||||
for ferror(). From Macs N (2014-3-14).
|
||||
|
19
TODO
19
TODO
@ -17,7 +17,7 @@ nuttx/
|
||||
(6) Binary loaders (binfmt/)
|
||||
(17) Network (net/, drivers/net)
|
||||
(4) USB (drivers/usbdev, drivers/usbhost)
|
||||
(11) Libraries (libc/, )
|
||||
(10) Libraries (libc/, )
|
||||
(12) File system/Generic drivers (fs/, drivers/)
|
||||
(5) Graphics subystem (graphics/)
|
||||
(1) Pascal add-on (pcode/)
|
||||
@ -1099,23 +1099,6 @@ o Libraries (libc/)
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Title: FERROR()
|
||||
Description: ferror(), feof(), and clearerror() are present, but the
|
||||
implementation of ferror() is limited. There are flags in the
|
||||
stream structure to indicate EOF and error conditions but nothing
|
||||
in the code currently sets the error indication. This is a
|
||||
trivial change to many interfaces and has not yet been done.
|
||||
Instead, for now, ferror() is equivalent to !feof(). If an
|
||||
interface can failure because of an error or and EOF and you
|
||||
only want to distinguish between an error and the EOF then
|
||||
this ferror() will work. However, if no error is reported then
|
||||
this ferror() cannot tell you if an error has occurred or not.
|
||||
Status: Open
|
||||
Priority: Meidum to Low: Some applications use ferror() and not the
|
||||
return value to determine if an error occurred. Those
|
||||
applications will fail with this limited implementation of
|
||||
ferror().
|
||||
|
||||
Title: CONCURRENT STREAM READ/WRITE
|
||||
Description: NuttX only supports a single file pointer so reads and writes
|
||||
must be from the same position. This prohibits implementation
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/stdio/lib_ferror.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -64,26 +64,12 @@
|
||||
|
||||
int ferror(FILE *stream)
|
||||
{
|
||||
#if 0
|
||||
/* If an error is encountered by any of the C-buffered I/O functions, they
|
||||
* should set the __FS_FLAG_ERROR in the fs_flags field of struct
|
||||
* file_struct.
|
||||
*/
|
||||
|
||||
return (stream->fs_flags & __FS_FLAG_ERROR) != 0;
|
||||
#else
|
||||
/* However, nothing currenlty sets the __FS_FLAG_ERROR flag (that is a job
|
||||
* for another day). The __FS_FLAG_EOF is set by operations that perform
|
||||
* read operations. Since ferror() is probably only called to disambiguate
|
||||
* the meaning of other functions that return EOF, to indicate either EOF or
|
||||
* an error, just testing for not EOF is probably sufficient for now.
|
||||
*
|
||||
* This approach would not work if ferror() is called in other contexts. In
|
||||
* those cases, ferror() will always report an error.
|
||||
*/
|
||||
|
||||
return (stream->fs_flags & __FS_FLAG_EOF) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFILE_STREAMS */
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
@ -95,5 +95,6 @@ size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream)
|
||||
|
||||
items_read = bytes_read / size;
|
||||
}
|
||||
|
||||
return items_read;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/stdio/lib_libfflush.c
|
||||
*
|
||||
* Copyright (C) 2007-2008, 2011-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2008, 2011-2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -33,10 +33,6 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
@ -54,7 +50,7 @@
|
||||
#include "lib_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
@ -157,6 +153,7 @@ ssize_t lib_fflush(FAR FILE *stream, bool bforce)
|
||||
* returned the negated errno value.
|
||||
*/
|
||||
|
||||
stream->fs_flags |= __FS_FLAG_ERROR;
|
||||
lib_give_semaphore(stream);
|
||||
return -get_errno();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/stdio/lib_libfread.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2011-2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -37,7 +37,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
@ -312,6 +312,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
|
||||
/* Error exits */
|
||||
|
||||
errout_with_errno:
|
||||
stream->fs_flags |= __FS_FLAG_ERROR;
|
||||
lib_give_semaphore(stream);
|
||||
return -get_errno();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* libc/stdio/lib_libfwrite.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -37,7 +37,7 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h> /* for CONFIG_STDIO_BUFFER_SIZE */
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
@ -145,6 +145,7 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
stream->fs_bufpos = dest;
|
||||
|
||||
/* Is the buffer full? */
|
||||
@ -169,10 +170,21 @@ errout_with_semaphore:
|
||||
lib_give_semaphore(stream);
|
||||
|
||||
errout:
|
||||
if (ret < 0)
|
||||
{
|
||||
stream->fs_flags |= __FS_FLAG_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
{
|
||||
return write(stream->fs_fd, ptr, count);
|
||||
ssize_t ret = write(stream->fs_fd, ptr, count);
|
||||
if (ret < 0)
|
||||
{
|
||||
stream->fs_flags |= __FS_FLAG_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_STDIO_BUFFER_SIZE */
|
||||
|
Loading…
Reference in New Issue
Block a user