diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-05 18:13:13 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-02-05 18:13:13 +0000 |
commit | d1f1e007f149be8a8c3084d144599a7456d15aba (patch) | |
tree | dc4794aec1816bddcdf86ad50da6c7ebe86b4d51 /nuttx/lib/lib_fseek.c | |
parent | e05c8208701c52f71abfda389c5dbbea8cf380a7 (diff) | |
download | px4-nuttx-d1f1e007f149be8a8c3084d144599a7456d15aba.tar.gz px4-nuttx-d1f1e007f149be8a8c3084d144599a7456d15aba.tar.bz2 px4-nuttx-d1f1e007f149be8a8c3084d144599a7456d15aba.zip |
Various fixes for buffered R/W I/O and seeking
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@630 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_fseek.c')
-rw-r--r-- | nuttx/lib/lib_fseek.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/nuttx/lib/lib_fseek.c b/nuttx/lib/lib_fseek.c index a770f8f30..18781b6e3 100644 --- a/nuttx/lib/lib_fseek.c +++ b/nuttx/lib/lib_fseek.c @@ -41,8 +41,13 @@ * Included Files ****************************************************************************/ +#include <nuttx/config.h> + +#include <sys/types.h> #include <stdio.h> #include <unistd.h> +#include <fcntl.h> +#include <errno.h> #include "lib_internal.h" @@ -75,7 +80,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions ****************************************************************************/ /**************************************************************************** @@ -84,6 +93,23 @@ int fseek(FILE *stream, long int offset, int whence) { +#if CONFIG_STDIO_BUFFER_SIZE > 0 + /* Flush any valid read/write data in the buffer (also verifies stream) */ + + if (lib_rdflush(stream) < 0 || lib_wrflush(stream) < 0) + { + return ERROR; + } +#else + /* Verify that we were provided with a stream */ + + if (!stream) + { + *get_errno_ptr() = EBADF; + return ERROR; + } +#endif + /* Perform the fseek on the underlying file descriptor */ return lseek(stream->fs_filedes, offset, whence) >= 0 ? OK : ERROR; |