00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <eyedbconfig.h>
00025
00026 #include <sys/types.h>
00027 #include <sys/ipc.h>
00028 #include <sys/sem.h>
00029 #include <sys/stat.h>
00030 #include <unistd.h>
00031 #include <fcntl.h>
00032 #include <eyedblib/filelib.h>
00033
00034 #ifdef HAVE_FLOCK_T
00035 #define FLOCK_DECL flock_t
00036 #else
00037 #define FLOCK_DECL struct flock
00038 #endif
00039
00040 int ut_file_lock(int fd, ut_Lock excl, ut_Block block)
00041 {
00042 FLOCK_DECL flk = {0};
00043
00044 flk.l_type = (excl == ut_LOCKX ? F_WRLCK : F_RDLCK);
00045
00046 return fcntl(fd, (block == ut_BLOCK ? F_SETLKW : F_SETLK), &flk);
00047 }
00048
00049 int ut_file_unlock(int fd)
00050 {
00051 FLOCK_DECL flk = {0};
00052
00053 flk.l_type = F_UNLCK;
00054
00055 return fcntl(fd, F_SETLK, &flk);
00056 }