idl: add to_null property
[Samba/gbeck.git] / examples / libsmbclient / testread.c
blob87625e8ca1afdb74e5e82c72a3256e5cfead4118
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 fgets(path, sizeof(path) - 1, stdin);
28 if (strlen(path) == 0)
30 return 0;
33 p = path + strlen(path) - 1;
34 if (*p == '\n')
36 *p = '\0';
39 if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
41 perror("smbc_open");
42 continue;
47 ret = smbc_read(fd, buffer, sizeof(buffer));
48 savedErrno = errno;
49 if (ret > 0) fwrite(buffer, 1, ret, stdout);
50 } while (ret > 0);
52 smbc_close(fd);
54 if (ret < 0)
56 errno = savedErrno;
57 perror("read");
61 return 0;