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 
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.
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 
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.
41  }
42 
43  return uv_run(loop, UV_RUN_DEFAULT);
44 }
static mcore_handle handle
Definition: asm_mcore.c:8
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
voidpf void uLong size
Definition: ioapi.h:138
const char * filename
Definition: ioapi.h:137
int main(int argc, const char **argv)
Definition: main.c:340
void * malloc(size_t size)
Definition: malloc.c:123
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
Definition: uv.h:1780
uv_loop_t * loop
Definition: main.c:7
const char * command
Definition: main.c:7
void run_command(uv_fs_event_t *handle, const char *filename, int events, int status)
Definition: main.c:9
@ UV_RUN_DEFAULT
Definition: uv.h:255
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_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
@ UV_FS_EVENT_RECURSIVE
Definition: uv.h:1620
@ UV_CHANGE
Definition: uv.h:1542
@ UV_RENAME
Definition: uv.h:1541
UV_EXTERN int uv_fs_event_init(uv_loop_t *loop, uv_fs_event_t *handle)
Definition: aix.c:757
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763
UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t *handle, char *buffer, size_t *size)
Definition: uv-common.c:592