1 #include "ruby/config.h"
4 #elif defined HAVE_FCNTL && defined HAVE_FCNTL_H
6 /* These are the flock() constants. Since this sytems doesn't have
7 flock(), the values of the constants are probably not available.
27 flock(int fd
, int operation
)
31 switch (operation
& ~LOCK_NB
) {
33 lock
.l_type
= F_RDLCK
;
36 lock
.l_type
= F_WRLCK
;
39 lock
.l_type
= F_UNLCK
;
45 lock
.l_whence
= SEEK_SET
;
46 lock
.l_start
= lock
.l_len
= 0L;
48 return fcntl(fd
, (operation
& LOCK_NB
) ? F_SETLK
: F_SETLKW
, &lock
);
51 #elif defined(HAVE_LOCKF)
56 /* Emulate flock() with lockf() or fcntl(). This is just to increase
57 portability of scripts. The calls might not be completely
58 interchangeable. What's really needed is a good file
63 # define F_ULOCK 0 /* Unlock a previously locked region */
66 # define F_LOCK 1 /* Lock a region for exclusive use */
69 # define F_TLOCK 2 /* Test and lock a region for exclusive use */
72 # define F_TEST 3 /* Test a region for other processes locks */
75 /* These are the flock() constants. Since this sytems doesn't have
76 flock(), the values of the constants are probably not available.
92 flock(int fd
, int operation
)
96 /* LOCK_SH - get a shared lock */
100 /* LOCK_EX - get an exclusive lock */
102 return lockf (fd
, F_LOCK
, 0);
104 /* LOCK_SH|LOCK_NB - get a non-blocking shared lock */
105 case LOCK_SH
|LOCK_NB
:
108 /* LOCK_EX|LOCK_NB - get a non-blocking exclusive lock */
109 case LOCK_EX
|LOCK_NB
:
110 return lockf (fd
, F_TLOCK
, 0);
112 /* LOCK_UN - unlock */
114 return lockf (fd
, F_ULOCK
, 0);
116 /* Default - can't decipher operation */
124 flock(int fd
, int operation
)