summaryrefslogtreecommitdiffstats
path: root/libc/unistd/eventfd.c
blob: a48704328adc29ed3e340fface78fee086131b28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}