X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FLockFile.c;fp=sources%2FLockFile.c;h=5bdc4a36cc30634aabee393d3bfbda8d67951784;hp=0000000000000000000000000000000000000000;hb=b1ead1b930038e4f7cd6ee7f737d7ee4699a068c;hpb=d12bc3e1e4b3ee762036d1c226c3b2ba1a720fb9 diff --git a/sources/LockFile.c b/sources/LockFile.c new file mode 100644 index 0000000..5bdc4a3 --- /dev/null +++ b/sources/LockFile.c @@ -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 +#include +#include /* unix standard functions */ +#include /* 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); +}