summaryrefslogtreecommitdiff
path: root/unix/file.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-07-27 00:24:09 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-07-27 00:24:09 +0300
commit8fac939889c6f2db36cc8f1290605812305cea59 (patch)
treeb7e5c9f3b71f538616b85ccd4c43b2995d6847f2 /unix/file.c
parent6ead9f6f3d6a9a5e9b41891851868c885265dbf3 (diff)
unix/file: Implement MP_STREAM_FLUSH ioctl.
Diffstat (limited to 'unix/file.c')
-rw-r--r--unix/file.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/unix/file.c b/unix/file.c
index a7620e079..4d3a9f362 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -105,18 +105,26 @@ STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
mp_obj_fdfile_t *o = MP_OBJ_TO_PTR(o_in);
- if (request == MP_STREAM_SEEK) {
- struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
- off_t off = lseek(o->fd, s->offset, s->whence);
- if (off == (off_t)-1) {
- *errcode = errno;
- return MP_STREAM_ERROR;
+ switch (request) {
+ case MP_STREAM_SEEK: {
+ struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
+ off_t off = lseek(o->fd, s->offset, s->whence);
+ if (off == (off_t)-1) {
+ *errcode = errno;
+ return MP_STREAM_ERROR;
+ }
+ s->offset = off;
+ return 0;
}
- s->offset = off;
- return 0;
- } else {
- *errcode = EINVAL;
- return MP_STREAM_ERROR;
+ case MP_STREAM_FLUSH:
+ if (fsync(o->fd) < 0) {
+ *errcode = errno;
+ return MP_STREAM_ERROR;
+ }
+ return 0;
+ default:
+ *errcode = EINVAL;
+ return MP_STREAM_ERROR;
}
}