Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / examples / libsmbclient / testread.c
blobd59fc70ec11fcc7683ed71cf0c991e6c291a46b8
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 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;
24 if (argc == 1)
26 pSmbPath = "smb://RANDOM/Public/bigfile";
28 else if (argc == 2)
30 pSmbPath = argv[1];
32 else
34 printf("usage: "
35 "%s [ smb://path/to/file ]\n",
36 argv[0]);
37 return 1;
40 smbc_init(get_auth_data_fn, debug);
42 printf("Open file %s\n", pSmbPath);
44 t0 = time(NULL);
46 if ((fd = smbc_open(pSmbPath, O_RDONLY, 0)) < 0)
48 perror("smbc_open");
49 return 1;
52 printf("Beginning read loop.\n");
56 ret = smbc_read(fd, buffer, sizeof(buffer));
57 savedErrno = errno;
58 if (ret > 0) fwrite(buffer, 1, ret, stdout);
59 } while (ret > 0);
61 smbc_close(fd);
63 if (ret < 0)
65 errno = savedErrno;
66 perror("read");
67 return 1;
70 t1 = time(NULL);
72 printf("Elapsed time: %d seconds\n", t1 - t0);
74 return 0;