Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
[samba.git] / examples / libsmbclient / testread.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 "get_auth_data_fn.h"
9
10
11 int main(int argc, char * argv[]) 
12
13     int             i;
14     int             fd;
15     int             ret;
16     int             debug = 0;
17     int             mode = 0666;
18     int             savedErrno;
19     char            buffer[2048]; 
20     char            path[2048];
21     char *          p;
22     time_t          t0;
23     time_t          t1;
24     struct stat     st; 
25     
26     smbc_init(get_auth_data_fn, debug); 
27     
28     for (;;)
29     {
30         fprintf(stdout, "Path: ");
31         *path = '\0';
32         fgets(path, sizeof(path) - 1, stdin);
33         if (strlen(path) == 0)
34         {
35             return 0;
36         }
37
38         p = path + strlen(path) - 1;
39         if (*p == '\n')
40         {
41             *p = '\0';
42         }
43     
44         if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
45         {
46             perror("smbc_open");
47             continue;
48         }
49
50         do
51         {
52             ret = smbc_read(fd, buffer, sizeof(buffer));
53             savedErrno = errno;
54             if (ret > 0) fwrite(buffer, 1, ret, stdout);
55         } while (ret > 0);
56
57         smbc_close(fd);
58
59         if (ret < 0)
60         {
61             errno = savedErrno;
62             perror("read");
63         }
64     }
65
66     return 0; 
67 }