summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-12-17 12:17:11 +0000
committerJens Arnold <amiconn@rockbox.org>2005-12-17 12:17:11 +0000
commita601fb8d1922ddd8e7fbb39f8ae2c6137b3a12a5 (patch)
treeea42ac66c73091329f904f982b5059cf6005eb87
parent69f187032425722a8ca5ee75a160e4b635a168a8 (diff)
downloadrockbox-a601fb8d1922ddd8e7fbb39f8ae2c6137b3a12a5.zip
rockbox-a601fb8d1922ddd8e7fbb39f8ae2c6137b3a12a5.tar.gz
rockbox-a601fb8d1922ddd8e7fbb39f8ae2c6137b3a12a5.tar.bz2
rockbox-a601fb8d1922ddd8e7fbb39f8ae2c6137b3a12a5.tar.xz
More compact & straight-forward headbytes handling.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8255 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/common/file.c45
1 files changed, 11 insertions, 34 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 7f36ecf..90fab6d 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -24,6 +24,7 @@
#include "dir.h"
#include "debug.h"
#include "dircache.h"
+#include "system.h"
/*
These functions provide a roughly POSIX-compatible file IO API.
@@ -439,53 +440,29 @@ static int readwrite(int fd, void* buf, long count, bool write)
/* any head bytes? */
if ( file->cacheoffset != -1 ) {
- int headbytes;
int offs = file->cacheoffset;
- if ( count <= SECTOR_SIZE - file->cacheoffset ) {
- headbytes = count;
- file->cacheoffset += count;
- if ( file->cacheoffset >= SECTOR_SIZE )
- {
- /* Flush the cache first if it's dirty. */
- if (file->dirty)
- {
- rc = flush_cache(fd);
- if ( rc < 0 ) {
- errno = EIO;
- return rc * 10 - 9;
- }
- }
- file->cacheoffset = -1;
- }
+ int headbytes = MIN(count, SECTOR_SIZE - offs);
+
+ if (write) {
+ memcpy( file->cache + offs, buf, headbytes );
+ file->dirty = true;
}
else {
- headbytes = SECTOR_SIZE - file->cacheoffset;
- if (file->dirty)
- {
- rc = flush_cache(fd);
- if ( rc < 0 ) {
- errno = EIO;
- return rc * 10 - 9;
- }
- }
- file->cacheoffset = -1;
+ memcpy( buf, file->cache + offs, headbytes );
}
- if (write) {
- memcpy( file->cache + offs, buf, headbytes );
- if (offs+headbytes == SECTOR_SIZE) {
+ if (offs + headbytes == SECTOR_SIZE) {
+ if (file->dirty) {
int rc = flush_cache(fd);
if ( rc < 0 ) {
errno = EIO;
return rc * 10 - 2;
}
- file->cacheoffset = -1;
}
- else
- file->dirty = true;
+ file->cacheoffset = -1;
}
else {
- memcpy( buf, file->cache + offs, headbytes );
+ file->cacheoffset += headbytes;
}
nread = headbytes;