Merge branch 'master' of ctdb into 'master' of samba
[nivanova/samba-autobuild/.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 *          pUrl = argv[1];
21
22         if(argc != 2)
23         {
24                 printf("usage: %s <file_url>\n", argv[0]);
25                 return 1;
26         }
27
28         
29         smbc_init(get_auth_data_fn, 0);
30         
31         if (smbc_stat(pUrl, &st1) < 0)
32         {
33                 perror("smbc_stat");
34                 return 1;
35         }
36         
37         if ((fd = smbc_open(pUrl, O_RDONLY, 0)) < 0)
38         {
39                 perror("smbc_open");
40                 return 1;
41         }
42
43         if (smbc_fstat(fd, &st2) < 0)
44         {
45                 perror("smbc_fstat");
46                 return 1;
47         }
48         
49         smbc_close(fd);
50
51 #define COMPARE(name, field)                                            \
52         if (st1.field != st2.field)                                     \
53         {                                                               \
54                 printf("Field " name " MISMATCH: st1=%lu, st2=%lu\n",   \
55                        (unsigned long) st1.field,                       \
56                        (unsigned long) st2.field);                      \
57         }
58
59         COMPARE("st_dev", st_dev);
60         COMPARE("st_ino", st_ino);
61         COMPARE("st_mode", st_mode);
62         COMPARE("st_nlink", st_nlink);
63         COMPARE("st_uid", st_uid);
64         COMPARE("st_gid", st_gid);
65         COMPARE("st_rdev", st_rdev);
66         COMPARE("st_size", st_size);
67         COMPARE("st_blksize", st_blksize);
68         COMPARE("st_blocks", st_blocks);
69         COMPARE("st_atime", st_atime);
70         COMPARE("st_mtime", st_mtime);
71         COMPARE("st_ctime", st_ctime);
72
73         return 0;
74 }
75