Add Win32 ccache locking from Christophe Gisquet patch http://lists.samba.org/archive/ccache/2006q3/000242.html

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10992 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2008-12-20 17:20:25 +00:00
commit 5e50d29bb3
2 changed files with 17 additions and 5 deletions

View file

@ -5,6 +5,7 @@
#ifndef _WIN32
#include "config.h"
#else
#include <sys/locking.h>
#define PACKAGE_NAME "ccache-swig.exe"
#endif

View file

@ -617,9 +617,24 @@ char *dirname(char *s)
return s;
}
/*
http://www.ecst.csuchico.edu/~beej/guide/ipc/flock.html
http://cvs.php.net/viewvc.cgi/php-src/win32/flock.c?revision=1.2&view=markup
Should return 0 for success, >0 otherwise
*/
int lock_fd(int fd)
{
#ifndef _WIN32
#ifdef _WIN32
# if 1
return _locking(fd, _LK_NBLCK, 1);
# else
HANDLE fl = (HANDLE)_get_osfhandle(fd);
OVERLAPPED o;
memset(&o, 0, sizeof(o));
return (LockFileEx(fl, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &o))
? 0 : GetLastError();
# endif
#else
struct flock fl;
int ret;
@ -635,10 +650,6 @@ int lock_fd(int fd)
ret = fcntl(fd, F_SETLKW, &fl);
} while (ret == -1 && errno == EINTR);
return ret;
#else
(void)fd;
#warning "missing implementation???"
return 0;
#endif
}