|
7 | 7 | #define PATH_BUF_LEN 4096
|
8 | 8 | #include <windows.h>
|
9 | 9 | #include <stringapiset.h>
|
10 |
| -#else |
11 |
| -// We support a pipe-based API for non-Windows platforms. |
12 |
| -#include <unistd.h> |
13 |
| -#include <fcntl.h> |
14 |
| -#include <string> |
15 | 10 | #endif
|
16 | 11 |
|
17 | 12 | extern "C" {
|
@@ -79,57 +74,4 @@ bool wtr_watcher_close(void* watcher)
|
79 | 74 | return true;
|
80 | 75 | }
|
81 | 76 |
|
82 |
| -#ifdef _WIN32 |
83 |
| -void* wtr_watcher_open_pipe(char const* const path, int* read_fd, int* write_fd) |
84 |
| -{ |
85 |
| - return NULL; |
86 |
| -} |
87 |
| - |
88 |
| -bool wtr_watcher_close_pipe(void* watcher, int read_fd, int write_fd) |
89 |
| -{ |
90 |
| - return false; |
91 |
| -} |
92 |
| -#else |
93 |
| -void* wtr_watcher_open_pipe(char const* const path, int* read_fd, int* write_fd) |
94 |
| -{ |
95 |
| - if (! path) { fprintf(stderr, "Path is null.\n"); return NULL; } |
96 |
| - if (! read_fd) { fprintf(stderr, "Read fd is null.\n"); return NULL; } |
97 |
| - if (! write_fd) { fprintf(stderr, "Write fd is null.\n"); return NULL; } |
98 |
| - if (*read_fd > 0) { fprintf(stderr, "Read fd is already open.\n"); return NULL; } |
99 |
| - if (*write_fd > 0) { fprintf(stderr, "Write fd is already open.\n"); return NULL; } |
100 |
| - int pipe_fds[2]; |
101 |
| - memset(pipe_fds, 0, sizeof(pipe_fds)); |
102 |
| - if (pipe(pipe_fds) == -1) { perror("pipe"); return NULL; } |
103 |
| - if (pipe_fds[0] <= 0) { fprintf(stderr, "Read fd is invalid.\n"); return NULL; } |
104 |
| - if (pipe_fds[1] <= 0) { fprintf(stderr, "Write fd is invalid.\n"); return NULL; } |
105 |
| - fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK); |
106 |
| - fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK); |
107 |
| - *read_fd = pipe_fds[0]; |
108 |
| - *write_fd = pipe_fds[1]; |
109 |
| - auto json_serialize_event_to_pipe = [pipe_fds](wtr::watcher::event event) { |
110 |
| - auto json = wtr::to<std::string>(event) + "\n"; |
111 |
| - write(pipe_fds[1], json.c_str(), json.size()); |
112 |
| - }; |
113 |
| - auto w = new wtr::watcher::watch(path, json_serialize_event_to_pipe); |
114 |
| - if (! w) { |
115 |
| - perror("new wtr::watcher::watch"); |
116 |
| - close(pipe_fds[0]); |
117 |
| - close(pipe_fds[1]); |
118 |
| - return NULL; |
119 |
| - } |
120 |
| - *read_fd = pipe_fds[0]; |
121 |
| - return (void*)w; |
122 |
| -} |
123 |
| - |
124 |
| -bool wtr_watcher_close_pipe(void* watcher, int read_fd, int write_fd) |
125 |
| -{ |
126 |
| - bool ok = false; |
127 |
| - ok |= watcher && ((wtr::watcher::watch*)watcher)->close(); |
128 |
| - ok |= write_fd > 0 && close(write_fd); |
129 |
| - ok |= read_fd > 0 && close(read_fd); |
130 |
| - if (watcher) delete (wtr::watcher::watch*)watcher; |
131 |
| - return ok; |
132 |
| -} |
133 |
| -#endif |
134 |
| - |
135 | 77 | } // extern "C"
|
0 commit comments