1 /* $Id: tstlockscope.c,v 1.1 2006-07-02 21:22:17 adam Exp $
6 /** \file tstlockscope.c
7 \brief tests scope of fcntl locks.. Either "process" or "thread"
22 const char *scope = "unknown";
24 static int file_lock(int fd, int type, int cmd)
28 area.l_whence = SEEK_SET;
29 area.l_len = area.l_start = 0L;
31 return fcntl(fd, cmd, &area);
34 void *run_func(void *arg)
36 if (file_lock(fd, F_WRLCK, F_SETLK) == -1)
43 int main(int argc, char **argv)
45 pthread_t child_thread;
46 fd = open("my.LCK", (O_CREAT|O_RDWR), 0666);
49 fprintf(stderr, "open: %s\n", strerror(errno));
53 if (file_lock(fd, F_WRLCK, F_SETLKW) == -1)
55 fprintf(stderr, "fcntl: %s\n", strerror(errno));
60 pthread_create(&child_thread, 0 /* attr */, run_func, 0);
61 pthread_join(child_thread, 0);
63 printf("fcntl lock scope: %s\n", scope);
70 * indent-tabs-mode: nil
72 * vim: shiftwidth=4 tabstop=8 expandtab