Improve the Gemand pam_winbind translation.
[Samba/gbeck.git] / examples / libsmbclient / testutime.c
blob2ad395f862177806792346778d1c66f1a5e3dff5
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 char buffer[16384];
14 char mtime[32];
15 char ctime[32];
16 char atime[32];
17 char * pSmbPath = NULL;
18 time_t t = time(NULL);
19 struct tm tm;
20 struct stat st;
21 struct utimbuf utimbuf;
23 if (argc == 1)
25 pSmbPath = "smb://RANDOM/Public/small";
27 else if (argc == 2)
29 pSmbPath = argv[1];
31 else if (argc == 3)
33 pSmbPath = argv[1];
34 t = (time_t) strtol(argv[2], NULL, 10);
36 else
38 printf("usage: "
39 "%s [ smb://path/to/file [ mtime ] ]\n",
40 argv[0]);
41 return 1;
44 smbc_init(get_auth_data_fn, debug);
46 if (smbc_stat(pSmbPath, &st) < 0)
48 perror("smbc_stat");
49 return 1;
52 printf("Before\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
53 st.st_mtime, ctime_r(&st.st_mtime, mtime),
54 st.st_ctime, ctime_r(&st.st_ctime, ctime),
55 st.st_atime, ctime_r(&st.st_atime, atime));
57 utimbuf.actime = t; /* unchangable (wont change) */
58 utimbuf.modtime = t; /* this one should succeed */
59 if (smbc_utime(pSmbPath, &utimbuf) < 0)
61 perror("smbc_utime");
62 return 1;
65 if (smbc_stat(pSmbPath, &st) < 0)
67 perror("smbc_stat");
68 return 1;
71 printf("After\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
72 st.st_mtime, ctime_r(&st.st_mtime, mtime),
73 st.st_ctime, ctime_r(&st.st_ctime, ctime),
74 st.st_atime, ctime_r(&st.st_atime, atime));
76 return 0;