tevent: version 0.9.36
[Samba.git] / examples / libsmbclient / testnotify.c
blob8760cf0ba08aa1e39335d3bcfb388e0fdc7b76c7
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <time.h>
6 #include <errno.h>
7 #include <libsmbclient.h>
8 #include <inttypes.h>
9 #include "get_auth_data_fn.h"
11 static int notify_cb(const struct smbc_notify_callback_action *actions,
12 size_t num_actions, void *private_data)
14 int *count = private_data;
15 size_t i;
17 printf("%zu\n", num_actions);
19 for (i=0; i<num_actions; i++) {
20 const struct smbc_notify_callback_action *a = &actions[i];
21 printf("%s: %"PRIu32"\n", a->filename, a->action);
24 *count -= 1;
25 if (*count < 0) {
26 return 1;
29 return 0;
32 int main(int argc, char * argv[])
34 int fd;
35 int ret;
36 int debug = 0;
37 int saved_errno;
38 char path[2048];
39 char * p;
40 int count = 1000;
42 smbc_init(get_auth_data_fn, debug);
44 fprintf(stdout, "Path: ");
45 *path = '\0';
46 p = fgets(path, sizeof(path) - 1, stdin);
47 if (p == NULL) {
48 fprintf(stderr, "error reading from stdin\n");
49 return 1;
51 if (strlen(path) == 0) {
52 return 0;
55 p = path + strlen(path) - 1;
56 if (*p == '\n') {
57 *p = '\0';
60 fd = smbc_opendir(path);
61 if (fd < 0) {
62 perror("smbc_open");
63 return 1;
66 ret = smbc_notify(fd, 1,
67 SMBC_NOTIFY_CHANGE_SECURITY|
68 SMBC_NOTIFY_CHANGE_FILE_NAME,
69 1000, notify_cb, &count);
70 if (ret < 0) {
71 saved_errno = errno;
74 smbc_close(fd);
76 if (ret < 0) {
77 errno = saved_errno;
78 perror("notify");
81 return 0;