1 /* test whether fcntl locking 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.fcntl"
36 /* lock a byte range in a open file */
37 int main(int argc, char *argv[])
40 int fd, ret, status=1;
45 fd = open(DATA, O_RDONLY);
47 if (fd == -1) exit(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_GETLK,&lock);
61 (lock.l_type == F_UNLCK)) {
68 fd = open(DATA, O_RDWR|O_CREAT|O_TRUNC, 0600);
70 lock.l_type = F_WRLCK;
71 lock.l_whence = SEEK_SET;
74 lock.l_pid = getpid();
76 /* set a 4 byte write lock */
77 fcntl(fd,F_SETLK,&lock);
79 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) */