加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stream_stdout.cpp 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
/* Copyright 2014-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#include "watchman.h"
static inline int which_fd(w_stm_t stm);
static int stdio_close(w_stm_t) {
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, w_evt_t*) {
w_log(W_LOG_FATAL, "calling get_events on a stdio stm\n");
}
static void stdio_set_nonb(w_stm_t, bool) {}
static bool stdio_rewind(w_stm_t) {
return false;
}
static bool stdio_shutdown(w_stm_t) {
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,
NULL
};
static struct watchman_stream stm_stdout = {
(void*)&stdio_ops,
&stdio_ops
};
static struct watchman_stream stm_stdin = {
(void*)&stdio_ops,
&stdio_ops
};
static inline int which_fd(w_stm_t stm) {
if (stm == &stm_stdout) {
return STDOUT_FILENO;
}
return STDIN_FILENO;
}
w_stm_t w_stm_stdout(void) {
return &stm_stdout;
}
w_stm_t w_stm_stdin(void) {
return &stm_stdin;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化