ReactOS 0.4.15-dev-7846-g8ba6c66
stat64.c File Reference
#include <precomp.h>
#include <tchar.h>
#include <direct.h>
#include <internal/wine/msvcrt.h>
Include dependency graph for stat64.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ALL_S_IREAD   (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))
 
#define ALL_S_IWRITE   (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))
 
#define ALL_S_IEXEC   (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))
 
#define TCHAR4   ULONG
 
#define TCSIZE_BITS   (sizeof(_TCHAR)*8)
 
#define EXE   (((TCHAR4)('e')<<(2*TCSIZE_BITS)) | ((TCHAR4)('x')<<TCSIZE_BITS) | ((TCHAR4)('e')))
 
#define BAT   (((TCHAR4)('b')<<(2*TCSIZE_BITS)) | ((TCHAR4)('a')<<TCSIZE_BITS) | ((TCHAR4)('t')))
 
#define CMD   (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('m')<<TCSIZE_BITS) | ((TCHAR4)('d')))
 
#define COM   (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('o')<<TCSIZE_BITS) | ((TCHAR4)('m')))
 

Functions

ioinfoget_ioinfo (int fd)
 
void release_ioinfo (ioinfo *info)
 
int CDECL _tstat64 (const _TCHAR *path, struct __stat64 *buf)
 
int CDECL _fstat64 (int fd, struct __stat64 *buf)
 

Macro Definition Documentation

◆ ALL_S_IEXEC

#define ALL_S_IEXEC   (_S_IEXEC | (_S_IEXEC >> 3) | (_S_IEXEC >> 6))

Definition at line 11 of file stat64.c.

◆ ALL_S_IREAD

#define ALL_S_IREAD   (_S_IREAD | (_S_IREAD >> 3) | (_S_IREAD >> 6))

Definition at line 9 of file stat64.c.

◆ ALL_S_IWRITE

#define ALL_S_IWRITE   (_S_IWRITE | (_S_IWRITE >> 3) | (_S_IWRITE >> 6))

Definition at line 10 of file stat64.c.

◆ BAT

#define BAT   (((TCHAR4)('b')<<(2*TCSIZE_BITS)) | ((TCHAR4)('a')<<TCSIZE_BITS) | ((TCHAR4)('t')))

Definition at line 22 of file stat64.c.

◆ CMD

#define CMD   (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('m')<<TCSIZE_BITS) | ((TCHAR4)('d')))

Definition at line 23 of file stat64.c.

◆ COM

#define COM   (((TCHAR4)('c')<<(2*TCSIZE_BITS)) | ((TCHAR4)('o')<<TCSIZE_BITS) | ((TCHAR4)('m')))

Definition at line 24 of file stat64.c.

◆ EXE

#define EXE   (((TCHAR4)('e')<<(2*TCSIZE_BITS)) | ((TCHAR4)('x')<<TCSIZE_BITS) | ((TCHAR4)('e')))

Definition at line 21 of file stat64.c.

◆ TCHAR4

#define TCHAR4   ULONG

Definition at line 16 of file stat64.c.

◆ TCSIZE_BITS

#define TCSIZE_BITS   (sizeof(_TCHAR)*8)

Definition at line 19 of file stat64.c.

Function Documentation

◆ _fstat64()

int CDECL _fstat64 ( int  fd,
struct __stat64 buf 
)

Definition at line 102 of file stat64.c.

103{
105 DWORD dw;
106 DWORD type;
108
109 TRACE(":fd (%d) stat (%p)\n", fd, buf);
110 if (info->handle == INVALID_HANDLE_VALUE)
111 {
113 return -1;
114 }
115
116 if (!buf)
117 {
118 WARN(":failed-NULL buf\n");
121 return -1;
122 }
123
124 memset(&hfi, 0, sizeof(hfi));
125 memset(buf, 0, sizeof(struct __stat64));
126 type = GetFileType(info->handle);
127 if (type == FILE_TYPE_PIPE)
128 {
129 buf->st_dev = buf->st_rdev = fd;
130 buf->st_mode = _S_IFIFO;
131 buf->st_nlink = 1;
132 }
133 else if (type == FILE_TYPE_CHAR)
134 {
135 buf->st_dev = buf->st_rdev = fd;
136 buf->st_mode = _S_IFCHR;
137 buf->st_nlink = 1;
138 }
139 else /* FILE_TYPE_DISK etc. */
140 {
141 if (!GetFileInformationByHandle(info->handle, &hfi))
142 {
143 WARN(":failed-last error (%d)\n",GetLastError());
146 return -1;
147 }
148 buf->st_mode = _S_IFREG | ALL_S_IREAD;
150 buf->st_mode |= ALL_S_IWRITE;
151 buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
153 buf->st_atime = dw;
155 buf->st_mtime = buf->st_ctime = dw;
156 buf->st_nlink = (short)hfi.nNumberOfLinks;
157 }
158 TRACE(":dwFileAttributes = 0x%x, mode set to 0x%x\n",hfi.dwFileAttributes,
159 buf->st_mode);
161 return 0;
162}
#define __int64
Definition: basetyps.h:16
#define WARN(fmt,...)
Definition: debug.h:112
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _S_IFCHR
Definition: stat.h:135
#define _S_IFREG
Definition: stat.h:137
#define __stat64
Definition: stat.h:129
#define _S_IFIFO
Definition: stat.h:136
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
void _dosmaperr(unsigned long oserrcode)
Definition: errno.c:81
static int fd
Definition: io.c:51
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
ioinfo * get_ioinfo(int fd)
Definition: file.c:181
void release_ioinfo(ioinfo *info)
Definition: file.c:263
#define ALL_S_IREAD
Definition: stat64.c:9
#define ALL_S_IWRITE
Definition: stat64.c:10
Definition: file.c:40
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_TYPE_CHAR
Definition: winbase.h:260
#define FILE_TYPE_PIPE
Definition: winbase.h:261

