We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 621649e commit b00b848Copy full SHA for b00b848
file-locking/fcntl-locking.c
@@ -135,11 +135,8 @@ dump_file(char *filename, bool locking)
135
136
while (1) {
137
/* Lock only the 2nd half of the file. */
138
- if (locking) {
139
- fl.l_type = F_RDLCK;
140
- if (fcntl(fd, F_SETLKW, &fl) == -1)
141
- err(1, "fcntl");
142
- }
+ if (locking)
+ lock(fd, &fl);
143
144
(void) lseek(fd, SEEK_SET, 0);
145
memset(buf, 0, sizeof (buf));
@@ -148,11 +145,9 @@ dump_file(char *filename, bool locking)
148
(void) printf(" %zd\n", n);
149
146
150
147
sleep(1);
151
152
- fl.l_type = F_UNLCK;
153
154
155
+
+ unlock(fd, &fl);
156
157
/* Let the writers do their job. */
158
0 commit comments