Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <uv.h>

Go to the source code of this file.

Functions

void run_command (uv_fs_event_t *handle, const char *filename, int events, int status)
 
int main (int argc, char **argv)
 

Variables

uv_loop_tloop
 
const char * command
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file main.c.

26  {
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 }
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
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_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

References argv, command, loop, malloc(), run_command(), uv_default_loop(), uv_fs_event_init(), UV_FS_EVENT_RECURSIVE, uv_fs_event_start(), uv_run(), and UV_RUN_DEFAULT.

◆ run_command()

void run_command ( uv_fs_event_t handle,
const char *  filename,
int  events,
int  status 
)

Definition at line 9 of file main.c.

9  {
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 }
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
@ UV_CHANGE
Definition: uv.h:1542
@ UV_RENAME
Definition: uv.h:1541
UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t *handle, char *buffer, size_t *size)
Definition: uv-common.c:592

References command, handle, path, UV_CHANGE, uv_fs_event_getpath(), and UV_RENAME.

Referenced by main().

Variable Documentation

◆ command

◆ loop

uv_loop_t* loop

Definition at line 6 of file main.c.