forked from len0rd/rockbox
Zagor added the flush() function
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3416 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
c5aaab4a36
commit
44e51833ed
2 changed files with 28 additions and 1 deletions
|
|
@ -174,6 +174,31 @@ int close(int fd)
|
|||
|
||||
LDEBUGF("close(%d)\n", fd);
|
||||
|
||||
if (fd < 0 || fd > MAX_OPEN_FILES-1) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!file->busy) {
|
||||
errno = EBADF;
|
||||
return -2;
|
||||
}
|
||||
if (file->write) {
|
||||
rc = flush(fd);
|
||||
if (rc < 0)
|
||||
return rc * 10 - 3;
|
||||
}
|
||||
|
||||
file->busy = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flush(int fd)
|
||||
{
|
||||
struct filedesc* file = &openfiles[fd];
|
||||
int rc = 0;
|
||||
|
||||
LDEBUGF("flush(%d)\n", fd);
|
||||
|
||||
if (fd < 0 || fd > MAX_OPEN_FILES-1) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
|
@ -202,7 +227,6 @@ int close(int fd)
|
|||
if (rc < 0)
|
||||
return rc * 10 - 5;
|
||||
}
|
||||
file->busy = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -318,9 +342,11 @@ static int flush_cache(int fd)
|
|||
DEBUGF("Flushing dirty sector cache %x\n", sector);
|
||||
|
||||
/* seek back one sector to get file position right */
|
||||
#if 0
|
||||
rc = fat_seek(&(file->fatfile), sector);
|
||||
if ( rc < 0 )
|
||||
return rc * 10 - 1;
|
||||
#endif
|
||||
|
||||
rc = fat_readwrite(&(file->fatfile), 1,
|
||||
file->cache, true );
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ extern int remove(const char*);
|
|||
#ifndef SIMULATOR
|
||||
extern int open(const char* pathname, int flags);
|
||||
extern int close(int fd);
|
||||
extern int flush(int fd);
|
||||
extern int read(int fd, void* buf, int count);
|
||||
extern int lseek(int fd, int offset, int whence);
|
||||
extern int creat(const char *pathname, int mode);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue