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