~zulcss/samba/server-dailies-3.0.37

« back to all changes in this revision

Viewing changes to examples/libsmbclient/teststat2.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:24:01 UTC
  • Revision ID: zulcss@ubuntu.com-20100928202401-tgh438aoatxv3zp3
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 are the same as timestamps returned by the local system.  To
 
11
 * test this, we assume a working Samba environment, and and access the same
 
12
 * file via SMB and locally (or NFS).
 
13
 *
 
14
 */
 
15
 
 
16
 
 
17
static int gettime(const char * pUrl,
 
18
                   const char * pLocalPath);
 
19
 
 
20
 
 
21
int main(int argc, char* argv[])
 
22
{
 
23
        if(argc != 3)
 
24
        {
 
25
                printf("usage: %s <file_url> <file_localpath>\n", argv[0]);
 
26
                return 1;
 
27
        }
 
28
 
 
29
        gettime(argv[1], argv[2]);
 
30
        return 0;
 
31
}
 
32
 
 
33
 
 
34
static int gettime(const char * pUrl,
 
35
                   const char * pLocalPath)
 
36
{
 
37
        //char *pSmbPath = 0;
 
38
        struct stat st;
 
39
        char mtime[32];
 
40
        char ctime[32];
 
41
        char atime[32];
 
42
        
 
43
        smbc_init(get_auth_data_fn, 0);
 
44
        
 
45
        if (smbc_stat(pUrl, &st) < 0)
 
46
        {
 
47
                perror("smbc_stat");
 
48
                return 1;
 
49
        }
 
50
        
 
51
        printf("SAMBA\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
 
52
               st.st_mtime, ctime_r(&st.st_mtime, mtime),
 
53
               st.st_ctime, ctime_r(&st.st_ctime, ctime),
 
54
               st.st_atime, ctime_r(&st.st_atime, atime)); 
 
55
        
 
56
        
 
57
        // check the stat on this file
 
58
        if (stat(pLocalPath, &st) < 0)
 
59
        {
 
60
                perror("stat");
 
61
                return 1;
 
62
        }
 
63
        
 
64
        printf("LOCAL\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n",
 
65
               st.st_mtime, ctime_r(&st.st_mtime, mtime),
 
66
               st.st_ctime, ctime_r(&st.st_ctime, ctime),
 
67
               st.st_atime, ctime_r(&st.st_atime, atime));
 
68
        
 
69
        
 
70
        return 0;
 
71
}
 
72