Skip to content

Commit

Permalink
flush now ensures file data is fully written to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Nov 17, 2024
1 parent f990dcc commit 1828924
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions prof.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ _Static_assert(sizeof(long long) == 8, "incorrect size");
# include <winsock2.h>
# include <ws2tcpip.h>
# include <windows.h>
# include <io.h>
#elif defined(UTRACY_LINUX)
# define _GNU_SOURCE
# include <errno.h>
Expand Down Expand Up @@ -1654,11 +1655,25 @@ char *UTRACY_WINDOWS_CDECL UTRACY_LINUX_CDECL flush(int argc, char **argv) {
return "file stream closed";
}

if(fflush(utracy.fstream) != 0) {
// Then ensure it's written to disk
int fd = _fileno(utracy.fstream);
if(fd == -1) {
LOG_DEBUG_ERROR;
return "failed to flush file stream";
return "failed to get file descriptor";
}

#if defined(UTRACY_WINDOWS)
if(_commit(fd) != 0) {
LOG_DEBUG_ERROR;
return "failed to commit file to disk";
}
#elif defined(UTRACY_LINUX)
if(fsync(fd) != 0) {
LOG_DEBUG_ERROR;
return "failed to sync file to disk";
}
#endif

return "0";
}

Expand Down

0 comments on commit 1828924

Please sign in to comment.