diff options
author | fadhil riyanto <me@fadev.org> | 2024-08-18 10:27:18 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-08-18 10:27:18 +0700 |
commit | 1b5dd78a4ff7c866b7a21d72bd9245505fe1d826 (patch) | |
tree | 14bbc7eb27948cbf5d138faa34b3f80aa1f19860 /inotify.c | |
parent | 69e75e6e398fc602e80f5de21d2c120e0703dd94 (diff) |
test file
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'inotify.c')
-rw-r--r-- | inotify.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/inotify.c b/inotify.c new file mode 100644 index 0000000..6059d20 --- /dev/null +++ b/inotify.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +typedef int FD ; + +int main() { + FD filed = open("/tmp/test_inotify", O_RDWR ); + char buf[128]; + + if( !filed ) { + printf("Openfile error\n"); + exit(-1); + } + + int nbytes; + while(1) { + nbytes = read(filed, buf, 16); + printf("read %d bytes from file.\n", nbytes); + if(nbytes > 0) { + printf("%s\n", buf); // split buffer by new line. + } + sleep(1); + } + return 0; +} |