util: Free memory in genrand torture test to satisfy sanitizer
[samba.git] / examples / libsmbclient / testread.c
blobe6d9bf869ab9afc54c66586c27482b8caeb3d01b
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 "get_auth_data_fn.h"
11 int main(int argc, char * argv[])
13 int fd;
14 int ret;
15 int debug = 0;
16 int savedErrno;
17 char buffer[2048];
18 char path[2048];
19 char * p;
21 smbc_init(get_auth_data_fn, debug);
23 for (;;)
25 fprintf(stdout, "Path: ");
26 *path = '\0';
27 p = fgets(path, sizeof(path) - 1, stdin);
28 if (p == NULL) {
29 fprintf(stderr, "failed to read from stdin\n");
30 return 1;
32 if (strlen(path) == 0)
34 return 0;
37 p = path + strlen(path) - 1;
38 if (*p == '\n')
40 *p = '\0';
43 if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
45 perror("smbc_open");
46 continue;
51 ret = smbc_read(fd, buffer, sizeof(buffer));
52 savedErrno = errno;
53 if (ret > 0) fwrite(buffer, 1, ret, stdout);
54 } while (ret > 0);
56 smbc_close(fd);
58 if (ret < 0)
60 errno = savedErrno;
61 perror("read");
65 return 0;