r12852: r12150@cabra: derrell | 2006-01-11 13:21:14 -0500
[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             fd;
14     int             ret;
15     int             debug = 0;
16     int             mode = 0666;
17     int             savedErrno;
18     char            buffer[2048]; 
19     char *          pSmbPath = NULL;
20     time_t          t0;
21     time_t          t1;
22     struct stat     st; 
23     
24     if (argc == 1)
25     {
26         pSmbPath = "smb://RANDOM/Public/bigfile";
27     }
28     else if (argc == 2)
29     {
30         pSmbPath = argv[1];
31     }
32     else
33     {
34         printf("usage: "
35                "%s [ smb://path/to/file ]\n",
36                argv[0]);
37         return 1;
38     }
39
40     smbc_init(get_auth_data_fn, debug); 
41     
42     printf("Open file %s\n", pSmbPath);
43     
44     t0 = time(NULL);
45
46     if ((fd = smbc_open(pSmbPath, O_RDONLY, 0)) < 0)
47     {
48         perror("smbc_open");
49         return 1;
50     }
51
52     printf("Beginning read loop.\n");
53
54     do
55     {
56         ret = smbc_read(fd, buffer, sizeof(buffer));
57         savedErrno = errno;
58     } while (ret > 0);
59
60     smbc_close(fd);
61
62     if (ret < 0)
63     {
64         errno = savedErrno;
65         perror("read");
66         return 1;
67     }
68
69     t1 = time(NULL);
70
71     printf("Elapsed time: %d seconds\n", t1 - t0);
72
73     return 0; 
74 }