Skip to content

Commit 8fac939

Browse files
committed
unix/file: Implement MP_STREAM_FLUSH ioctl.
1 parent 6ead9f6 commit 8fac939

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

unix/file.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,26 @@ STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in
105105

106106
STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) {
107107
mp_obj_fdfile_t *o = MP_OBJ_TO_PTR(o_in);
108-
if (request == MP_STREAM_SEEK) {
109-
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
110-
off_t off = lseek(o->fd, s->offset, s->whence);
111-
if (off == (off_t)-1) {
112-
*errcode = errno;
113-
return MP_STREAM_ERROR;
108+
switch (request) {
109+
case MP_STREAM_SEEK: {
110+
struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg;
111+
off_t off = lseek(o->fd, s->offset, s->whence);
112+
if (off == (off_t)-1) {
113+
*errcode = errno;
114+
return MP_STREAM_ERROR;
115+
}
116+
s->offset = off;
117+
return 0;
114118
}
115-
s->offset = off;
116-
return 0;
117-
} else {
118-
*errcode = EINVAL;
119-
return MP_STREAM_ERROR;
119+
case MP_STREAM_FLUSH:
120+
if (fsync(o->fd) < 0) {
121+
*errcode = errno;
122+
return MP_STREAM_ERROR;
123+
}
124+
return 0;
125+
default:
126+
*errcode = EINVAL;
127+
return MP_STREAM_ERROR;
120128
}
121129
}
122130

0 commit comments

Comments
 (0)