chiark / gitweb /
[PATCH] update klibc to version 0.181
[elogind.git] / klibc / klibc / tests / fcntl.c
1 /*
2  * Simple test of fcntl
3  */
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <errno.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 int main(int argc, char *argv[])
13 {
14   int fd = open(argv[0], O_RDONLY);
15   struct flock l;
16   long flags;
17
18   (void)argc;
19
20   if ( fd < 0 ) {
21     perror("open");
22     exit(1);
23   }
24
25   /* Get the flags on this FD */
26
27   if ( (flags = fcntl(fd, F_GETFL)) == -1 ) {
28     perror("F_GETFL");
29     exit(1);
30   }
31
32   if ( flags != (O_RDONLY|O_LARGEFILE) )
33     fprintf(stderr, "flags = %#lx\n", flags);
34
35   /* Set a lock on this FD */
36   memset(&l, 0, sizeof l);
37   l.l_type   = F_RDLCK;
38   l.l_whence = SEEK_SET;
39   l.l_start  = 123;
40   l.l_len    = 456;
41
42   if ( fcntl(fd, F_SETLK, &l) == -1 ) {
43     perror("F_SETLK");
44     exit(1);
45   }
46
47   /* Eventually, fork and try to conflict with this lock... */
48
49   return 0;
50 }
51
52   
53