diff --git a/io/sys/darwin/file.c b/io/sys/darwin/file.c index ddfe6d7..d0b7e39 100644 --- a/io/sys/darwin/file.c +++ b/io/sys/darwin/file.c @@ -274,6 +274,18 @@ static enum b_status stream_seek( return b_file_cursor(file, &stream->s_cursor); } +static enum b_status stream_tell(const struct b_stream *stream, size_t *pos) +{ + const struct b_file *file = stream->s_ptr; + off_t v = lseek(file->fd, 0, SEEK_CUR); + if (v == (off_t)-1) { + return b_status_from_errno(errno, B_ERR_IO_FAILURE); + } + + *pos = v; + return B_SUCCESS; +} + const struct b_path *b_file_path(const struct b_file *file) { return file->path; @@ -306,6 +318,7 @@ enum b_status b_file_open_stream(struct b_file *file, struct b_stream **out) stream->s_read = stream_read; stream->s_write = stream_write; stream->s_seek = stream_seek; + stream->s_tell = stream_tell; *out = stream; @@ -387,11 +400,11 @@ enum b_status b_file_seek( } int err = lseek(file->fd, offset, whence); - if (err == 0) { - return B_SUCCESS; + if (err == (off_t)-1) { + return b_status_from_errno(errno, B_ERR_IO_FAILURE); } - return b_status_from_errno(errno, B_ERR_IO_FAILURE); + return B_SUCCESS; } enum b_status b_file_swap_shadow(struct b_file *main_file, struct b_file *shadow_file)