examples:smbclient:notify: fix O3 error unused result from fgets
[samba.git] / examples / libsmbclient / testnotify.c
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"
10
11 static int notify_cb(const struct smbc_notify_callback_action *actions,
12                      size_t num_actions, void *private_data)
13 {
14         int *count = private_data;
15         size_t i;
16
17         printf("%zu\n", num_actions);
18
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);
22         }
23
24         *count -= 1;
25         if (*count < 0) {
26                 return 1;
27         }
28
29         return 0;
30 }
31
32 int main(int argc, char * argv[])
33 {
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;
41
42         smbc_init(get_auth_data_fn, debug);
43
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;
50         }
51         if (strlen(path) == 0) {
52                 return 0;
53         }
54
55         p = path + strlen(path) - 1;
56         if (*p == '\n') {
57                 *p = '\0';
58         }
59
60         fd = smbc_opendir(path);
61         if (fd < 0) {
62                 perror("smbc_open");
63                 return 1;
64         }
65
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;
72         }
73
74         smbc_close(fd);
75
76         if (ret < 0) {
77                 errno = saved_errno;
78                 perror("notify");
79         }
80
81         return 0;
82 }