io: file: implement tell() callback for file streams
This commit is contained in:
@@ -274,6 +274,18 @@ static enum b_status stream_seek(
|
|||||||
return b_file_cursor(file, &stream->s_cursor);
|
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)
|
const struct b_path *b_file_path(const struct b_file *file)
|
||||||
{
|
{
|
||||||
return file->path;
|
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_read = stream_read;
|
||||||
stream->s_write = stream_write;
|
stream->s_write = stream_write;
|
||||||
stream->s_seek = stream_seek;
|
stream->s_seek = stream_seek;
|
||||||
|
stream->s_tell = stream_tell;
|
||||||
|
|
||||||
*out = stream;
|
*out = stream;
|
||||||
|
|
||||||
@@ -387,11 +400,11 @@ enum b_status b_file_seek(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int err = lseek(file->fd, offset, whence);
|
int err = lseek(file->fd, offset, whence);
|
||||||
if (err == 0) {
|
if (err == (off_t)-1) {
|
||||||
return B_SUCCESS;
|
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)
|
enum b_status b_file_swap_shadow(struct b_file *main_file, struct b_file *shadow_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user