platform_bionic/libc/unistd/eventfd.c
David 'Digit' Turner defd162212 libc: add <sys/eventfd.h> and corresponding implementations.
Change-Id: Ide040884c456190226e580513099fdb8377e015b
2010-09-28 09:20:37 +02:00

25 lines
527 B
C

#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;
}