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>
19 #ifdef HAVE_SYS_WAIT_H
25 static int sys_waitpid(pid_t pid
,int *status
,int options
)
28 return waitpid(pid
,status
,options
);
29 #else /* USE_WAITPID */
30 return wait4(pid
, status
, options
, NULL
);
31 #endif /* USE_WAITPID */
34 #define DATA "conftest.fcntl64"
36 /* lock a byte range in a open file */
37 int main(int argc
, char *argv
[])
40 int fd
, ret
, status
=1;
45 fd
= open64(DATA
, O_RDONLY
);
47 if (fd
== -1) return 1;
49 lock
.l_type
= F_WRLCK
;
50 lock
.l_whence
= SEEK_SET
;
53 lock
.l_pid
= getpid();
55 lock
.l_type
= F_WRLCK
;
57 /* check if a lock applies */
58 ret
= fcntl(fd
,F_GETLK64
,&lock
);
61 (lock
.l_type
== F_UNLCK
)) {
62 /* printf("No lock conflict\n"); */
65 /* printf("lock conflict\n"); */
70 fd
= open64(DATA
, O_RDWR
|O_CREAT
|O_TRUNC
, 0600);
72 lock
.l_type
= F_WRLCK
;
73 lock
.l_whence
= SEEK_SET
;
74 #if defined(COMPILER_SUPPORTS_LL)
75 lock
.l_start
= 0x100000000LL
;
77 lock
.l_start
= 0x100000000;
80 lock
.l_pid
= getpid();
82 /* set a 4 byte write lock */
83 fcntl(fd
,F_SETLK64
,&lock
);
85 sys_waitpid(pid
, &status
, 0);
87 #if defined(WIFEXITED) && defined(WEXITSTATUS)
88 if(WIFEXITED(status
)) {
89 status
= WEXITSTATUS(status
);
93 #else /* defined(WIFEXITED) && defined(WEXITSTATUS) */
94 status
= (status
== 0) ? 0 : 1;
95 #endif /* defined(WIFEXITED) && defined(WEXITSTATUS) */