blob: a48704328adc29ed3e340fface78fee086131b28 [file] [log] [blame]
David 'Digit' Turnerdefd1622010-09-26 22:29:14 +02001#include <sys/eventfd.h>
2#include <unistd.h>
3
4/* We duplicate the GLibc error semantics, which are poorly defined
5 * if the read() or write() does not return the proper number of bytes.
6 */
7int eventfd_read(int fd, eventfd_t *counter)
8{
9 int ret = read(fd, counter, sizeof(*counter));
10
11 if (ret == sizeof(*counter))
12 return 0;
13
14 return -1;
15}
16
17int eventfd_write(int fd, eventfd_t counter)
18{
19 int ret = write(fd, &counter, sizeof(counter));
20
21 if (ret == sizeof(counter))
22 return 0;
23
24 return -1;
25}