DEFINITIONS
This source file includes following functions.
- flock
- flock
- flock
1 #include "config.h"
2
3 #if defined HAVE_FCNTL && defined HAVE_FCNTL_H
4
5
6
7
8 # ifndef LOCK_SH
9 # define LOCK_SH 1
10 # endif
11 # ifndef LOCK_EX
12 # define LOCK_EX 2
13 # endif
14 # ifndef LOCK_NB
15 # define LOCK_NB 4
16 # endif
17 # ifndef LOCK_UN
18 # define LOCK_UN 8
19 # endif
20
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <errno.h>
24
25 int
26 flock(fd, operation)
27 int fd;
28 int operation;
29 {
30 struct flock lock;
31
32 switch (operation & ~LOCK_NB) {
33 case LOCK_SH:
34 lock.l_type = F_RDLCK;
35 break;
36 case LOCK_EX:
37 lock.l_type = F_WRLCK;
38 break;
39 case LOCK_UN:
40 lock.l_type = F_UNLCK;
41 break;
42 default:
43 errno = EINVAL;
44 return -1;
45 }
46 lock.l_whence = SEEK_SET;
47 lock.l_start = lock.l_len = 0L;
48
49 return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock);
50 }
51
52 #elif defined(HAVE_LOCKF)
53
54 #include <unistd.h>
55 #include <errno.h>
56
57
58
59
60
61
62
63 # ifndef F_ULOCK
64 # define F_ULOCK 0
65 # endif
66 # ifndef F_LOCK
67 # define F_LOCK 1
68 # endif
69 # ifndef F_TLOCK
70 # define F_TLOCK 2
71 # endif
72 # ifndef F_TEST
73 # define F_TEST 3
74 # endif
75
76
77
78
79 # ifndef LOCK_SH
80 # define LOCK_SH 1
81 # endif
82 # ifndef LOCK_EX
83 # define LOCK_EX 2
84 # endif
85 # ifndef LOCK_NB
86 # define LOCK_NB 4
87 # endif
88 # ifndef LOCK_UN
89 # define LOCK_UN 8
90 # endif
91
92 int
93 flock(fd, operation)
94 int fd;
95 int operation;
96 {
97 switch (operation) {
98
99
100 case LOCK_SH:
101 rb_notimplement();
102 return -1;
103
104 case LOCK_EX:
105 return lockf (fd, F_LOCK, 0);
106
107
108 case LOCK_SH|LOCK_NB:
109 rb_notimplement();
110 return -1;
111
112 case LOCK_EX|LOCK_NB:
113 return lockf (fd, F_TLOCK, 0);
114
115
116 case LOCK_UN:
117 return lockf (fd, F_ULOCK, 0);
118
119
120 default:
121 errno = EINVAL;
122 return -1;
123 }
124 }
125 #elif !defined NT
126 int
127 flock(fd, operation)
128 int fd;
129 int operation;
130 {
131 rb_notimplement();
132 return -1;
133 }
134 #endif