Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions library/fcntl/flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@
#include "stdlib_memory.h"
#endif /* _STDLIB_MEMORY_H */

#include <stdio.h>

int
flock(int fd, int op) {
int ret = -1;
struct flock lock;

if (op != LOCK_SH && op != LOCK_EX && op != LOCK_UN && op != LOCK_NB) {
if (op != LOCK_SH
&& op != LOCK_EX
&& op != LOCK_UN
&& op != (LOCK_SH|LOCK_NB)
&& op != (LOCK_EX|LOCK_NB)) {
__set_errno(EINVAL);
goto out;
}

/* Initialize the flock structure. */
memset(&lock, 0, sizeof(lock));

if (op == LOCK_SH) {
if (op & LOCK_SH) {
lock.l_type = F_RDLCK;
/* Place a shared (read) lock on the file. */
ret = fcntl(fd, F_SETLK, &lock);
}
else if (op == LOCK_EX) {
else if (op & LOCK_EX) {
lock.l_type = F_WRLCK;
/* Place an exclusive (write) lock on the file. */
ret = fcntl(fd, F_SETLK, &lock);
Expand Down