File: trigger_set.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (34 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (7)
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
26
27
28
29
30
31
32
33
34
#include "sysdeps.h"
#include <fcntl.h>
#include <unistd.h>
#include "trigger.h"

/** Set up a trigger for polling.
 *
 * The passed \c iopoll_fd must have at least two slots, as the second
 * slot may be required in the event the OS exhibits the "named pipe
 * bug".  This function must be called every time the trigger is pulled
 * to reset the trigger's state.
 */
int trigger_set(iopoll_fd* io, const char* path)
{
  if (io[0].fd > 0)
    close(io[0].fd);
#ifdef HASNAMEDPIPEBUG
  if (io[1].fd > 0)
    close(io[1].fd);
#endif
  if ((io[0].fd = open(path, O_RDONLY | O_NDELAY)) == -1)
    return 0;
  io[0].events = IOPOLL_READ;
  io[0].revents = 0;
#ifdef HASNAMEDPIPEBUG
  if ((io[1].fd = open(path, O_WRONLY | O_NDELAY)) == -1)
    return 0;
#else
  io[1].fd = -1;
#endif
  io[1].events = 0;
  io[1].revents = 0;
  return 1;
}