summaryrefslogtreecommitdiffstats
path: root/libc/unistd/eventfd.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/unistd/eventfd.c')
-rw-r--r--libc/unistd/eventfd.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/libc/unistd/eventfd.c b/libc/unistd/eventfd.c
new file mode 100644
index 0000000..a487043
--- /dev/null
+++ b/libc/unistd/eventfd.c
@@ -0,0 +1,25 @@
+#include <sys/eventfd.h>
+#include <unistd.h>
+
+/* We duplicate the GLibc error semantics, which are poorly defined
+ * if the read() or write() does not return the proper number of bytes.
+ */
+int eventfd_read(int fd, eventfd_t *counter)
+{
+ int ret = read(fd, counter, sizeof(*counter));
+
+ if (ret == sizeof(*counter))
+ return 0;
+
+ return -1;
+}
+
+int eventfd_write(int fd, eventfd_t counter)
+{
+ int ret = write(fd, &counter, sizeof(counter));
+
+ if (ret == sizeof(counter))
+ return 0;
+
+ return -1;
+}