Created
November 23, 2014 21:35
-
-
Save doppioandante/aadde9de9f5aef503830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <uv.h> | |
uv_loop_t *loop; | |
void fs_callback(uv_fs_event_t *handle, const char *filename, int events, int status) { | |
fprintf(stderr, "Change detected(%d) in %s: ", events, handle->path); | |
if (events & UV_RENAME) | |
fprintf(stderr, "renamed"); | |
if (events & UV_CHANGE) | |
fprintf(stderr, "changed"); | |
fprintf(stderr, " %s\n", filename ? filename : ""); | |
} | |
int main(int argc, char **argv) { | |
if (argc <= 1) { | |
fprintf(stderr, "Usage: %s <file1> [file2 ...]\n", argv[0]); | |
return 1; | |
} | |
loop = uv_default_loop(); | |
while (argc-- > 1) { | |
fprintf(stderr, "Adding watch on %s\n", argv[argc]); | |
uv_fs_event_t *fs_event_req = malloc(sizeof(uv_fs_event_t)); | |
uv_fs_event_init(loop, fs_event_req); | |
// The recursive flag watches subdirectories too. | |
uv_fs_event_start(fs_event_req, fs_callback, argv[argc], UV_FS_EVENT_RECURSIVE); | |
} | |
return uv_run(loop, UV_RUN_DEFAULT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment