Uses an explicit fsync() in Windows.

This should allow a more precise error detection.
This commit is contained in:
Andrea Mazzoleni 2014-09-24 22:25:35 +02:00
parent e6019351d4
commit 0433033c12
2 changed files with 33 additions and 2 deletions

View file

@ -567,7 +567,10 @@ static void windows_errno(DWORD error)
{
switch (error) {
case ERROR_INVALID_HANDLE :
errno = EBADF;
/* we check for a bad handle calling _get_osfhandle() */
/* and in such case we return EBADF */
/* Other cases are here identified with EINVAL */
errno = EINVAL;
break;
case ERROR_FILE_NOT_FOUND :
case ERROR_PATH_NOT_FOUND : /* in GetFileAttributeW() if internal path not found */
@ -791,6 +794,29 @@ int windows_ftruncate(int fd, off64_t off)
return 0;
}
int windows_fsync(int fd)
{
HANDLE h;
if (fd == -1) {
errno = EBADF;
return -1;
}
h = (HANDLE)_get_osfhandle(fd);
if (h == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;
}
if (!FlushFileBuffers(h)) {
windows_errno(GetLastError());
return -1;
}
return 0;
}
int windows_futimens(int fd, struct windows_timespec tv[2])
{
HANDLE h;

View file

@ -54,7 +54,7 @@
#define ftruncate windows_ftruncate
#define HAVE_FSYNC 1
#undef fsync
#define fsync _commit
#define fsync windows_fsync
#undef rename
#define rename windows_rename
#undef remove
@ -191,6 +191,11 @@ int lstat_ex(const char* file, struct windows_stat* st);
*/
int windows_ftruncate(int fd, off64_t off);
/**
* Like the C fsync().
*/
int windows_fsync(int fd);
/**
* Like the C futimes().
*/