unix/file: Implement MP_STREAM_FLUSH ioctl.
This commit is contained in:
parent
6ead9f6f3d
commit
8fac939889
12
unix/file.c
12
unix/file.c
|
@ -105,7 +105,8 @@ 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) {
|
||||
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) {
|
||||
|
@ -114,7 +115,14 @@ STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, i
|
|||
}
|
||||
s->offset = off;
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
case MP_STREAM_FLUSH:
|
||||
if (fsync(o->fd) < 0) {
|
||||
*errcode = errno;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
*errcode = EINVAL;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue