00001 /*! \file flock.c 00002 This file implements file locking facility. 00003 */ 00004 00005 #include "flock.h" 00006 00007 /*! \brief Lock a file. 00008 \author Denis BEURIVE 00009 \param fd File descriptor that identifies the file to lock. 00010 \return If the lock succed, the function returns 0. Otherwise the function returns 1. 00011 */ 00012 00013 int lock_file(int fd) 00014 { 00015 int cr; 00016 00017 cr = flock (fd, LOCK_EX); 00018 if (cr == -1) { return 1; } 00019 return 0; 00020 } 00021 00022 /*! \brief Unlock a file. 00023 \author Denis BEURIVE 00024 \param fd File descriptor that identifies the file to unlock. 00025 \return If the operation succed, the function returns 0. Otherwise the function returns 1. 00026 */ 00027 00028 int unlock_file(int fd) 00029 { 00030 int cr; 00031 00032 cr = flock (fd, LOCK_UN); 00033 if (cr == -1) { return 1; } 00034 return 0; 00035 } 00036 00037 00038 00039 00040