r6369: update release notes
[Samba.git] / examples / libsmbclient / testutime.c
blob3a1540c654251fd0ffccab6daff72dbe1abe107d
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <time.h>
5 #include <libsmbclient.h>
6 #include "get_auth_data_fn.h"
9 int main(int argc, char * argv[])
11 int ret;
12 int debug = 0;
13 int mode = 0666;
14 char buffer[16384];
15 char mtime[32];
16 char ctime[32];
17 char atime[32];
18 char * pSmbPath = NULL;
19 struct stat st;
20 struct utimbuf utimbuf;
22 if (argc == 1)
24 pSmbPath = "smb://RANDOM/Public/small";
26 else if (argc == 2)
28 pSmbPath = argv[1];
30 else if (argc == 3)
32 pSmbPath = argv[1];
33 mode = (int) strtol(argv[2], NULL, 8);
35 else
37 printf("usage: "
38 "%s [ smb://path/to/file [ octal_mode ] ]\n",
39 argv[0]);
40 return 1;
43 smbc_init(get_auth_data_fn, debug);
45 if (smbc_stat(pSmbPath, &st) < 0)
47 perror("smbc_stat");
48 return 1;
51 printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
52 st.st_mtime, ctime_r(&st.st_mtime, mtime),
53 st.st_ctime, ctime_r(&st.st_ctime, ctime),
54 st.st_atime, ctime_r(&st.st_atime, atime));
56 utimbuf.actime = st.st_atime - 120; /* unchangable. this one wont change */
57 utimbuf.modtime = st.st_mtime - 120; /* this one should succeed */
58 if (smbc_utime(pSmbPath, &utimbuf) < 0)
60 perror("smbc_utime");
61 return 1;
64 if (smbc_stat(pSmbPath, &st) < 0)
66 perror("smbc_stat");
67 return 1;
70 printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
71 st.st_mtime, ctime_r(&st.st_mtime, mtime),
72 st.st_ctime, ctime_r(&st.st_ctime, ctime),
73 st.st_atime, ctime_r(&st.st_atime, atime));
75 return 0;