#include #include #include int open_lock_file (char *path) { return (open (path, O_RDWR | O_CREAT, 0664)); } int set_lock (int fd, const char *type) { struct flock fl; if (strcasecmp (type, "shared") == 0) fl.l_type = F_RDLCK; else if (strcasecmp (type, "exclusive") == 0) fl.l_type = F_WRLCK; else if (strcasecmp (type, "nil") == 0) fl.l_type = F_UNLCK; else FEerror ("Unrecognized lock type ~s", 1, make_simple_string (type)); fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; return (fcntl (fd, F_SETLKW, &fl)); }