~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to wince/sys/stat.c

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************
 
2
  stat.c
 
3
 
 
4
  author : uema2
 
5
  date   : Nov 30, 2002
 
6
 
 
7
  You can freely use, copy, modify, and redistribute
 
8
  the whole contents.
 
9
***************************************************************/
 
10
 
 
11
#include <windows.h>
 
12
#include <sys/stat.h>
 
13
#include <time.h>
 
14
#include "..\wince.h" /* for wce_mbtowc */
 
15
 
 
16
 
 
17
int _stat(const char *filename, struct _stat *st)
 
18
{
 
19
        DWORD dwAttribute;
 
20
        HANDLE h;
 
21
        DWORD dwSizeLow=0, dwSizeHigh=0, dwError=0;
 
22
        WIN32_FIND_DATAW fd;
 
23
        wchar_t *wfilename;
 
24
 
 
25
//      wfilename = wce_mbtowc(filename);
 
26
        wfilename = wce_replaceRelativeDir(filename);
 
27
 
 
28
        dwAttribute = GetFileAttributesW(wfilename);
 
29
        if(dwAttribute==0xFFFFFFFF)
 
30
        {
 
31
                free(wfilename);
 
32
                return -1;
 
33
        }
 
34
 
 
35
        st->st_mode = 0;
 
36
        if((dwAttribute & FILE_ATTRIBUTE_DIRECTORY) != 0)
 
37
                st->st_mode += S_IFDIR;
 
38
        else
 
39
                st->st_mode += S_IFREG;
 
40
 
 
41
        /* initialize */
 
42
        st->st_atime = 0;
 
43
    st->st_mtime = 0;
 
44
    st->st_ctime = 0;
 
45
        st->st_size  = 0;
 
46
        st->st_dev   = 0;
 
47
 
 
48
        h = FindFirstFileW(wfilename, &fd);
 
49
        if(h == INVALID_HANDLE_VALUE)
 
50
        {
 
51
                if(wfilename[wcslen(wfilename)-1]       == L'\\')
 
52
                {
 
53
                        wfilename[wcslen(wfilename)-1] = L'\0';
 
54
                        h = FindFirstFileW(wfilename, &fd);
 
55
                        if(h == INVALID_HANDLE_VALUE)
 
56
                        {
 
57
                                free(wfilename);
 
58
                                return 0;
 
59
                        }
 
60
                }
 
61
                else
 
62
                {
 
63
                        free(wfilename);
 
64
                        return 0;
 
65
                }
 
66
        }
 
67
 
 
68
        /* FILETIME -> time_t */
 
69
        st->st_atime = wce_FILETIME2time_t(&fd.ftLastAccessTime);
 
70
    st->st_mtime = wce_FILETIME2time_t(&fd.ftLastWriteTime);
 
71
    st->st_ctime = wce_FILETIME2time_t(&fd.ftCreationTime);
 
72
        st->st_size  = fd.nFileSizeLow;
 
73
 
 
74
        FindClose( h );
 
75
        free(wfilename);
 
76
        return 0;
 
77
}
 
78
 
 
79
int fstat(int file, struct stat *sbuf)
 
80
{
 
81
        /* GetFileSize & GetFileTime */
 
82
        DWORD dwSize;
 
83
        FILETIME ctime, atime, mtime;
 
84
 
 
85
        dwSize = GetFileSize( (HANDLE)file, NULL );
 
86
        if( dwSize == 0xFFFFFFFF )
 
87
                return -1;
 
88
 
 
89
        sbuf->st_size = dwSize;
 
90
        sbuf->st_dev  = 0;
 
91
        sbuf->st_rdev = 0;
 
92
        sbuf->st_mode = _S_IFREG;
 
93
        sbuf->st_nlink= 1;
 
94
 
 
95
        GetFileTime( (HANDLE)file, &ctime, &atime, &mtime );
 
96
        sbuf->st_ctime = wce_FILETIME2time_t(&ctime);
 
97
        sbuf->st_atime = wce_FILETIME2time_t(&atime);
 
98
        sbuf->st_mtime = wce_FILETIME2time_t(&mtime);
 
99
 
 
100
        return 0;
 
101
}
 
102