added demo of signal/uid handling feature
[tridge/junkcode.git] / fcntl.c
1 #define _FILE_OFFSET_BITS 64
2 #include <stdio.h>
3 #include <fcntl.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6
7 int main(void) 
8 {
9         struct flock lock;
10         int status;
11         int fd = open("conftest.dat", O_CREAT|O_RDWR, 0600);
12         lock.l_type = F_WRLCK;
13         lock.l_whence = SEEK_SET;
14         lock.l_start = 0;
15         lock.l_len = 1;
16         lock.l_pid = 0;
17         
18         fcntl(fd,F_SETLK,&lock);
19         if (fork() == 0) {
20                 lock.l_start = 1;               
21                 exit(fcntl(fd,F_SETLK,&lock) != 0);
22         }
23         wait(&status);
24         unlink("conftest.dat");
25         if (WEXITSTATUS(status)) {
26                 perror("lock");
27                 exit(1);
28         } else {
29                 printf("OK\n");
30         }
31         exit(WEXITSTATUS(status));
32 }