r11143: addnig derrell's test code changes
[Samba.git] / examples / libsmbclient / testread.c
blob1f1219ca8498067147a592bc4e6e262a382d6a8c
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 } while (ret > 0);
60 smbc_close(fd);
62 if (ret < 0)
64 errno = savedErrno;
65 perror("read");
66 return 1;
69 t1 = time(NULL);
71 printf("Elapsed time: %d seconds\n", t1 - t0);
73 return 0;