Referenced by _fstat(), _fstat32i64(), and _fstati64().

◆ _tstat64()

int CDECL _tstat64 ( const _TCHAR path,
struct __stat64 buf 
)

Definition at line 26 of file stat64.c.

27{
28 DWORD dw;
30 unsigned short mode = ALL_S_IREAD;
31 size_t plen;
32
33 TRACE(":file (%s) buf(%p)\n",path,buf);
34
35 plen = _tcslen(path);
36 while (plen && path[plen-1]==__T(' '))
37 plen--;
38
39 if (plen && (plen<2 || path[plen-2]!=__T(':')) &&
40 (path[plen-1]==__T(':') || path[plen-1]==__T('\\') || path[plen-1]==__T('/')))
41 {
42 *_errno() = ENOENT;
43 return -1;
44 }
45
47 {
48 TRACE("failed (%d)\n",GetLastError());
49 *_errno() = ENOENT;
50 return -1;
51 }
52
53 memset(buf,0,sizeof(struct __stat64));
54
55 /* FIXME: rdev isn't drive num, despite what the docs say-what is it?
56 Bon 011120: This FIXME seems incorrect
57 Also a letter as first char isn't enough to be classified
58 as a drive letter
59 */
60 if (_istalpha(*path) && (*(path+1)==__T(':')))
61 buf->st_dev = buf->st_rdev = _totupper(*path) - __T('A'); /* drive num */
62 else
63 buf->st_dev = buf->st_rdev = _getdrive() - 1;
64
65 /* Dir, or regular file? */
68 else
69 {
70 mode |= _S_IFREG;
71 /* executable? */
72 if (plen > 6 && path[plen-4] == __T('.')) /* shortest exe: "\x.exe" */
73 {
74
75 TCHAR4 ext = (TCHAR4)_totlower(path[plen-1])
76 | ((TCHAR4)_totlower(path[plen-2]) << TCSIZE_BITS)
77 | ((TCHAR4)_totlower(path[plen-3]) << 2*TCSIZE_BITS);
78
79 if (ext == EXE || ext == BAT || ext == CMD || ext == COM)
81 }
82 }
83
86
87 buf->st_mode = mode;
88 buf->st_nlink = 1;
89 buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
91 buf->st_atime = dw;
93 buf->st_mtime = buf->st_ctime = dw;
94 TRACE("%d %d 0x%08x%08x %d %d %d\n", buf->st_mode,buf->st_nlink,
95 (int)(buf->st_size >> 32),(int)buf->st_size,
96 (int)buf->st_atime,(int)buf->st_mtime,(int)buf->st_ctime);
97 return 0;
98}
#define ENOENT
Definition: acclib.h:79
_Check_return_ _CRTIMP int __cdecl _getdrive(void)
Definition: getdrive.c:20
static const WCHAR *const ext[]
Definition: module.c:53
GLenum mode
Definition: glext.h:6217
#define _S_IFDIR
Definition: stat.h:134
#define _istalpha
Definition: tchar.h:1492
#define _totupper
Definition: tchar.h:1509
#define _totlower
Definition: tchar.h:1511
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define CMD
Definition: stat64.c:23
#define ALL_S_IEXEC
Definition: stat64.c:11
#define COM
Definition: stat64.c:24
#define BAT
Definition: stat64.c:22
#define TCSIZE_BITS
Definition: stat64.c:19
#define TCHAR4
Definition: stat64.c:16
#define EXE
Definition: stat64.c:21
#define __T(x)
Definition: vfdio.h:17
#define GetFileAttributesEx
Definition: winbase.h:3751
@ GetFileExInfoStandard
Definition: winbase.h:1161
#define _tcslen
Definition: xmlstorage.h:198

◆ get_ioinfo()

ioinfo * get_ioinfo ( int  fd)

Definition at line 181 of file file.c.

182{
184 if(ret == &__badioinfo)
185 return ret;
188 return ret;
189}
static void init_ioinfo_cs(ioinfo *info)
Definition: file.c:169
static ioinfo * get_ioinfo_nolock(int fd)
Definition: file.c:158
ioinfo __badioinfo
Definition: file.c:126
int ret
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

Referenced by _fstat64().

◆ release_ioinfo()

void release_ioinfo ( ioinfo info)

Definition at line 263 of file file.c.

264{
265 if(info!=&__badioinfo && info->exflag & EF_CRIT_INIT)
267}
#define EF_CRIT_INIT
Definition: file.c:105
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by _fstat64().