492c23c28712dd9a9ab57ae20bdfffee90641f37
[gapil.git] / sources / LockFile.c
1 /*****************************************************************************
2  *
3  * File LockFile.h: 
4  * Function to manipulate lock files.
5  *
6  * Author: S. Piccardi, Dec 2002
7  *
8  * $Id: LockFile.c,v 1.1 2002/12/03 11:06:05 piccardi Exp $
9  *
10  *****************************************************************************/
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>                               /* unix standard functions */
14 #include <fcntl.h>                          /* file control (lock) functions */
15 /*
16  * Function LockFile:
17  *
18  * Create a lockfile of the given pathname.  Fail and exit in case of
19  * error or existence of the same lock file, using unlink do not need
20  * to remove the file.
21  *
22  * Author: Simone Piccardi, Dec. 2002
23  */
24 int LockFile(const char* path_name)
25 {
26     return open(path_name, O_EXCL|O_CREAT);
27 }
28 /*
29  * Function UnlockFile:
30  * Remove a lockfile of the given pathname.
31  *
32  * Author: Simone Piccardi, Dec. 2002
33  */
34 int UnlockFile(const char* path_name) 
35 {
36     return unlink(path_name);
37 }