• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include <unsupported_api.h>
5 
lockf(int fd,int op,off_t size)6 int lockf(int fd, int op, off_t size)
7 {
8 	struct flock l = {
9 		.l_type = F_WRLCK,
10 		.l_whence = SEEK_CUR,
11 		.l_len = size,
12 	};
13 	unsupported_api(__FUNCTION__);
14 	switch (op) {
15 	case F_TEST:
16 		l.l_type = F_RDLCK;
17 		if (fcntl(fd, F_GETLK, &l) < 0)
18 			return -1;
19 		if (l.l_type == F_UNLCK || l.l_pid == getpid())
20 			return 0;
21 		errno = EACCES;
22 		return -1;
23 	case F_ULOCK:
24 		l.l_type = F_UNLCK;
25 	case F_TLOCK:
26 		return fcntl(fd, F_SETLK, &l);
27 	case F_LOCK:
28 		return fcntl(fd, F_SETLKW, &l);
29 	}
30 	errno = EINVAL;
31 	return -1;
32 }
33 
34 weak_alias(lockf, lockf64);
35