Rizin
unix-like reverse engineering framework and cli tools
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
}
handle
static mcore_handle handle
Definition:
asm_mcore.c:8
path
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition:
sflib.h:35
size
voidpf void uLong size
Definition:
ioapi.h:138
filename
const char * filename
Definition:
ioapi.h:137
main
int main(int argc, const char **argv)
Definition:
main.c:340
malloc
void * malloc(size_t size)
Definition:
malloc.c:123
argv
static static fork const void static count static fd const char const char static newpath char char argv
Definition:
sflib.h:40
status
static const char struct stat static buf struct stat static buf static vhangup int status
Definition:
sflib.h:145
uv_fs_event_s
Definition:
uv.h:1546
uv_loop_s
Definition:
uv.h:1780
loop
uv_loop_t * loop
Definition:
main.c:7
command
const char * command
Definition:
main.c:7
run_command
void run_command(uv_fs_event_t *handle, const char *filename, int events, int status)
Definition:
main.c:9
uv.h
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:255
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:767
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
core.c:365
UV_FS_EVENT_RECURSIVE
@ UV_FS_EVENT_RECURSIVE
Definition:
uv.h:1620
UV_CHANGE
@ UV_CHANGE
Definition:
uv.h:1542
UV_RENAME
@ UV_RENAME
Definition:
uv.h:1541
uv_fs_event_init
UV_EXTERN int uv_fs_event_init(uv_loop_t *loop, uv_fs_event_t *handle)
Definition:
aix.c:757
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:763
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:592
subprojects
libuv-v1.40.0
docs
code
onchange
main.c
Generated by
1.9.1