Merge commit 'origin/v3-2-test' into v3-2-stable
[samba.git] / examples / libsmbclient / teststat3.c
1 #include <libsmbclient.h>
2 #include <sys/stat.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <time.h>
6 #include "get_auth_data_fn.h"
7
8 /*
9  * This test is intended to ensure that the timestamps returned by
10  * libsmbclient using smbc_stat() are the same as those returned by
11  * smbc_fstat().
12  */
13
14
15 int main(int argc, char* argv[])
16 {
17         int             fd;
18         struct stat     st1;
19         struct stat     st2;
20         char            mtime[32];
21         char            ctime[32];
22         char            atime[32];
23         char *          pUrl = argv[1];
24
25         if(argc != 2)
26         {
27                 printf("usage: %s <file_url>\n", argv[0]);
28                 return 1;
29         }
30
31         
32         smbc_init(get_auth_data_fn, 0);
33         
34         if (smbc_stat(pUrl, &st1) < 0)
35         {
36                 perror("smbc_stat");
37                 return 1;
38         }
39         
40         if ((fd = smbc_open(pUrl, O_RDONLY, 0)) < 0)
41         {
42                 perror("smbc_open");
43                 return 1;
44         }
45
46         if (smbc_fstat(fd, &st2) < 0)
47         {
48                 perror("smbc_fstat");
49                 return 1;
50         }
51         
52         smbc_close(fd);
53
54 #define COMPARE(name, field)                                            \
55         if (st1.field != st2.field)                                     \
56         {                                                               \
57                 printf("Field " name " MISMATCH: st1=%lu, st2=%lu\n",   \
58                        (unsigned long) st1.field,                       \
59                        (unsigned long) st2.field);                      \
60         }
61
62         COMPARE("st_dev", st_dev);
63         COMPARE("st_ino", st_ino);
64         COMPARE("st_mode", st_mode);
65         COMPARE("st_nlink", st_nlink);
66         COMPARE("st_uid", st_uid);
67         COMPARE("st_gid", st_gid);
68         COMPARE("st_rdev", st_rdev);
69         COMPARE("st_size", st_size);
70         COMPARE("st_blksize", st_blksize);
71         COMPARE("st_blocks", st_blocks);
72         COMPARE("st_atime", st_atime);
73         COMPARE("st_mtime", st_mtime);
74         COMPARE("st_ctime", st_ctime);
75
76         return 0;
77 }
78