• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #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  */
eventfd_read(int fd,eventfd_t * counter)7 int 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 
eventfd_write(int fd,eventfd_t counter)17 int 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 }
26