1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
15 fprintf(stderr, "usage: ./flocks_test on|off -c|-f|-l /path/to/file\n");
19 int main(int argc, char *argv[])
22 int mount_with_flock = 0;
28 if (!strncmp(argv[1], "on", 3)) {
30 } else if (!strncmp(argv[1], "off", 4)) {
36 if ((fd = open(argv[3], O_RDWR)) < 0) {
37 fprintf(stderr, "Couldn't open file: %s\n", argv[2]);
41 if (!strncmp(argv[2], "-c", 3)) {
45 fl.l_whence = SEEK_SET;
49 error = fcntl(fd, F_SETLK, &fl);
50 } else if (!strncmp(argv[2], "-l", 3)) {
51 error = lockf(fd, F_LOCK, 1);
52 } else if (!strncmp(argv[2], "-f", 3)) {
53 error = flock(fd, LOCK_EX);
59 return((error == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
61 return((error == 0) ? EXIT_FAILURE : EXIT_SUCCESS);