8624ca108b63ed95e45986e794ee9f0954622f68
[kai/samba.git] / examples / libsmbclient / testutime.c
1 #include "config.h"
2 #include <stdio.h> 
3 #include <unistd.h>
4 #include <string.h> 
5 #include <time.h> 
6 #include <libsmbclient.h> 
7 #include "get_auth_data_fn.h"
8
9
10 int main(int argc, char * argv[]) 
11
12     int             ret;
13     int             debug = 0;
14     char            buffer[16384]; 
15     char            mtime[32];
16     char            ctime[32];
17     char            atime[32];
18     char *          pSmbPath = NULL;
19     time_t          t = time(NULL);
20     struct tm       tm;
21     struct stat     st;
22     struct utimbuf  utimbuf;
23     
24     if (argc == 1)
25     {
26         pSmbPath = "smb://RANDOM/Public/small";
27     }
28     else if (argc == 2)
29     {
30         pSmbPath = argv[1];
31     }
32     else if (argc == 3)
33     {
34         pSmbPath = argv[1];
35         t = (time_t) strtol(argv[2], NULL, 10);
36     }
37     else
38     {
39         printf("usage: "
40                "%s [ smb://path/to/file [ mtime ] ]\n",
41                argv[0]);
42         return 1;
43     }
44
45     smbc_init(get_auth_data_fn, debug); 
46     
47     if (smbc_stat(pSmbPath, &st) < 0)
48     {
49         perror("smbc_stat");
50         return 1;
51     }
52     
53     printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
54            st.st_mtime, ctime_r(&st.st_mtime, mtime),
55            st.st_ctime, ctime_r(&st.st_ctime, ctime),
56            st.st_atime, ctime_r(&st.st_atime, atime)); 
57     
58     utimbuf.actime = t;         /* unchangable (wont change) */
59     utimbuf.modtime = t;        /* this one should succeed */
60     if (smbc_utime(pSmbPath, &utimbuf) < 0)
61     {
62         perror("smbc_utime");
63         return 1;
64     }
65
66     if (smbc_stat(pSmbPath, &st) < 0)
67     {
68         perror("smbc_stat");
69         return 1;
70     }
71     
72     printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
73            st.st_mtime, ctime_r(&st.st_mtime, mtime),
74            st.st_ctime, ctime_r(&st.st_ctime, ctime),
75            st.st_atime, ctime_r(&st.st_atime, atime)); 
76     
77     return 0; 
78 }