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 781dd8a commit ed6eb27Copy full SHA for ed6eb27
file-locking/fcntl-locking.c
@@ -109,6 +109,14 @@ lock(int fd, struct flock *fl)
109
err(1, "fcntl");
110
}
111
112
+static void
113
+lockr(int fd, struct flock *fl)
114
+{
115
+ fl->l_type = F_RDLCK;
116
+ if (fcntl(fd, F_SETLKW, fl) == -1)
117
+ err(1, "fcntl");
118
+}
119
+
120
static void
121
unlock(int fd, struct flock *fl)
122
{
@@ -141,7 +149,7 @@ dump_file(char *filename, bool locking)
141
149
while (1) {
142
150
/* Lock only the 2nd half of the file. */
143
151
if (locking)
144
- lock(fd, &fl);
152
+ lockr(fd, &fl);
145
153
146
154
(void) lseek(fd, SEEK_SET, 0);
147
155
memset(buf, 0, sizeof (buf));
0 commit comments