2016-09-06 17:08:46 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-06 17:08:46 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "event.h"
|
2016-09-06 17:08:46 +00:00
|
|
|
#include "locking.h"
|
|
|
|
|
2016-09-07 20:29:57 +00:00
|
|
|
#if defined (F_SETLKW)
|
2016-09-06 17:08:46 +00:00
|
|
|
|
2016-10-09 20:41:55 +00:00
|
|
|
int lock_file (FILE *fp)
|
2016-09-06 17:08:46 +00:00
|
|
|
{
|
|
|
|
struct flock lock;
|
|
|
|
|
|
|
|
memset (&lock, 0, sizeof (struct flock));
|
|
|
|
|
|
|
|
lock.l_type = F_WRLCK;
|
|
|
|
|
2016-10-09 20:41:55 +00:00
|
|
|
if (fcntl (fileno (fp), F_SETLKW, &lock)) return -1;
|
2016-09-06 17:08:46 +00:00
|
|
|
|
2016-10-09 20:41:55 +00:00
|
|
|
return 0;
|
2016-09-06 17:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unlock_file (FILE *fp)
|
|
|
|
{
|
|
|
|
struct flock lock;
|
|
|
|
|
|
|
|
memset (&lock, 0, sizeof (struct flock));
|
|
|
|
|
|
|
|
lock.l_type = F_UNLCK;
|
|
|
|
|
|
|
|
fcntl (fileno (fp), F_SETLK, &lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // F_SETLKW
|