Rimetto quello che avevo levato
[gapil.git] / sources / LockFile.c
diff --git a/sources/LockFile.c b/sources/LockFile.c
new file mode 100644 (file)
index 0000000..5bdc4a3
--- /dev/null
@@ -0,0 +1,55 @@
+/* LockFile.c
+ * 
+ * Copyright (C) 2002 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/*****************************************************************************
+ *
+ * File LockFile.h: 
+ * Function to manipulate lock files.
+ *
+ * Author: S. Piccardi, Dec 2002
+ *
+ * $Id: LockFile.c,v 1.4 2003/05/02 09:55:14 piccardi Exp $
+ *
+ *****************************************************************************/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>                               /* unix standard functions */
+#include <fcntl.h>                          /* file control (lock) functions */
+/*
+ * Function LockFile:
+ *
+ * Create a lockfile of the given pathname.  Fail and exit in case of
+ * error or existence of the same lock file, using unlink do not need
+ * to remove the file.
+ *
+ * Author: Simone Piccardi, Dec. 2002
+ */
+int LockFile(const char* path_name)
+{
+    return open(path_name, O_EXCL|O_CREAT);
+}
+/*
+ * Function UnlockFile:
+ * Remove a lockfile of the given pathname.
+ *
+ * Author: Simone Piccardi, Dec. 2002
+ */
+int UnlockFile(const char* path_name) 
+{
+    return unlink(path_name);
+}