Skip to content

Commit

Permalink
- there is no fsync for MinGW/Windows, use FlushFileBuffers
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17039 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Sep 3, 2013
1 parent 010089b commit 024e3ea
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Compiler/runtime/socketimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,46 @@
#if defined(__MINGW32__) || defined(_MSC_VER)
#include <winsock2.h>
#include <ws2tcpip.h>

#include <unistd.h>
#include <errno.h>
#include <io.h>

int
fsync (int fd)
{
HANDLE h = (HANDLE) _get_osfhandle (fd);
DWORD err;

if (h == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return -1;
}

if (!FlushFileBuffers (h))
{
/* Translate some Windows errors into rough approximations of Unix
* errors. MSDN is useless as usual - in this case it doesn't
* document the full range of errors.
*/
err = GetLastError ();
switch (err)
{
/* eg. Trying to fsync a tty. */
case ERROR_INVALID_HANDLE:
errno = EINVAL;
break;

default:
errno = EIO;
}
return -1;
}

return 0;
}

#else
#include <sys/socket.h>
#include <netinet/in.h>
Expand Down

0 comments on commit 024e3ea

Please sign in to comment.