grpc
third_party
libuv
docs
code
onchange
libuv/docs/code/onchange/main.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
4
#include <
uv.h
>
5
6
uv_loop_t
*
loop
;
7
const
char
*
command
;
8
9
void
run_command
(
uv_fs_event_t
*
handle
,
const
char
*
filename
,
int
events,
int
status
) {
10
char
path
[1024];
11
size_t
size
= 1023;
12
// Does not handle error if path is longer than 1023.
13
uv_fs_event_getpath
(
handle
,
path
, &
size
);
14
path
[
size
] =
'\0'
;
15
16
fprintf(
stderr
,
"Change detected in %s: "
,
path
);
17
if
(events &
UV_RENAME
)
18
fprintf(
stderr
,
"renamed"
);
19
if
(events &
UV_CHANGE
)
20
fprintf(
stderr
,
"changed"
);
21
22
fprintf(
stderr
,
" %s\n"
,
filename
?
filename
:
""
);
23
system(
command
);
24
}
25
26
int
main
(
int
argc,
char
**argv) {
27
if
(argc <= 2) {
28
fprintf(
stderr
,
"Usage: %s <command> <file1> [file2 ...]\n"
, argv[0]);
29
return
1;
30
}
31
32
loop
=
uv_default_loop
();
33
command
= argv[1];
34
35
while
(argc-- > 2) {
36
fprintf(
stderr
,
"Adding watch on %s\n"
, argv[argc]);
37
uv_fs_event_t
*fs_event_req = malloc(
sizeof
(
uv_fs_event_t
));
38
uv_fs_event_init
(
loop
, fs_event_req);
39
// The recursive flag watches subdirectories too.
40
uv_fs_event_start
(fs_event_req,
run_command
, argv[argc],
UV_FS_EVENT_RECURSIVE
);
41
}
42
43
return
uv_run
(
loop
,
UV_RUN_DEFAULT
);
44
}
uv_fs_event_s
Definition:
uv.h:1533
loop
uv_loop_t * loop
Definition:
libuv/docs/code/onchange/main.c:6
filename
const char * filename
Definition:
bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
main
int main(int argc, char **argv)
Definition:
libuv/docs/code/onchange/main.c:26
status
absl::Status status
Definition:
rls.cc:251
check_documentation.path
path
Definition:
check_documentation.py:57
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
unix/core.c:361
python_utils.port_server.stderr
stderr
Definition:
port_server.py:51
run_command
void run_command(uv_fs_event_t *handle, const char *filename, int events, int status)
Definition:
libuv/docs/code/onchange/main.c:9
uv_fs_event_getpath
UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t *handle, char *buffer, size_t *size)
Definition:
uv-common.c:562
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:733
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:254
UV_RENAME
@ UV_RENAME
Definition:
uv.h:1528
UV_CHANGE
@ UV_CHANGE
Definition:
uv.h:1529
uv.h
UV_FS_EVENT_RECURSIVE
@ UV_FS_EVENT_RECURSIVE
Definition:
uv.h:1607
command
const char * command
Definition:
libuv/docs/code/onchange/main.c:7
uv_fs_event_start
UV_EXTERN int uv_fs_event_start(uv_fs_event_t *handle, uv_fs_event_cb cb, const char *path, unsigned int flags)
Definition:
aix.c:727
handle
static csh handle
Definition:
test_arm_regression.c:16
uv_loop_s
Definition:
uv.h:1767
uv_fs_event_init
UV_EXTERN int uv_fs_event_init(uv_loop_t *loop, uv_fs_event_t *handle)
Definition:
aix.c:717
size
voidpf void uLong size
Definition:
bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:17