VirtualBox

Ticket #16467: checkDeleteLocked.c

File checkDeleteLocked.c, 1.0 KB (added by egooo, 8 years ago)
Line 
1
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <fcntl.h>
5#include <unistd.h>
6#include <stdio.h>
7
8int main(int argc, char *argv[])
9{
10 unlink("test.lock");
11
12 printf("Open file. Result: ");
13 int fd = open("test.lock", O_WRONLY|O_CREAT, 0666);
14 printf("%i\n", fd);
15
16 printf("Locking file. Result: ");
17 struct flock lock_data;
18 lock_data.l_type = F_WRLCK;
19 lock_data.l_whence = SEEK_SET;
20 lock_data.l_start = 0;
21 lock_data.l_len = 1;
22 int result = fcntl(fd, F_SETLK, &lock_data);
23 printf("%i\n", result);
24
25 printf("Unlink file. Result: ");
26 // following call fails, when executing in a shared folder:
27 result = unlink("test.lock");
28 printf("%i\n", result);
29
30 if (result == -1)
31 {
32 printf("Test failed\n");
33 close(fd);
34 unlink("test.lock");
35 return -1;
36 }
37
38 printf("Close file. Result: ");
39 result = close(fd);
40 printf("%i\n", result);
41
42 printf("Test passed.\n");
43
44 return 0;
45}

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy