1 #include "ruby/internal/config.h"
9 flock(int fd
, int operation
)
14 #elif defined HAVE_FCNTL && defined HAVE_FCNTL_H
16 /* These are the flock() constants. Since this systems doesn't have
17 flock(), the values of the constants are probably not available.
37 flock(int fd
, int operation
)
41 switch (operation
& ~LOCK_NB
) {
43 lock
.l_type
= F_RDLCK
;
46 lock
.l_type
= F_WRLCK
;
49 lock
.l_type
= F_UNLCK
;
55 lock
.l_whence
= SEEK_SET
;
56 lock
.l_start
= lock
.l_len
= 0L;
58 return fcntl(fd
, (operation
& LOCK_NB
) ? F_SETLK
: F_SETLKW
, &lock
);
61 #elif defined(HAVE_LOCKF)
66 /* Emulate flock() with lockf() or fcntl(). This is just to increase
67 portability of scripts. The calls might not be completely
68 interchangeable. What's really needed is a good file
73 # define F_ULOCK 0 /* Unlock a previously locked region */
76 # define F_LOCK 1 /* Lock a region for exclusive use */
79 # define F_TLOCK 2 /* Test and lock a region for exclusive use */
82 # define F_TEST 3 /* Test a region for other processes locks */
85 /* These are the flock() constants. Since this systems doesn't have
86 flock(), the values of the constants are probably not available.
102 flock(int fd
, int operation
)
106 /* LOCK_SH - get a shared lock */
110 /* LOCK_EX - get an exclusive lock */
112 return lockf (fd
, F_LOCK
, 0);
114 /* LOCK_SH|LOCK_NB - get a non-blocking shared lock */
115 case LOCK_SH
|LOCK_NB
:
118 /* LOCK_EX|LOCK_NB - get a non-blocking exclusive lock */
119 case LOCK_EX
|LOCK_NB
:
120 return lockf (fd
, F_TLOCK
, 0);
122 /* LOCK_UN - unlock */
124 return lockf (fd
, F_ULOCK
, 0);
126 /* Default - can't decipher operation */
134 flock(int fd
, int operation
)