Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/fcntl.c
Parent Directory | Revision Log
Revision 1297 -
(show annotations)
(download)
Fri May 27 15:12:11 2011 UTC (12 years, 11 months ago) by niro
File MIME type: text/plain
File size: 787 byte(s)
Fri May 27 15:12:11 2011 UTC (12 years, 11 months ago) by niro
File MIME type: text/plain
File size: 787 byte(s)
-updated to klibc-1.5.22 with mntproc definitions patch included
1 | /* |
2 | * Simple test of fcntl |
3 | */ |
4 | |
5 | #include <stdio.h> |
6 | #include <unistd.h> |
7 | #include <fcntl.h> |
8 | #include <stdlib.h> |
9 | #include <string.h> |
10 | |
11 | int main(int argc, char *argv[]) |
12 | { |
13 | int fd = open(argv[0], O_RDONLY); |
14 | struct flock l; |
15 | long flags; |
16 | |
17 | (void)argc; |
18 | |
19 | if (fd < 0) { |
20 | perror("open"); |
21 | exit(1); |
22 | } |
23 | |
24 | /* Get the flags on this FD */ |
25 | |
26 | if ((flags = fcntl(fd, F_GETFL)) == -1) { |
27 | perror("F_GETFL"); |
28 | exit(1); |
29 | } |
30 | |
31 | if (flags != (O_RDONLY | O_LARGEFILE)) |
32 | fprintf(stderr, "flags = %#lx\n", flags); |
33 | |
34 | /* Set a lock on this FD */ |
35 | memset(&l, 0, sizeof l); |
36 | l.l_type = F_RDLCK; |
37 | l.l_whence = SEEK_SET; |
38 | l.l_start = 123; |
39 | l.l_len = 456; |
40 | |
41 | if (fcntl(fd, F_SETLK, &l) == -1) { |
42 | perror("F_SETLK"); |
43 | exit(1); |
44 | } |
45 | |
46 | /* Eventually, fork and try to conflict with this lock... */ |
47 | |
48 | close(fd); |
49 | return 0; |
50 | } |