1 #define _FILE_OFFSET_BITS 64
17 static int test_shmd(int fd, int access, int deny)
26 if ((ret = fcntl(fd, F_SHARE, &sh)) == 0)
27 fcntl(fd, F_UNSHARE, &sh);
32 static int get_shmd(int fd, fshare_t *sh_rv)
39 /* Check deny modes */
40 if (test_shmd(fd, F_RDACC, F_NODNY) != 0) {
41 perror("test_shmd(fd, F_RDACC, F_NODNY)");
42 sh_rv->f_deny |= F_RDDNY;
44 if (test_shmd(fd, F_WRACC, F_NODNY) != 0) {
45 perror("test_shmd(fd, F_WRACC, F_NODNY)");
46 sh_rv->f_deny |= F_WRDNY;
49 /* Check access modes */
50 if (test_shmd(fd, F_RWACC, F_RDDNY) != 0) {
51 perror("test_shmd(fd, 0, F_RDDNY)");
52 sh_rv->f_access |= F_RDACC;
54 if (test_shmd(fd, F_RWACC, F_WRDNY) != 0) {
55 perror("test_shmd(fd, 0, F_WRDNY)");
56 sh_rv->f_access |= F_WRACC;
63 int main(int argc, char *argv[])
72 printf("usage: %s FILE\n", argv[0]);
76 if ((pid = fork()) == -1) {
87 printf("Press <RETURN> to get sharemodee: ");
92 printf("Sharemodes:\n"
97 (share.f_access & F_RDACC) ? "yes" : "no",
98 (share.f_access & F_WRACC) ? "yes" : "no",
99 (share.f_deny & F_RDDNY) ? "yes" : "no",
100 (share.f_deny & F_WRDNY) ? "yes" : "no"
104 printf("Child: Press <RETURN> to set sharemode: ");
108 if ((fd2 = open(argv[1], O_RDWR)) == -1) {
113 if (flock(fd2, LOCK_MAND | LOCK_READ | LOCK_NB) != 0) {
118 printf("Child: got lock\n");
121 printf("Child: Press <RETURN> to exit");
126 if ((fd = open(argv[1], O_RDWR)) == -1) {
131 printf("Parent: Press <RETURN> to set sharemode: ");
135 share.f_access = F_RDACC;
136 share.f_deny = F_WRDNY;
139 if (fcntl(fd, F_SHARE, &share) == -1) {
145 if (flock(fd, LOCK_MAND | LOCK_READ | LOCK_NB) != 0) {
151 printf("Parent: got lock\n");
154 if (waitpid(pid, NULL, 0) != pid) {