WHATSNEW: Add release notes for Samba 4.5.4.
[Samba.git] / examples / libsmbclient / testutime.c
blobcdbcfec316471230a23c125ea394475da663e34d
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"
10 int main(int argc, char * argv[])
12 int debug = 0;
13 char m_time[32];
14 char c_time[32];
15 char a_time[32];
16 const char * pSmbPath = NULL;
17 time_t t = time(NULL);
18 struct stat st;
19 struct utimbuf utimbuf;
21 if (argc == 1)
23 pSmbPath = "smb://RANDOM/Public/small";
25 else if (argc == 2)
27 pSmbPath = argv[1];
29 else if (argc == 3)
31 pSmbPath = argv[1];
32 t = (time_t) strtol(argv[2], NULL, 10);
34 else
36 printf("usage: "
37 "%s [ smb://path/to/file [ mtime ] ]\n",
38 argv[0]);
39 return 1;
42 smbc_init(get_auth_data_fn, debug);
44 if (smbc_stat(pSmbPath, &st) < 0)
46 perror("smbc_stat");
47 return 1;
50 printf("Before\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
51 (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
52 (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
53 (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
55 utimbuf.actime = t; /* unchangable (wont change) */
56 utimbuf.modtime = t; /* this one should succeed */
57 if (smbc_utime(pSmbPath, &utimbuf) < 0)
59 perror("smbc_utime");
60 return 1;
63 if (smbc_stat(pSmbPath, &st) < 0)
65 perror("smbc_stat");
66 return 1;
69 printf("After\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
70 (long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
71 (long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
72 (long long)st.st_atime, ctime_r(&st.st_atime, a_time));
74 return 0;