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 11int 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 if (ret > 0) fwrite(buffer, 1, ret, stdout); 59 } while (ret > 0); 60 61 smbc_close(fd); 62 63 if (ret < 0) 64 { 65 errno = savedErrno; 66 perror("read"); 67 return 1; 68 } 69 70 t1 = time(NULL); 71 72 printf("Elapsed time: %d seconds\n", t1 - t0); 73 74 return 0; 75} 76