Fix fseek/ftell; add fsetpos/fgetpos
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@862 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
3c21f19572
commit
b5e603e0ea
|
@ -435,3 +435,9 @@
|
|||
writing to the socket.
|
||||
|
||||
0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* FAT FS now uses position variable in struct file. This simplifies operations
|
||||
like ftell().
|
||||
* fseek() needs to discard bytes buffered by ungetc().
|
||||
* Corrected ftell() return value.
|
||||
* Added fsetpos() and fgetpos().
|
||||
|
||||
|
|
|
@ -1062,6 +1062,11 @@ buildroot-0.1.0 2007-03-09 <spudmonkey@racsa.co.cr>
|
|||
|
||||
<pre><ul>
|
||||
nuttx-0.3.14 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
* FAT FS now uses position variable in struct file. This simplifies operations
|
||||
like ftell().
|
||||
* fseek() needs to discard bytes buffered by ungetc().
|
||||
* Corrected ftell() return value.
|
||||
* Added fsetpos() and fgetpos().
|
||||
|
||||
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ User's Manual
|
|||
<p>
|
||||
Gregory Nutt
|
||||
<p>
|
||||
<small>Last Update: August 22, 2008</small>
|
||||
<small>Last Update: September 1, 2008</small>
|
||||
</center>
|
||||
|
||||
<h1>1.0 <A NAME="Introduction">Introduction</a></h1>
|
||||
|
@ -5910,11 +5910,14 @@ interface of the same name.
|
|||
</p>
|
||||
|
||||
<h2><a name="driveroperations">2.11.2 Driver Operations</a></h2>
|
||||
<a name="drvrfcntlops">
|
||||
<ul><pre>
|
||||
#include <fcntl.h>
|
||||
int open(const char *path, int oflag, ...);
|
||||
</pre></ul>
|
||||
</a>
|
||||
|
||||
<a name="drvrunistdops">
|
||||
<ul><pre>
|
||||
#include <unistd.h>
|
||||
int close(int fd);
|
||||
|
@ -5925,13 +5928,17 @@ interface of the same name.
|
|||
int unlink(const char *path);
|
||||
ssize_t write(int fd, const void *buf, size_t nbytes);
|
||||
</pre></ul>
|
||||
</a>
|
||||
|
||||
<a name="drvrioctlops">
|
||||
<ul><pre>
|
||||
#include <sys/ioctl.h>
|
||||
int ioctl(int fd, int req, unsigned long arg);
|
||||
</pre></ul>
|
||||
</a>
|
||||
|
||||
<h2><a name="directoryoperations">2.11.3 Directory Operations</a></h2>
|
||||
<a name="dirdirentops">
|
||||
<ul><pre>
|
||||
#include <dirent.h>
|
||||
int closedir(DIR *dirp);
|
||||
|
@ -5942,11 +5949,15 @@ interface of the same name.
|
|||
void seekdir(FAR DIR *dirp, int loc);
|
||||
int telldir(FAR DIR *dirp);
|
||||
</pre></ul>
|
||||
</a>
|
||||
|
||||
<a name="dirunistdops">
|
||||
<ul><pre>
|
||||
#include <unistd.h>
|
||||
int chdir(FAR const char *path);
|
||||
FAR char *getcwd(FAR char *buf, size_t size);
|
||||
</pre></ul>
|
||||
</a>
|
||||
|
||||
<h2><a name="standardio">2.11.4 Standard I/O</a></h2>
|
||||
<ul><pre>
|
||||
|
@ -5956,13 +5967,16 @@ interface of the same name.
|
|||
int feof(FILE *stream); /* Prototyped but not implemented */
|
||||
int ferror(FILE *stream); /* Prototyped but not implemented */
|
||||
int fgetc(FILE *stream);
|
||||
int fgetpos(FILE *stream, fpos_t *pos);
|
||||
char *fgets(char *s, int n, FILE *stream);
|
||||
FILE *fopen(const char *path, const char *type);
|
||||
int fprintf(FILE *stream, const char *format, ...);
|
||||
int fputc(int c, FILE *stream);
|
||||
int fputs(const char *s, FILE *stream);
|
||||
size_t fread(void *ptr, size_t size, size_t n_items, FILE *stream);
|
||||
int fseek(FILE *stream, long int offset, int whence); /* Prototyped but not implemented */
|
||||
int fseek(FILE *stream, long int offset, int whence);
|
||||
int fsetpos(FILE *stream, fpos_t *pos);
|
||||
long ftell(FILE *stream);
|
||||
size_t fwrite(const void *ptr, size_t size, size_t n_items, FILE *stream);
|
||||
char *gets(char *s);
|
||||
|
||||
|
@ -6973,29 +6987,57 @@ notify a task when a message is available on a queue.
|
|||
<h1><a name="index">Index</a></h1>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<td valign="top" width="34%">
|
||||
<li><a href="#accept">accept</a></li>
|
||||
<li><a href="#bind">bind</a></li>
|
||||
<li><a href="#dirunistdops">chdir</a></li>
|
||||
<li><a href="#clockgetres">clock_getres</a></li>
|
||||
<li><a href="#clockgettime">clock_gettime</a></li>
|
||||
<li><a href="#ClocksNTimers">Clocks</a></li>
|
||||
<li><a href="#clocksettime">clock_settime</a></li>
|
||||
<li><a href="#drvrunistdops">close</a></li>
|
||||
<li><a href="#dirdirentops">closedir</a></li>
|
||||
<li><a href="#connect">connect</a></li>
|
||||
<li><a href="#Data_Structures">Data structures</a></li>
|
||||
<li><a href="#directoryoperations">Directory operations</a></li>
|
||||
<li><a href="#driveroperations">Driver operations</a></li>
|
||||
<li><a href="#drvrunistdops">dup</a></li>
|
||||
<li><a href="#drvrunistdops">dup2</a></li>
|
||||
<li><a href="#exit">exit</a></li>
|
||||
<li><a href="#fatsupport">FAT File System Support</a></li>
|
||||
<li><a href="#standardio">fclose</a></li>
|
||||
<li><a href="#standardio">fdopen</a></li>
|
||||
<li><a href="#standardio">feof</a></li>
|
||||
<li><a href="#standardio">ferror</a></li>
|
||||
<li><a href="#FileSystem">File system, interfaces</a></li>
|
||||
<li><a href="#FileSystemOverview">File system, overview</a></li>
|
||||
<li><a href="#standardio">fflush</a></li>
|
||||
<li><a href="#standardio">fgetc</a></li>
|
||||
<li><a href="#standardio">fgetpos</a></li>
|
||||
<li><a href="#standardio">fgets</a></li>
|
||||
<li><a href="#standardio">fopen</a></li>
|
||||
<li><a href="#standardio">fprintf</a></li>
|
||||
<li><a href="#standardio">fputc</a></li>
|
||||
<li><a href="#standardio">fputs</a></li>
|
||||
<li><a href="#standardio">fread</a></li>
|
||||
<li><a href="#standardio">fseek</a></li>
|
||||
<li><a href="#standardio">fsetpos</a></li>
|
||||
<li><a href="#standardio">fstat(</a></li>
|
||||
<li><a href="#standardio">ftell</a></li>
|
||||
<li><a href="#standardio">fwrite</a></li>
|
||||
<li><a href="#dirunistdops">getcwd</a></li>
|
||||
<li><a href="#getpid">getpid</a></li>
|
||||
<li><a href="#standardio">gets</a></li>
|
||||
<li><a href="#getsockopt">getsockopt</a></li>
|
||||
<li><a href="#gmtimer">gmtime_r</a></li>
|
||||
<li><a href="#Introduction">Introduction</a>
|
||||
<li><a href="#drvrioctlops">ioctl</a></li>
|
||||
<li><a href="#kill">kill</a></li>
|
||||
<li><a href="#listen">listen</a></li>
|
||||
<li><a href="#localtimer">localtime_r</a></li>
|
||||
<li><a href="#drvrunistdops">lseek</a></li>
|
||||
<li><a href="#Message_Queue">Named Message Queue Interfaces</a>
|
||||
<li><a href="#standardio">mkdir</a></li>
|
||||
<li><a href="#mkfatfs">mkfatfs</a></li>
|
||||
<li><a href="#mkfifo">mkfifo</a></li>
|
||||
<li><a href="#mktime">mktime</a></li>
|
||||
|
@ -7010,8 +7052,13 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#mqtimedsend">mq_timedsend</a></li>
|
||||
<li><a href="#mqunlink">mq_unlink</a></li>
|
||||
<li><a href="#Network">Network Interfaces</a></li>
|
||||
<li><a href="#drvrfcntlops">open</a></li>
|
||||
<li><a href="#dirdirentops">opendir</a></li>
|
||||
<li><a href="#OS_Interfaces">OS Interfaces</a></li>
|
||||
<li><a href="#pipe">pipe</a></li>
|
||||
</td>
|
||||
<td valign="top" width="33%">
|
||||
<li><a href="#standardio">printf</a></li>
|
||||
<li><a href="#Pthread">Pthread Interfaces</a>
|
||||
<li><a href="#pthreadattrdestroy">pthread_attr_destroy</a></li>
|
||||
<li><a href="#pthreadattrgetinheritsched">pthread_attr_getinheritsched</a></li>
|
||||
|
@ -7052,8 +7099,6 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#pthreadmutexattrgetpshared">pthread_mutexattr_getpshared</a></li>
|
||||
<li><a href="#pthreadmutexattrgettype">pthread_mutexattr_gettype</a></li>
|
||||
<li><a href="#pthreadmutexattrinit">pthread_mutexattr_init</a></li>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<li><a href="#pthreadmutexattrsetpshared">pthread_mutexattr_setpshared</a></li>
|
||||
<li><a href="#pthreadmutexattrsettype">pthread_mutexattr_settype</a></li>
|
||||
<li><a href="#pthreadmutexdestrory">pthread_mutex_destroy</a></li>
|
||||
|
@ -7070,10 +7115,19 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#pthreadsigmask">pthread_sigmask</a></li>
|
||||
<li><a href="#pthreadtestcancelstate">pthread_testcancelstate</a></li>
|
||||
<li><a href="#pthreadyield">pthread_yield</a></li>
|
||||
<li><a href="#standardio">puts</a></li>
|
||||
<li><a href="#drvrunistdops">read</a></li>
|
||||
<li><a href="#dirdirentops">readdir</a></li>
|
||||
<li><a href="#dirdirentops">readdir_r</a></li>
|
||||
<li><a href="#recv">recv</a></li>
|
||||
<li><a href="#recvfrom">recvfrom</a></li>
|
||||
<li><a href="#standardio">rename</a></li>
|
||||
<li><a href="#standardio">rmdir</a></li>
|
||||
<li><a href="#dirdirentops">rewinddir</a></li>
|
||||
<li><a href="#schedgetparam">sched_getparam</a></li>
|
||||
<li><a href="#schedgetprioritymax">sched_get_priority_max</a></li>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<li><a href="#schedgetprioritymin">sched_get_priority_min</a></li>
|
||||
<li><a href="#schedgetrrinterval">sched_get_rr_interval</a></li>
|
||||
<li><a href="#schedlockcount">sched_lockcount</a></li>
|
||||
|
@ -7093,6 +7147,7 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#semunlink">sem_unlink</a></li>
|
||||
<li><a href="#semwait">sem_wait</a></li>
|
||||
<li><a href="#setgetscheduler">sched_getscheduler</a></li>
|
||||
<li><a href="#dirdirentops">seekdir</a></li>
|
||||
<li><a href="#send">send</a></li>
|
||||
<li><a href="#sendto">sendto</a></li>
|
||||
<li><a href="#setsockopt">setsockopt</a></li>
|
||||
|
@ -7110,7 +7165,10 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#sigtimedwait">sigtimedwait</a></li>
|
||||
<li><a href="#sigwaitinfo">sigwaitinfo</a></li>
|
||||
<li><a href="#socket">socket</a></li>
|
||||
<li><a href="#standardio">sprintf</a></li>
|
||||
<li><a href="#standardio">Standard I/O</a></li>
|
||||
<li><a href="#standardio">stat</a></li>
|
||||
<li><a href="#standardio">statfs</a></li>
|
||||
<li><a href="#taskactivate">task_activate</a></li>
|
||||
<li><a href="#Task_Control">Task Control Interfaces</a>
|
||||
<li><a href="#taskcreate">task_create</a></li>
|
||||
|
@ -7119,18 +7177,25 @@ notify a task when a message is available on a queue.
|
|||
<li><a href="#taskrestart">task_restart</a></li>
|
||||
<li><a href="#Task_Schedule">Task Scheduling Interfaces</a>
|
||||
<li><a href="#Task_Switch">Task Switching Interfaces</a>
|
||||
<li><a href="#dirdirentops">telldir</a></li>
|
||||
<li><a href="#timercreate">timer_create</a></li>
|
||||
<li><a href="#timerdelete">timer_delete</a></li>
|
||||
<li><a href="#timergetoverrun">timer_getoverrun</a></li>
|
||||
<li><a href="#timergettime">timer_gettime</a></li>
|
||||
<li><a href="#ClocksNTimers">Timers</a></li>
|
||||
<li><a href="#timersettime">timer_settime</a></li>
|
||||
<li><a href="#standardio">ungetc</a></li>
|
||||
<li><a href="#drvrunistdops">unlink</a></li>
|
||||
<li><a href="#standardio">vfprintf</a></li>
|
||||
<li><a href="#standardio">vprintf</a></li>
|
||||
<li><a href="#standardio">vsprintf</a></li>
|
||||
<li><a href="#Watchdogs">Watchdog Timer Interfaces</a>
|
||||
<li><a href="#wdcancel">wd_cancel</a></li>
|
||||
<li><a href="#wdcreate">wd_create</a></li>
|
||||
<li><a href="#wddelete">wd_delete</a></li>
|
||||
<li><a href="#wdgettime">wd_gettime</a></li>
|
||||
<li><a href="#wdstart">wd_start</a></li>
|
||||
<li><a href="#drvrunistdops">write</a></li>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
59
nuttx/TODO
59
nuttx/TODO
|
@ -7,21 +7,22 @@ NuttX TODO List (Last updated July 31, 2008)
|
|||
(1) Signals (sched/, arch/)
|
||||
(1) pthreads (sched/)
|
||||
(1) C++ Support
|
||||
(10) Network (net/, netutils/)
|
||||
(12) Network (net/, netutils/)
|
||||
(2) USB (drivers/usbdev)
|
||||
(3) Libraries (lib/)
|
||||
(4) File system/Generic drivers (fs/, drivers/)
|
||||
(1) Pascal add-on (pcode/)
|
||||
(2) Documentation (Documentation/)
|
||||
(3) Build system
|
||||
(0) Applications & Tests (examples/)
|
||||
(2) NuttShell (NSH) (examples/nsh)
|
||||
(1) Other Applications & Tests (examples/)
|
||||
(1) ARM (arch/arm/)
|
||||
(1) ARM/C5471 (arch/arm/src/c5471/)
|
||||
(1) ARM/DM320 (arch/arm/src/dm320/)
|
||||
(2) ARM/LPC214x (arch/arm/src/lpc214x/)
|
||||
(4) pjrc-8052 / MCS51 (arch/pjrc-8051/)
|
||||
(6) z80/z8 (arch/z80/)
|
||||
(7) z16 (arch/z16/)
|
||||
(7) z80/z8 (arch/z80/)
|
||||
(8) z16 (arch/z16/)
|
||||
|
||||
o Task/Scheduler (sched/)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -183,6 +184,23 @@ o Network (net/, netutils/)
|
|||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Description: At present, there cannot be two concurrent active TCP send
|
||||
operations in progress. This is because the uIP ACK logic will
|
||||
support only one transfer at a time. The solution is simple:
|
||||
A mutex will be needed to make sure that each send that is
|
||||
started is able to be the exclusive sender until all of the
|
||||
data to be sent has been ACKed.
|
||||
Status: Open. There is some temporary logic to examples/nsh that does
|
||||
this same fix and that temporary logic should be removed when
|
||||
send() is fixed.
|
||||
Priority: Medium-Low. This is an important issue for applications that
|
||||
send on the same TCP socket from multiple threads.
|
||||
|
||||
Description: Some application-level interface to the ICMP logic is needed
|
||||
to support ping from the target.
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
o USB (drivers/usbdev)
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -272,8 +290,27 @@ o Build system
|
|||
Status: Open
|
||||
Priority: Medium (maybe higher for z80 target)
|
||||
|
||||
o Applications & Tests (examples/)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
o NuttShell (NSH) (examples/nsh)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Description: When the telnetd front end is received, each TCP packet
|
||||
received causes a prompt (nsh >) to be presented. The
|
||||
prompt should only be presented when the user enters a
|
||||
carriage return.
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Description: Here are some commands that would be good to have in NSH:
|
||||
ping
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
o Other Applications & Tests (examples/)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Description: The redirection test (part of examples/pipe) terminates
|
||||
incorrectly on the Cywgin-based simulation platform (but works
|
||||
fine on the Linux-based simulation platform).
|
||||
|
||||
o ARM (arch/arm/)
|
||||
^^^^^^^^^^^^^^^
|
||||
|
@ -405,6 +442,11 @@ o z80/z8 (arch/z80)
|
|||
Status: Open
|
||||
Priority: Medium
|
||||
|
||||
Description: Upgrade to the ZDS-II Z8Encore! 4.11.0 toolchain
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
|
||||
o z16 (arch/z16)
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -491,4 +533,9 @@ o z16 (arch/z16)
|
|||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Description: Upgrade to the ZDS-II ZNEO 4.11.1 toolchain
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -74,15 +74,15 @@
|
|||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int fat_open(FAR struct file *filp, const char *relpath,
|
||||
static int fat_open(FAR struct file *filep, const char *relpath,
|
||||
int oflags, mode_t mode);
|
||||
static int fat_close(FAR struct file *filp);
|
||||
static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen);
|
||||
static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
||||
static int fat_close(FAR struct file *filep);
|
||||
static ssize_t fat_read(FAR struct file *filep, char *buffer, size_t buflen);
|
||||
static ssize_t fat_write(FAR struct file *filep, const char *buffer,
|
||||
size_t buflen);
|
||||
static off_t fat_seek(FAR struct file *filp, off_t offset, int whence);
|
||||
static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg);
|
||||
static int fat_sync(FAR struct file *filp);
|
||||
static off_t fat_seek(FAR struct file *filep, off_t offset, int whence);
|
||||
static int fat_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
static int fat_sync(FAR struct file *filep);
|
||||
|
||||
static int fat_opendir(struct inode *mountpt, const char *relpath,
|
||||
struct internal_dir_s *dir);
|
||||
|
@ -149,7 +149,7 @@ const struct mountpt_operations fat_operations =
|
|||
* Name: fat_open
|
||||
****************************************************************************/
|
||||
|
||||
static int fat_open(FAR struct file *filp, const char *relpath,
|
||||
static int fat_open(FAR struct file *filep, const char *relpath,
|
||||
int oflags, mode_t mode)
|
||||
{
|
||||
struct fat_dirinfo_s dirinfo;
|
||||
|
@ -160,13 +160,13 @@ static int fat_open(FAR struct file *filp, const char *relpath,
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv == NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv == NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Get the mountpoint inode reference from the file structure and the
|
||||
* mountpoint private data from the inode structure
|
||||
*/
|
||||
|
||||
inode = filp->f_inode;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -320,7 +320,7 @@ static int fat_open(FAR struct file *filp, const char *relpath,
|
|||
|
||||
/* Attach the private date to the struct file instance */
|
||||
|
||||
filp->f_priv = ff;
|
||||
filep->f_priv = ff;
|
||||
|
||||
/* Then insert the new instance into the mountpoint structure.
|
||||
* It needs to be there (1) to handle error conditions that effect
|
||||
|
@ -337,7 +337,7 @@ static int fat_open(FAR struct file *filp, const char *relpath,
|
|||
|
||||
if ((oflags & (O_APPEND|O_WRONLY)) == (O_APPEND|O_WRONLY))
|
||||
{
|
||||
ssize_t offset = (ssize_t)fat_seek(filp, ff->ff_size, SEEK_SET);
|
||||
ssize_t offset = (ssize_t)fat_seek(filep, ff->ff_size, SEEK_SET);
|
||||
if (offset < 0)
|
||||
{
|
||||
free(ff);
|
||||
|
@ -363,7 +363,7 @@ errout_with_semaphore:
|
|||
* Name: fat_close
|
||||
****************************************************************************/
|
||||
|
||||
static int fat_close(FAR struct file *filp)
|
||||
static int fat_close(FAR struct file *filep)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct fat_mountpt_s *fs;
|
||||
|
@ -372,12 +372,12 @@ static int fat_close(FAR struct file *filp)
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -388,7 +388,7 @@ static int fat_close(FAR struct file *filp)
|
|||
|
||||
/* Synchronize the file buffers and disk content; update times */
|
||||
|
||||
ret = fat_sync(filp);
|
||||
ret = fat_sync(filep);
|
||||
|
||||
/* Then deallocate the memory structures created when the open method
|
||||
* was called.
|
||||
|
@ -404,7 +404,7 @@ static int fat_close(FAR struct file *filp)
|
|||
/* Then free the file structure itself. */
|
||||
|
||||
free(ff);
|
||||
filp->f_priv = NULL;
|
||||
filep->f_priv = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ static int fat_close(FAR struct file *filp)
|
|||
* Name: fat_read
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
||||
static ssize_t fat_read(FAR struct file *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct fat_mountpt_s *fs;
|
||||
|
@ -428,12 +428,12 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -457,7 +457,7 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
|||
|
||||
/* Get the number of bytes left in the file */
|
||||
|
||||
bytesleft = ff->ff_size - ff->ff_position;
|
||||
bytesleft = ff->ff_size - filep->f_pos;
|
||||
|
||||
/* Truncate read count so that it does not exceed the number
|
||||
* of bytes left in the file.
|
||||
|
@ -478,7 +478,7 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
|||
{
|
||||
/* Get offset into the sector where we begin the read */
|
||||
|
||||
int sectorindex = ff->ff_position & SEC_NDXMASK(fs);
|
||||
int sectorindex = filep->f_pos & SEC_NDXMASK(fs);
|
||||
bytesread = 0;
|
||||
|
||||
/* Check if the current read stream happens to lie on a
|
||||
|
@ -505,7 +505,7 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
|||
{
|
||||
/* No.. Handle the case of the first sector of the file */
|
||||
|
||||
if (ff->ff_position == 0)
|
||||
if (filep->f_pos == 0)
|
||||
{
|
||||
/* Get the first cluster of the file */
|
||||
|
||||
|
@ -602,10 +602,10 @@ static ssize_t fat_read(FAR struct file *filp, char *buffer, size_t buflen)
|
|||
|
||||
/* Set up for the next sector read */
|
||||
|
||||
userbuffer += bytesread;
|
||||
ff->ff_position += bytesread;
|
||||
readsize += bytesread;
|
||||
buflen -= bytesread;
|
||||
userbuffer += bytesread;
|
||||
filep->f_pos += bytesread;
|
||||
readsize += bytesread;
|
||||
buflen -= bytesread;
|
||||
}
|
||||
|
||||
fat_semgive(fs);
|
||||
|
@ -620,7 +620,7 @@ errout_with_semaphore:
|
|||
* Name: fat_write
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
||||
static ssize_t fat_write(FAR struct file *filep, const char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
struct inode *inode;
|
||||
|
@ -636,12 +636,12 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -681,7 +681,7 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||
{
|
||||
/* Get offset into the sector where we begin the read */
|
||||
|
||||
int sectorindex = ff->ff_position & SEC_NDXMASK(fs);
|
||||
int sectorindex = filep->f_pos & SEC_NDXMASK(fs);
|
||||
|
||||
/* Check if the current read stream happens to lie on a
|
||||
* sector boundary.
|
||||
|
@ -707,7 +707,7 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||
{
|
||||
/* No.. Handle the case of the first sector of the file */
|
||||
|
||||
if (ff->ff_position == 0)
|
||||
if (filep->f_pos == 0)
|
||||
{
|
||||
/* Check the first cluster of the file. Zero means that
|
||||
* the file is empty -- perhaps the file was truncated or
|
||||
|
@ -816,12 +816,12 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||
* We will first have to read the full sector in memory as
|
||||
* part of a read-modify-write operation. NOTE we don't
|
||||
* have to read the data on a rare case: When we are extending
|
||||
* the file (ff->ff_position == ff->ff_size) -AND- the new data
|
||||
* the file (filep->f_pos == ff->ff_size) -AND- the new data
|
||||
* happens to be aligned at the beginning of the sector
|
||||
* (sectorindex == 0).
|
||||
*/
|
||||
|
||||
if (ff->ff_position < ff->ff_size || sectorindex != 0)
|
||||
if (filep->f_pos < ff->ff_size || sectorindex != 0)
|
||||
{
|
||||
ff->ff_currentsector = writesector;
|
||||
ret = fat_ffcacheread(fs, ff, writesector);
|
||||
|
@ -846,17 +846,17 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||
|
||||
/* Set up for the next write */
|
||||
|
||||
userbuffer += writesize;
|
||||
ff->ff_position += writesize;
|
||||
userbuffer += writesize;
|
||||
filep->f_pos += writesize;
|
||||
byteswritten += writesize;
|
||||
buflen -= writesize;
|
||||
buflen -= writesize;
|
||||
}
|
||||
|
||||
/* The transfer has completed without error. Update the file size */
|
||||
|
||||
if (ff->ff_position > ff->ff_size)
|
||||
if (filep->f_pos > ff->ff_size)
|
||||
{
|
||||
ff->ff_size = ff->ff_position;
|
||||
ff->ff_size = filep->f_pos;
|
||||
}
|
||||
|
||||
fat_semgive(fs);
|
||||
|
@ -871,7 +871,7 @@ errout_with_semaphore:
|
|||
* Name: fat_seek
|
||||
****************************************************************************/
|
||||
|
||||
static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
||||
static off_t fat_seek(FAR struct file *filep, off_t offset, int whence)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct fat_mountpt_s *fs;
|
||||
|
@ -884,12 +884,12 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -904,7 +904,7 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
|||
case SEEK_CUR: /* The offset is set to its current location plus
|
||||
* offset bytes. */
|
||||
|
||||
position = offset + ff->ff_position;
|
||||
position = offset + filep->f_pos;
|
||||
break;
|
||||
|
||||
case SEEK_END: /* The offset is set to the size of the file plus
|
||||
|
@ -946,7 +946,7 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
|||
|
||||
/* Set file position to the beginning of the file */
|
||||
|
||||
ff->ff_position = 0;
|
||||
filep->f_pos = 0;
|
||||
ff->ff_sectorsincluster = 1;
|
||||
|
||||
/* Move file position if necessary */
|
||||
|
@ -1044,8 +1044,8 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
|||
|
||||
/* Otherwise, update the position and continue looking */
|
||||
|
||||
ff->ff_position += clustersize;
|
||||
position -= clustersize;
|
||||
filep->f_pos += clustersize;
|
||||
position -= clustersize;
|
||||
}
|
||||
|
||||
/* We get here after we have found the sector containing
|
||||
|
@ -1078,15 +1078,15 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
|
|||
|
||||
/* And save the new file position */
|
||||
|
||||
ff->ff_position += position;
|
||||
filep->f_pos += position;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we extended the size of the file, then mark the file as modified. */
|
||||
|
||||
if ((ff->ff_oflags & O_WROK) != 0 && ff->ff_position > ff->ff_size)
|
||||
if ((ff->ff_oflags & O_WROK) != 0 && filep->f_pos > ff->ff_size)
|
||||
{
|
||||
ff->ff_size = ff->ff_position;
|
||||
ff->ff_size = filep->f_pos;
|
||||
ff->ff_bflags |= FFBUFF_MODIFIED;
|
||||
}
|
||||
|
||||
|
@ -1102,7 +1102,7 @@ errout_with_semaphore:
|
|||
* Name: fat_ioctl
|
||||
****************************************************************************/
|
||||
|
||||
static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg)
|
||||
static int fat_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct fat_mountpt_s *fs;
|
||||
|
@ -1111,12 +1111,12 @@ static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg)
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
@ -1145,7 +1145,7 @@ static int fat_ioctl(FAR struct file *filp, int cmd, unsigned long arg)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int fat_sync(FAR struct file *filp)
|
||||
static int fat_sync(FAR struct file *filep)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct fat_mountpt_s *fs;
|
||||
|
@ -1156,12 +1156,12 @@ static int fat_sync(FAR struct file *filp)
|
|||
|
||||
/* Sanity checks */
|
||||
|
||||
DEBUGASSERT(filp->f_priv != NULL && filp->f_inode != NULL);
|
||||
DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
|
||||
|
||||
/* Recover our private data from the struct file instance */
|
||||
|
||||
ff = filp->f_priv;
|
||||
inode = filp->f_inode;
|
||||
ff = filep->f_priv;
|
||||
inode = filep->f_inode;
|
||||
fs = inode->i_private;
|
||||
|
||||
DEBUGASSERT(fs != NULL);
|
||||
|
|
|
@ -513,8 +513,7 @@ struct fat_file_s
|
|||
uint16 ff_dirindex; /* Index into ff_dirsector to directory entry */
|
||||
uint32 ff_currentcluster; /* Current cluster being accessed */
|
||||
size_t ff_dirsector; /* Sector containing the directory entry */
|
||||
size_t ff_position; /* File position for read/write/seek in bytes */
|
||||
size_t ff_size; /* Size of the file in bytes */
|
||||
off_t ff_size; /* Size of the file in bytes */
|
||||
size_t ff_startcluster; /* Start cluster of file on media */
|
||||
size_t ff_currentsector; /* Current sector in the file buffer */
|
||||
ubyte *ff_buffer; /* File buffer (for partial sector accesses) */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/************************************************************
|
||||
* stdio.h
|
||||
/****************************************************************************
|
||||
* include/stdio.h
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -14,7 +14,7 @@
|
|||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
|
@ -31,14 +31,14 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __STDIO_H
|
||||
#define __STDIO_H
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
|
@ -50,13 +50,13 @@
|
|||
|
||||
#include <nuttx/fs.h>
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* File System Definitions **********************************/
|
||||
/* File System Definitions **************************************************/
|
||||
|
||||
/* File system error values *********************************/
|
||||
/* File system error values *************************************************/
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
|
@ -74,24 +74,23 @@
|
|||
#define putchar(c) fputc(c, stdout)
|
||||
#define getc(s) fgetc(s)
|
||||
#define getchar() fgetc(stdin)
|
||||
#define ftell(s) fseek((s),0,SEEK_CUR)
|
||||
#define rewind(s) ((void)fseek((s),0,SEEK_SET))
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/* Streams */
|
||||
|
||||
typedef FAR struct file_struct FILE;
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
@ -108,16 +107,17 @@ EXTERN int fflush(FILE *stream);
|
|||
EXTERN int feof(FILE *stream);
|
||||
EXTERN int ferror(FILE *stream);
|
||||
EXTERN int fgetc(FILE *stream);
|
||||
EXTERN int fgetpos(FILE *stream, fpos_t *pos);
|
||||
EXTERN char *fgets(char *s, int n, FILE *stream);
|
||||
EXTERN FILE *fopen(const char *path, const char *type);
|
||||
EXTERN int fprintf(FILE *stream, const char *format, ...);
|
||||
EXTERN int fputc(int c, FILE *stream);
|
||||
EXTERN int fputs(const char *s, FILE *stream);
|
||||
EXTERN size_t fread(void *ptr, size_t size, size_t n_items,
|
||||
FILE *stream);
|
||||
EXTERN int fseek(FILE *stream, long int offset, int whence);
|
||||
EXTERN size_t fwrite(const void *ptr, size_t size,
|
||||
size_t n_items, FILE *stream);
|
||||
EXTERN size_t fread(void *ptr, size_t size, size_t n_items, FILE *stream);
|
||||
EXTERN int fseek(FAR FILE *stream, long int offset, int whence);
|
||||
EXTERN int fsetpos(FILE *stream, fpos_t *pos);
|
||||
EXTERN long ftell(FAR FILE *stream);
|
||||
EXTERN size_t fwrite(const void *ptr, size_t size, size_t n_items, FILE *stream);
|
||||
EXTERN char *gets(char *s);
|
||||
|
||||
EXTERN int printf(const char *format, ...);
|
||||
|
|
|
@ -123,6 +123,7 @@ typedef sint32 off_t;
|
|||
typedef uint16 blksize_t;
|
||||
typedef uint32 blkcnt_t;
|
||||
#endif
|
||||
typedef off_t fpos_t;
|
||||
typedef sint16 uid_t;
|
||||
typedef sint16 gid_t;
|
||||
typedef uint16 dev_t;
|
||||
|
|
|
@ -60,8 +60,9 @@ ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
|||
STDIO_SRCS += lib_rawstream.c
|
||||
ifneq ($(CONFIG_NFILE_STREAMS),0)
|
||||
STDIO_SRCS += lib_fopen.c lib_fclose.c lib_fread.c lib_libfread.c lib_fseek.c \
|
||||
lib_fgetc.c lib_fgets.c lib_gets.c lib_fwrite.c lib_libfwrite.c \
|
||||
lib_fflush.c lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \
|
||||
lib_ftell.c lib_fsetpos.c lib_fgetpos.c lib_fgetc.c lib_fgets.c \
|
||||
lib_gets.c lib_fwrite.c lib_libfwrite.c lib_fflush.c \
|
||||
lib_libflushall.c lib_libfflush.c lib_rdflush.c lib_wrflush.c \
|
||||
lib_fputc.c lib_puts.c lib_fputs.c lib_ungetc.c lib_vprintf.c \
|
||||
lib_fprintf.c lib_vfprintf.c lib_stdstream.c
|
||||
endif
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/****************************************************************************
|
||||
* lib/lib_fgetpos.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fgetpos
|
||||
*
|
||||
* Description:
|
||||
* fgetpos() function is an alternate interfaces equivalent to ftell().
|
||||
* It gets the current value of the file offset and store it in the location
|
||||
* referenced by pos. On some non-UNIX systems an fpos_t object may be a
|
||||
* complex object and fsetpos may be the only way to portably reposition a
|
||||
* stream.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on succes; -1 on failure with errno set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int fgetpos(FILE *stream, fpos_t *pos)
|
||||
{
|
||||
long position;
|
||||
|
||||
#if CONFIG_DEBUG
|
||||
if (!stream || !pos)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
position = ftell(stream, (off_t)*pos, SEEK_SET);
|
||||
if (position == -1)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
*pos = (fpos_t)pos;
|
||||
return OK;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/****************************************************************************
|
||||
* lib/lib_fsetpos.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fsetpos
|
||||
*
|
||||
* Description:
|
||||
* fsetpos() function is an alternate interfaces equivalent to fseek()
|
||||
* (with whence set to SEEK_SET). It sets the current value of the file
|
||||
* offset to value in the location referenced by pos. On some non-UNIX
|
||||
* systems an fpos_t object may be a complex object and fsetpos may be the
|
||||
* only way to portably reposition a stream.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on succes; -1 on failure with errno set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int fsetpos(FILE *stream, fpos_t *pos)
|
||||
{
|
||||
#if CONFIG_DEBUG
|
||||
if (!stream || !pos)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
return fseek(stream, (off_t)*pos, SEEK_SET);
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/****************************************************************************
|
||||
* lib/lib_ftell.c
|
||||
*
|
||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ftell
|
||||
*
|
||||
* Description:
|
||||
* ftell() returns the current value of the file position indicator for the
|
||||
* stream pointed to by stream.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on succes; -1 on failure with errno set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
long ftell(FAR FILE *stream)
|
||||
{
|
||||
off_t position;
|
||||
|
||||
/* Verify that we were provided with a stream */
|
||||
|
||||
if (!stream)
|
||||
{
|
||||
errno = EBADF;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Perform the lseek to the current position. This will not move the
|
||||
* file pointer, but will return its current setting
|
||||
*/
|
||||
|
||||
position = lseek(stream->fs_filedes, 0, SEEK_CUR);
|
||||
if (position != (off_t)-1)
|
||||
{
|
||||
return (long)position;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/************************************************************
|
||||
/****************************************************************************
|
||||
* lib_ungetc.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -14,7 +14,7 @@
|
|||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
|
@ -31,15 +31,15 @@
|
|||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdio.h>
|
||||
|
@ -48,45 +48,45 @@
|
|||
#include <nuttx/fs.h>
|
||||
#include "lib_internal.h"
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Function Prototypes
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/**********************************************************
|
||||
/**************************************************************************
|
||||
* Global Constant Data
|
||||
**********************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Variables
|
||||
************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/**********************************************************
|
||||
/**************************************************************************
|
||||
* Private Constant Data
|
||||
**********************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
**********************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
**********************************************************/
|
||||
**************************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* fgetc
|
||||
**********************************************************/
|
||||
/****************************************************************************
|
||||
* Name: ungetc
|
||||
**************************************************************************/
|
||||
|
||||
int ungetc(int c, FILE *stream)
|
||||
{
|
||||
|
@ -99,7 +99,7 @@ int ungetc(int c, FILE *stream)
|
|||
if ((stream && stream->fs_filedes < 0) ||
|
||||
((stream->fs_oflags & O_RDOK) == 0))
|
||||
{
|
||||
*get_errno_ptr() = EBADF;
|
||||
errno = EBADF;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ int ungetc(int c, FILE *stream)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
*get_errno_ptr() = ENOMEM;
|
||||
errno = ENOMEM;
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue