Ticket #3141: flock-bug.c

File flock-bug.c, 560 bytes (added by bhaible, 15 years ago)

test case

Line 
1#include <fcntl.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <unistd.h>
5#include <errno.h>
6
7#include <sys/file.h>
8
9int
10main (int argc, char *argv[])
11{
12 int fd;
13 const char *file = "test-flock.txt";
14 int ret;
15
16 /* Open a non-empty file for testing. */
17 fd = open (file, O_RDWR | O_CREAT | O_TRUNC, 0644);
18 if (!(fd >= 0))
19 exit (1);
20 if (!(write (fd, "hello", 5) == 5))
21 exit (2);
22
23 /* Some impossible operation codes which should never be accepted. */
24 ret = flock (fd, LOCK_SH | LOCK_EX);
25 printf ("%d %d\n", ret, errno);
26
27 return 0;
28}