Commit 8fac9398 authored by Paul Sokolovsky's avatar Paul Sokolovsky

unix/file: Implement MP_STREAM_FLUSH ioctl.

parent 6ead9f6f
...@@ -105,18 +105,26 @@ STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in ...@@ -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) { 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); mp_obj_fdfile_t *o = MP_OBJ_TO_PTR(o_in);
if (request == MP_STREAM_SEEK) { switch (request) {
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg; case MP_STREAM_SEEK: {
off_t off = lseek(o->fd, s->offset, s->whence); struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
if (off == (off_t)-1) { off_t off = lseek(o->fd, s->offset, s->whence);
*errcode = errno; if (off == (off_t)-1) {
return MP_STREAM_ERROR; *errcode = errno;
return MP_STREAM_ERROR;
}
s->offset = off;
return 0;
} }
s->offset = off; case MP_STREAM_FLUSH:
return 0; if (fsync(o->fd) < 0) {
} else { *errcode = errno;
*errcode = EINVAL; return MP_STREAM_ERROR;
return MP_STREAM_ERROR; }
return 0;
default:
*errcode = EINVAL;
return MP_STREAM_ERROR;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment