1 /* test whether 64 bit fcntl locking really works on this system */
3 #if defined(HAVE_UNISTD_H)
15 #ifdef HAVE_SYS_FCNTL_H
16 #include <sys/fcntl.h>
21 static int sys_waitpid(pid_t pid
,int *status
,int options
)
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
[])
36 int fd
, ret
, status
=1;
41 fd
= open64(DATA
, O_RDONLY
);
43 if (fd
== -1) exit(1);
45 lock
.l_type
= F_WRLCK
;
46 lock
.l_whence
= SEEK_SET
;
49 lock
.l_pid
= getpid();
51 lock
.l_type
= F_WRLCK
;
53 /* check if a lock applies */
54 ret
= fcntl(fd
,F_GETLK64
,&lock
);
57 (lock
.l_type
== F_UNLCK
)) {
58 /* printf("No lock conflict\n"); */
61 /* printf("lock conflict\n"); */
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
;
73 lock
.l_start
= 0x100000000;
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
);
89 #else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
90 status
= (status
== 0) ? 0 : 1;
91 #endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */