s4:dsdb/local_password: use DSDB_SECRET_ATTRIBUTES
[Samba/gebeck_regimport.git] / tests / fcntl_lock64.c
blobe5ecd88fd0444af79108cc335c382d5f27bac323
1 /* test whether 64 bit fcntl locking really works on this system */
3 #if defined(HAVE_UNISTD_H)
4 #include <unistd.h>
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
11 #ifdef HAVE_FCNTL_H
12 #include <fcntl.h>
13 #endif
15 #ifdef HAVE_SYS_FCNTL_H
16 #include <sys/fcntl.h>
17 #endif
19 #include <errno.h>
21 static int sys_waitpid(pid_t pid,int *status,int options)
23 #ifdef HAVE_WAITPID
24 return waitpid(pid,status,options);
25 #else /* USE_WAITPID */
26 return wait4(pid, status, options, NULL);
27 #endif /* USE_WAITPID */
30 #define DATA "conftest.fcntl64"
32 /* lock a byte range in a open file */
33 int main(int argc, char *argv[])
35 struct flock64 lock;
36 int fd, ret, status=1;
37 pid_t pid;
39 if (!(pid=fork())) {
40 sleep(2);
41 fd = open64(DATA, O_RDONLY);
43 if (fd == -1) exit(1);
45 lock.l_type = F_WRLCK;
46 lock.l_whence = SEEK_SET;
47 lock.l_start = 0;
48 lock.l_len = 4;
49 lock.l_pid = getpid();
51 lock.l_type = F_WRLCK;
53 /* check if a lock applies */
54 ret = fcntl(fd,F_GETLK64,&lock);
56 if ((ret == -1) ||
57 (lock.l_type == F_UNLCK)) {
58 /* printf("No lock conflict\n"); */
59 exit(1);
60 } else {
61 /* printf("lock conflict\n"); */
62 exit(0);
66 fd = open64(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600);
68 lock.l_type = F_WRLCK;
69 lock.l_whence = SEEK_SET;
70 #if defined(COMPILER_SUPPORTS_LL)
71 lock.l_start = 0x100000000LL;
72 #else
73 lock.l_start = 0x100000000;
74 #endif
75 lock.l_len = 4;
76 lock.l_pid = getpid();
78 /* set a 4 byte write lock */
79 fcntl(fd,F_SETLK64,&lock);
81 sys_waitpid(pid, &status, 0);
83 #if defined(WIFEXITED) && defined(WEXITSTATUS)
84 if(WIFEXITED(status)) {
85 status = WEXITSTATUS(status);
86 } else {
87 status = 1;
89 #else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
90 status = (status == 0) ? 0 : 1;
91 #endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */
93 unlink(DATA);
95 exit(status);