Portability: Use fcntl instead of flock

- POSIX file locking mechanism, eliminating platform-specific code.
This commit is contained in:
Paul Beckingham 2015-05-02 11:47:39 -04:00
parent 71fef9f22f
commit c346cf9395
6 changed files with 25 additions and 76 deletions

View file

@ -42,7 +42,6 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@ -228,40 +227,6 @@ const std::string uuid ()
}
#endif
////////////////////////////////////////////////////////////////////////////////
// On Solaris no flock function exists.
#ifdef SOLARIS
int flock (int fd, int operation)
{
struct flock fl;
switch (operation & ~LOCK_NB)
{
case LOCK_SH:
fl.l_type = F_RDLCK;
break;
case LOCK_EX:
fl.l_type = F_WRLCK;
break;
case LOCK_UN:
fl.l_type = F_UNLCK;
break;
default:
errno = EINVAL;
return -1;
}
fl.l_whence = 0;
fl.l_start = 0;
fl.l_len = 0;
return fcntl (fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &fl);
}
#endif
////////////////////////////////////////////////////////////////////////////////
// Run a binary with args, capturing output.
int execute (