fs: fix tracking of initial position with O_APPEND (*)

(*) O_APPEND is *not* functional yet, this is just a hack for write-only
streams. Currently O_APPEND does not reposition the cursor at the end of
the file before every write.
This commit is contained in:
Lephe 2022-03-19 19:26:23 +00:00
parent 48325fc54d
commit f300338a57
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -109,8 +109,11 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
/* If O_APPEND is set, move to the end of the file */ /* If O_APPEND is set, move to the end of the file */
// TODO: O_APPEND should move the cursor before *each* write // TODO: O_APPEND should move the cursor before *each* write
if((flags & O_APPEND)) int pos = 0;
BFile_Seek(fugue_fd, BFile_Size(fugue_fd)); if((flags & O_APPEND)) {
pos = BFile_Size(fugue_fd);
BFile_Seek(fugue_fd, pos);
}
/* Return the now-open file descriptor */ /* Return the now-open file descriptor */
fugue_fd_t *data = malloc(sizeof *data); fugue_fd_t *data = malloc(sizeof *data);
@ -119,7 +122,7 @@ int fugue_open(char const *path, int flags, GUNUSED mode_t mode)
goto end; goto end;
} }
data->fd = fugue_fd; data->fd = fugue_fd;
data->pos = 0; data->pos = pos;
fs_descriptor_t fd_data = { fs_descriptor_t fd_data = {
.type = &fugue_descriptor_type, .type = &fugue_descriptor_type,