termux-packages/x11-packages/qemu-system-x86_64/qemu-3.0.0_lockf_implementation.h.patch

61 lines
1.5 KiB
Diff
Raw Normal View History

2018-10-26 15:19:03 +02:00
diff -uNr qemu-3.0.0/lockf_implementation.h qemu-3.0.0.mod/lockf_implementation.h
--- qemu-3.0.0/lockf_implementation.h 1970-01-01 03:00:00.000000000 +0300
2018-10-26 16:21:47 +02:00
+++ qemu-3.0.0.mod/lockf_implementation.h 2018-10-26 16:49:45.283598536 +0300
2018-09-17 13:27:14 +02:00
@@ -0,0 +1,56 @@
+#ifndef LOCKF_IMPLEMENTATION_H
+#define LOCKF_IMPLEMENTATION_H
+
+//
+// lockf() implementation from GNU Libc
+//
+
+static int lockf (int fd, int cmd, off_t len)
+{
+ struct flock fl;
+
+ memset ((char *) &fl, '\0', sizeof (fl));
+
+ /* lockf is always relative to the current file position. */
+ fl.l_whence = SEEK_CUR;
+ fl.l_start = 0;
+ fl.l_len = len;
+
+ switch (cmd)
+ {
+ case F_TEST:
+ /* Test the lock: return 0 if FD is unlocked or locked by this process;
+ return -1, set errno to EACCES, if another process holds the lock. */
+ fl.l_type = F_RDLCK;
+ if (fcntl (fd, F_GETLK, &fl) < 0)
+ return -1;
+ if (fl.l_type == F_UNLCK || fl.l_pid == getpid ())
+ return 0;
+ errno = EACCES;
+ return -1;
+
+ case F_ULOCK:
+ fl.l_type = F_UNLCK;
+ cmd = F_SETLK;
+ break;
+ case F_LOCK:
+ fl.l_type = F_WRLCK;
+ cmd = F_SETLKW;
+ break;
+ case F_TLOCK:
+ fl.l_type = F_WRLCK;
+ cmd = F_SETLK;
+ break;
+
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* lockf() is a cancellation point but so is fcntl() if F_SETLKW is
+ used. Therefore we don't have to care about cancellation here,
+ the fcntl() function will take care of it. */
+ return fcntl (fd, cmd, &fl);
+}
+
+#endif