forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_stdout.c
75 lines (61 loc) · 1.48 KB
/
stream_stdout.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright 2014-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#include "watchman.h"
static struct watchman_stream stm_stdout;
static struct watchman_stream stm_stdin;
static inline int which_fd(w_stm_t stm) {
if (stm == &stm_stdout) {
return STDOUT_FILENO;
}
return STDIN_FILENO;
}
static int stdio_close(w_stm_t stm) {
unused_parameter(stm);
return -1;
}
static int stdio_read(w_stm_t stm, void *buf, int size) {
return read(which_fd(stm), buf, size);
}
static int stdio_write(w_stm_t stm, const void *buf, int size) {
return write(which_fd(stm), buf, size);
}
static void stdio_get_events(w_stm_t stm, w_evt_t *readable) {
unused_parameter(stm);
unused_parameter(readable);
w_log(W_LOG_FATAL, "calling get_events on a stdio stm\n");
}
static void stdio_set_nonb(w_stm_t stm, bool nonb) {
unused_parameter(stm);
unused_parameter(nonb);
}
static bool stdio_rewind(w_stm_t stm) {
unused_parameter(stm);
return false;
}
static bool stdio_shutdown(w_stm_t stm) {
unused_parameter(stm);
return false;
}
static struct watchman_stream_ops stdio_ops = {
stdio_close,
stdio_read,
stdio_write,
stdio_get_events,
stdio_set_nonb,
stdio_rewind,
stdio_shutdown
};
static struct watchman_stream stm_stdout = {
(void*)&stdio_ops,
&stdio_ops
};
static struct watchman_stream stm_stdin = {
(void*)&stdio_ops,
&stdio_ops
};
w_stm_t w_stm_stdout(void) {
return &stm_stdout;
}
w_stm_t w_stm_stdin(void) {
return &stm_stdin;
}