Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extmod/vfs_fat_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ static mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg,
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)(uintptr_t)arg;

switch (s->whence) {
case 0: // SEEK_SET
case MP_SEEK_SET:
f_lseek(&self->fp, s->offset);
break;

case 1: // SEEK_CUR
case MP_SEEK_CUR:
f_lseek(&self->fp, f_tell(&self->fp) + s->offset);
break;

case 2: // SEEK_END
case MP_SEEK_END:
f_lseek(&self->fp, f_size(&self->fp) + s->offset);
break;
}
Expand Down
6 changes: 3 additions & 3 deletions extmod/vfs_rom_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ static mp_uint_t vfs_rom_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t
switch (request) {
case MP_STREAM_SEEK: {
struct mp_stream_seek_t *s = (struct mp_stream_seek_t *)arg;
if (s->whence == 0) { // SEEK_SET
if (s->whence == MP_SEEK_SET) {
self->file_offset = (size_t)s->offset;
} else if (s->whence == 1) { // SEEK_CUR
} else if (s->whence == MP_SEEK_CUR) {
self->file_offset += s->offset;
} else { // SEEK_END
} else { // MP_SEEK_END
self->file_offset = self->file_size + s->offset;
}
if (self->file_offset > self->file_size) {
Expand Down
3 changes: 0 additions & 3 deletions ports/pic16bit/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

// XC16 compiler doesn't seem to have unistd.h file

#define SEEK_SET 0
#define SEEK_CUR 1

typedef int ssize_t;

#endif // MICROPY_INCLUDED_PIC16BIT_UNISTD_H
3 changes: 0 additions & 3 deletions ports/powerpc/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

// powerpc gcc compiler doesn't seem to have unistd.h file

#define SEEK_SET 0
#define SEEK_CUR 1

typedef int ssize_t;

#endif // MICROPY_INCLUDED_POWERPC_UNISTD_H
6 changes: 3 additions & 3 deletions py/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,13 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream___exit___obj, 4, 4, mp_stream___ex
static mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) {
// TODO: Could be uint64
mp_off_t offset = mp_obj_get_int(args[1]);
int whence = SEEK_SET;
int whence = MP_SEEK_SET;
if (n_args == 3) {
whence = mp_obj_get_int(args[2]);
}

// In POSIX, it's error to seek before end of stream, we enforce it here.
if (whence == SEEK_SET && offset < 0) {
if (whence == MP_SEEK_SET && offset < 0) {
mp_raise_OSError(MP_EINVAL);
}

Expand All @@ -484,7 +484,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek);

static mp_obj_t stream_tell(mp_obj_t self) {
mp_obj_t offset = MP_OBJ_NEW_SMALL_INT(0);
mp_obj_t whence = MP_OBJ_NEW_SMALL_INT(SEEK_CUR);
mp_obj_t whence = MP_OBJ_NEW_SMALL_INT(MP_SEEK_CUR);
const mp_obj_t args[3] = {self, offset, whence};
return stream_seek(3, args);
}
Expand Down
Loading