Magellan Linux

Annotation of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/fcntl.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 794 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 niro 532 /*
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     }