summaryrefslogtreecommitdiff
path: root/nuttx/lib/lib_fseek.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-01 20:35:41 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-01 20:35:41 +0000
commit671926c39c76b0bfb6442431bbdc6c85c21d7087 (patch)
tree414dd03cce0e7d3e0b3f5c057323c9d7e4a44b34 /nuttx/lib/lib_fseek.c
parentff578ec6f9ee1e0f015112924621e6ea5593883a (diff)
downloadpx4-nuttx-671926c39c76b0bfb6442431bbdc6c85c21d7087.tar.gz
px4-nuttx-671926c39c76b0bfb6442431bbdc6c85c21d7087.tar.bz2
px4-nuttx-671926c39c76b0bfb6442431bbdc6c85c21d7087.zip
Fix fseek/ftell; add fsetpos/fgetpos
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@862 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib/lib_fseek.c')
-rw-r--r--nuttx/lib/lib_fseek.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/nuttx/lib/lib_fseek.c b/nuttx/lib/lib_fseek.c
index 18781b6e3..379e5c322 100644
--- a/nuttx/lib/lib_fseek.c
+++ b/nuttx/lib/lib_fseek.c
@@ -89,11 +89,25 @@
/****************************************************************************
* Name: fseek
+ *
+ * Description:
+ * The fseek() function sets the file position indicator for the stream
+ * pointed to by stream. The new position, measured in bytes, is obtained
+ * by adding offset bytes to the position specified by whence. If whence is
+ * set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the
+ * start of the file, the current position indicator, or end-of-file,
+ * respectively. A successful call to the fseek() function clears the
+ * end-of-file indicator for the stream and undoes any effects of the ungetc(3)
+ * function on the same stream.
+ *
+ * Returned Value:
+ * Zero on succes; -1 on failure with errno set appropriately.
+ *
****************************************************************************/
-int fseek(FILE *stream, long int offset, int whence)
+int fseek(FAR FILE *stream, long int offset, int whence)
{
-#if CONFIG_STDIO_BUFFER_SIZE > 0
+ #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)
@@ -105,14 +119,20 @@ int fseek(FILE *stream, long int offset, int whence)
if (!stream)
{
- *get_errno_ptr() = EBADF;
+ errno = EBADF;
return ERROR;
}
#endif
+ /* On success or failure, discard any characters saved by ungetc() */
+
+#if CONFIG_NUNGET_CHARS > 0
+ stream->fs_nungotten = 0;
+#endif
+
/* Perform the fseek on the underlying file descriptor */
- return lseek(stream->fs_filedes, offset, whence) >= 0 ? OK : ERROR;
+ return lseek(stream->fs_filedes, offset, whence) == (off_t)-1 ? ERROR : OK;
}