source: vendor/current/examples/libsmbclient/testutime.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 1.9 KB
Line 
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
10int main(int argc, char * argv[])
11{
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;
20
21 if (argc == 1)
22 {
23 pSmbPath = "smb://RANDOM/Public/small";
24 }
25 else if (argc == 2)
26 {
27 pSmbPath = argv[1];
28 }
29 else if (argc == 3)
30 {
31 pSmbPath = argv[1];
32 t = (time_t) strtol(argv[2], NULL, 10);
33 }
34 else
35 {
36 printf("usage: "
37 "%s [ smb://path/to/file [ mtime ] ]\n",
38 argv[0]);
39 return 1;
40 }
41
42 smbc_init(get_auth_data_fn, debug);
43
44 if (smbc_stat(pSmbPath, &st) < 0)
45 {
46 perror("smbc_stat");
47 return 1;
48 }
49
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));
54
55 utimbuf.actime = t; /* unchangable (wont change) */
56 utimbuf.modtime = t; /* this one should succeed */
57 if (smbc_utime(pSmbPath, &utimbuf) < 0)
58 {
59 perror("smbc_utime");
60 return 1;
61 }
62
63 if (smbc_stat(pSmbPath, &st) < 0)
64 {
65 perror("smbc_stat");
66 return 1;
67 }
68
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));
73
74 return 0;
75}
Note: See TracBrowser for help on using the repository browser.