projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use strobe macros. Clean up and reformat.
[bertos.git]
/
bertos
/
emul
/
kfile_posix.c
diff --git
a/bertos/emul/kfile_posix.c
b/bertos/emul/kfile_posix.c
index 593571d4bfb8494c45540f35684d69a6052fde6d..d196c6aa7eadb5b23fb4d0b42c5a0341eae416b7 100644
(file)
--- a/
bertos/emul/kfile_posix.c
+++ b/
bertos/emul/kfile_posix.c
@@
-32,22
+32,27
@@
*
* \brief KFile interface implementation in Posix systems.
*
*
* \brief KFile interface implementation in Posix systems.
*
- * \version $Id$
* \author Luca Ottaviano <lottaviano@develer.com>
*/
#include <emul/kfile_posix.h>
* \author Luca Ottaviano <lottaviano@develer.com>
*/
#include <emul/kfile_posix.h>
+#include <string.h>
static size_t kfile_posix_read(struct KFile *_fd, void *buf, size_t size)
{
KFilePosix *fd = KFILEPOSIX_CAST(_fd);
static size_t kfile_posix_read(struct KFile *_fd, void *buf, size_t size)
{
KFilePosix *fd = KFILEPOSIX_CAST(_fd);
- return fread(buf, sizeof(uint8_t), size, fd->fp);
+ size_t len = fread(buf, sizeof(uint8_t), size, fd->fp);
+ fd->fd.seek_pos += len;
+ return len;
}
static size_t kfile_posix_write(struct KFile *_fd, const void *buf, size_t size)
{
KFilePosix *fd = KFILEPOSIX_CAST(_fd);
}
static size_t kfile_posix_write(struct KFile *_fd, const void *buf, size_t size)
{
KFilePosix *fd = KFILEPOSIX_CAST(_fd);
- return fwrite(buf, sizeof(uint8_t), size, fd->fp);
+ size_t len = fwrite(buf, sizeof(uint8_t), size, fd->fp);
+ fd->fd.seek_pos += len;
+ fd->fd.size = MAX(fd->fd.size, fd->fd.seek_pos);
+ return len;
}
static kfile_off_t kfile_posix_seek(struct KFile *_fd, kfile_off_t offset, KSeekMode whence)
}
static kfile_off_t kfile_posix_seek(struct KFile *_fd, kfile_off_t offset, KSeekMode whence)
@@
-67,9
+72,14
@@
static kfile_off_t kfile_posix_seek(struct KFile *_fd, kfile_off_t offset, KSeek
break;
default:
ASSERT(0);
break;
default:
ASSERT(0);
+ return EOF;
}
}
+ int err = fseek(fd->fp, offset, std_whence);
+ if (err)
+ return err;
- return fseek(fd->fp, offset, std_whence);
+ fd->fd.seek_pos = ftell(fd->fp);
+ return fd->fd.seek_pos;
}
static int kfile_posix_close(struct KFile *_fd)
}
static int kfile_posix_close(struct KFile *_fd)
@@
-86,7
+96,8
@@
static int kfile_posix_flush(struct KFile *_fd)
FILE *kfile_posix_init(KFilePosix *file, const char *filename, const char *mode)
{
FILE *kfile_posix_init(KFilePosix *file, const char *filename, const char *mode)
{
- file->fd._type = KFT_KFILEPOSIX;
+ memset(file, 0, sizeof(*file));
+ DB(file->fd._type = KFT_KFILEPOSIX);
file->fd.read = kfile_posix_read;
file->fd.write = kfile_posix_write;
file->fd.close = kfile_posix_close;
file->fd.read = kfile_posix_read;
file->fd.write = kfile_posix_write;
file->fd.close = kfile_posix_close;
@@
-94,5
+105,8
@@
FILE *kfile_posix_init(KFilePosix *file, const char *filename, const char *mode)
file->fd.flush = kfile_posix_flush;
file->fp = fopen(filename, mode);
file->fd.flush = kfile_posix_flush;
file->fp = fopen(filename, mode);
+ fseek(file->fp, 0, SEEK_END);
+ file->fd.size = ftell(file->fp);
+ fseek(file->fp, 0, SEEK_SET);
return file->fp;
}
return file->fp;
}