-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewritten file I / O for portable C API
Besides portability, it also provides more guarantees (for example, the write system call does not guarantee that the entire buffer will be written, unlike fwrite, which tries to write the remainder).
- Loading branch information
1 parent
bea4aaf
commit 22a348d
Showing
5 changed files
with
63 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#ifndef _WIN32 | ||
|
||
#include <unistd.h> | ||
|
||
#else | ||
|
||
#include <io.h> | ||
#include <Windows.h> | ||
|
||
inline int fsync(int fd) { | ||
HANDLE h = (HANDLE)_get_osfhandle(fd); | ||
if (h == INVALID_HANDLE_VALUE) { | ||
return -1; | ||
} | ||
if (!FlushFileBuffers(h)) { | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
inline int fdatasync(int fd) { | ||
return fsync(fd); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters