ReactOS 0.4.16-dev-2104-gb84fa49
stat.h File Reference
#include <corecrt.h>
#include <sys/types.h>
#include <pshpack8.h>
#include <poppack.h>
Include dependency graph for stat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _stat
 
struct  stat
 
struct  _stat32
 
struct  _stat32i64
 
struct  _stat64i32
 
struct  _stati64
 
struct  _stat64
 

Macros

#define _DEV_T_DEFINED
 
#define _INO_T_DEFINED
 
#define _OFF_T_DEFINED
 
#define _S_IEXEC   0x0040
 
#define _S_IWRITE   0x0080
 
#define _S_IREAD   0x0100
 
#define _S_IFIFO   0x1000
 
#define _S_IFCHR   0x2000
 
#define _S_IFDIR   0x4000
 
#define _S_IFREG   0x8000
 
#define _S_IFMT   0xF000
 
#define _STAT_DEFINED
 
#define _fstat64i32   _fstat
 
#define _fstat64   _fstati64
 
#define _stat64   _stati64
 
#define _stat64i32   _stat
 
#define _wstat64i32   _wstat
 
#define _wstat64   _wstati64
 
#define __stat64   _stat64
 
#define S_IFMT   _S_IFMT
 
#define S_IFDIR   _S_IFDIR
 
#define S_IFCHR   _S_IFCHR
 
#define S_IFREG   _S_IFREG
 
#define S_IREAD   _S_IREAD
 
#define S_IWRITE   _S_IWRITE
 
#define S_IEXEC   _S_IEXEC
 
#define _UMASK_DEFINED
 

Typedefs

typedef unsigned int _dev_t
 
typedef unsigned short _ino_t
 
typedef int _off_t
 

Functions

_ACRTIMP int __cdecl _fstat32 (int, struct _stat32 *)
 
_ACRTIMP int __cdecl _fstat32i64 (int, struct _stat32i64 *)
 
_ACRTIMP int __cdecl _fstat64 (int, struct _stat64 *)
 
_ACRTIMP int __cdecl _fstat64i32 (int, struct _stat64i32 *)
 
_ACRTIMP int __cdecl _stat32 (const char *, struct _stat32 *)
 
_ACRTIMP int __cdecl _stat32i64 (const char *, struct _stat32i64 *)
 
_ACRTIMP int __cdecl _stat64 (const char *, struct _stat64 *)
 
_ACRTIMP int __cdecl _stat64i32 (const char *, struct _stat64i32 *)
 
_ACRTIMP int __cdecl _umask (int)
 
_ACRTIMP int __cdecl _wstat32 (const wchar_t *, struct _stat32 *)
 
_ACRTIMP int __cdecl _wstat32i64 (const wchar_t *, struct _stat32i64 *)
 
_ACRTIMP int __cdecl _wstat64 (const wchar_t *, struct _stat64 *)
 
_ACRTIMP int __cdecl _wstat64i32 (const wchar_t *, struct _stat64i32 *)
 
static int fstat (int fd, struct stat *ptr)
 
static int stat (const char *path, struct stat *ptr)
 
static int umask (int fd)
 

Macro Definition Documentation

◆ __stat64

#define __stat64   _stat64

Definition at line 189 of file stat.h.

◆ _DEV_T_DEFINED

#define _DEV_T_DEFINED

Definition at line 22 of file stat.h.

◆ _fstat64

#define _fstat64   _fstati64

Definition at line 181 of file stat.h.

◆ _fstat64i32

#define _fstat64i32   _fstat

Definition at line 180 of file stat.h.

◆ _INO_T_DEFINED

#define _INO_T_DEFINED

Definition at line 27 of file stat.h.

◆ _OFF_T_DEFINED

#define _OFF_T_DEFINED

Definition at line 32 of file stat.h.

◆ _S_IEXEC

#define _S_IEXEC   0x0040

Definition at line 35 of file stat.h.

◆ _S_IFCHR

#define _S_IFCHR   0x2000

Definition at line 39 of file stat.h.

◆ _S_IFDIR

#define _S_IFDIR   0x4000

Definition at line 40 of file stat.h.

◆ _S_IFIFO

#define _S_IFIFO   0x1000

Definition at line 38 of file stat.h.

◆ _S_IFMT

#define _S_IFMT   0xF000

Definition at line 42 of file stat.h.

◆ _S_IFREG

#define _S_IFREG   0x8000

Definition at line 41 of file stat.h.

◆ _S_IREAD

#define _S_IREAD   0x0100

Definition at line 37 of file stat.h.

◆ _S_IWRITE

#define _S_IWRITE   0x0080

Definition at line 36 of file stat.h.

◆ _stat64

Definition at line 182 of file stat.h.

◆ _stat64i32

Definition at line 183 of file stat.h.

◆ _STAT_DEFINED

#define _STAT_DEFINED

Definition at line 50 of file stat.h.

◆ _UMASK_DEFINED

#define _UMASK_DEFINED

Definition at line 222 of file stat.h.

◆ _wstat64

#define _wstat64   _wstati64

Definition at line 185 of file stat.h.

◆ _wstat64i32

#define _wstat64i32   _wstat

Definition at line 184 of file stat.h.

◆ S_IEXEC

#define S_IEXEC   _S_IEXEC

Definition at line 216 of file stat.h.

◆ S_IFCHR

#define S_IFCHR   _S_IFCHR

Definition at line 212 of file stat.h.

◆ S_IFDIR

#define S_IFDIR   _S_IFDIR

Definition at line 211 of file stat.h.

◆ S_IFMT

#define S_IFMT   _S_IFMT

Definition at line 210 of file stat.h.

◆ S_IFREG

#define S_IFREG   _S_IFREG

Definition at line 213 of file stat.h.

◆ S_IREAD

#define S_IREAD   _S_IREAD

Definition at line 214 of file stat.h.

◆ S_IWRITE

#define S_IWRITE   _S_IWRITE

Definition at line 215 of file stat.h.

Typedef Documentation

◆ _dev_t

typedef unsigned int _dev_t

Definition at line 20 of file stat.h.

◆ _ino_t

Definition at line 26 of file stat.h.

◆ _off_t

typedef int _off_t

Definition at line 31 of file stat.h.

Function Documentation

◆ _fstat32()

_ACRTIMP int __cdecl _fstat32 ( int  fd,
struct _stat32 buf 
)

Definition at line 2030 of file file.c.

2031{
2032 int ret;
2033 struct _stat64 buf64;
2034
2035 ret = _fstat64(fd, &buf64);
2036 if (!ret)
2038 return ret;
2039}
static void msvcrt_stat64_to_stat32(const struct _stat64 *buf64, struct _stat32 *buf)
Definition: file.c:339
#define _fstat64
Definition: stat.h:181
return ret
Definition: mutex.c:146
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static int fd
Definition: io.c:51
Definition: stat.h:136

◆ _fstat32i64()

_ACRTIMP int __cdecl _fstat32i64 ( int  fd,
struct _stat32i64 buf 
)

Definition at line 2044 of file file.c.

2045{
2046 int ret;
2047 struct _stat64 buf64;
2048
2049 ret = _fstat64(fd, &buf64);
2050 if (!ret)
2052 return ret;
2053}
static void msvcrt_stat64_to_stat32i64(const struct _stat64 *buf64, struct _stat32i64 *buf)
Definition: file.c:369

◆ _fstat64()

_ACRTIMP int __cdecl _fstat64 ( int  fd,
struct _stat64 buf 
)

Definition at line 1934 of file file.c.

1935{
1937 DWORD dw;
1938 DWORD type;
1939
1940 TRACE(":fd (%d) stat (%p)\n", fd, buf);
1941 if (info->handle == INVALID_HANDLE_VALUE)
1942 {
1944 return -1;
1945 }
1946
1947 if (!buf)
1948 {
1949 WARN(":failed-NULL buf\n");
1952 return -1;
1953 }
1954
1955 memset(buf, 0, sizeof(struct _stat64));
1956 type = GetFileType(info->handle);
1957 if (type == FILE_TYPE_PIPE)
1958 {
1959 buf->st_dev = buf->st_rdev = fd;
1960 buf->st_mode = _S_IFIFO;
1961 buf->st_nlink = 1;
1962 }
1963 else if (type == FILE_TYPE_CHAR)
1964 {
1965 buf->st_dev = buf->st_rdev = fd;
1966 buf->st_mode = _S_IFCHR;
1967 buf->st_nlink = 1;
1968 }
1969 else /* FILE_TYPE_DISK etc. */
1970 {
1971 FILE_BASIC_INFORMATION basic_info;
1975
1976 if ((status = NtQueryInformationFile( info->handle, &io, &basic_info, sizeof(basic_info), FileBasicInformation )) ||
1977 (status = NtQueryInformationFile( info->handle, &io, &std_info, sizeof(std_info), FileStandardInformation )))
1978 {
1979 WARN(":failed-error %lx\n", status);
1982 return -1;
1983 }
1984 buf->st_mode = _S_IFREG | 0444;
1985 if (!(basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY))
1986 buf->st_mode |= 0222;
1987 buf->st_size = std_info.EndOfFile.QuadPart;
1989 buf->st_atime = dw;
1991 buf->st_mtime = buf->st_ctime = dw;
1992 buf->st_nlink = std_info.NumberOfLinks;
1993 TRACE(":dwFileAttributes = %#lx, mode set to %#x\n",
1994 basic_info.FileAttributes, buf->st_mode);
1995 }
1997 return 0;
1998}
LONG NTSTATUS
Definition: precomp.h:26
#define WARN(fmt,...)
Definition: precomp.h:61
#define _S_IFCHR
Definition: stat.h:21
#define _S_IFREG
Definition: stat.h:27
#define _S_IFIFO
Definition: stat.h:20
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
DWORD WINAPI GetFileType(HANDLE hFile)
Definition: fileinfo.c:269
static ioinfo * get_ioinfo(int fd)
Definition: file.c:417
static void release_ioinfo(ioinfo *info)
Definition: file.c:514
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileBasicInformation
Definition: from_kernel.h:65
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
#define msvcrt_set_errno
Definition: heap.c:50
#define memset(x, y, z)
Definition: compat.h:39
#define FileStandardInformation
Definition: propsheet.cpp:61
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:944
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:943
Definition: file.c:128
Definition: ps.c:97
LONGLONG QuadPart
Definition: typedefs.h:114
#define FILE_TYPE_CHAR
Definition: winbase.h:284
#define FILE_TYPE_PIPE
Definition: winbase.h:285

◆ _fstat64i32()

_ACRTIMP int __cdecl _fstat64i32 ( int  fd,
struct _stat64i32 buf 
)

Definition at line 2058 of file file.c.

2059{
2060 int ret;
2061 struct _stat64 buf64;
2062
2063 ret = _fstat64(fd, &buf64);
2064 if (!ret)
2066 return ret;
2067}
static void msvcrt_stat64_to_stat64i32(const struct _stat64 *buf64, struct _stat64i32 *buf)
Definition: file.c:354

◆ _stat32()

_ACRTIMP int __cdecl _stat32 ( const char path,
struct _stat32 result 
)

Definition at line 517 of file stat.cpp.

518{
519 return common_stat(path, result);
520}
GLuint64EXT * result
Definition: glext.h:11304
static int __cdecl common_stat(wchar_t const *const path, StatStruct *const result)
Definition: stat.cpp:453

◆ _stat32i64()

_ACRTIMP int __cdecl _stat32i64 ( const char path,
struct _stat32i64 result 
)

Definition at line 522 of file stat.cpp.

523{
524 return common_stat(path, result);
525}

◆ _stat64()

_ACRTIMP int __cdecl _stat64 ( const char path,
struct _stat64 buf 
)

Definition at line 3188 of file file.c.

3189{
3190 wchar_t *pathW = NULL;
3191 int ret;
3192
3193 if (path && !(pathW = wstrdupa_utf8(path))) return -1;
3194 ret = _wstat64(pathW, buf);
3195 free(pathW);
3196 return ret;
3197}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define _wstat64
Definition: stat.h:185
static wchar_t * wstrdupa_utf8(const char *str)
Definition: msvcrt.h:440

◆ _stat64i32()

_ACRTIMP int __cdecl _stat64i32 ( const char path,
struct _stat64i32 result 
)

Definition at line 532 of file stat.cpp.

533{
534 return common_stat(path, result);
535}

◆ _umask()

_ACRTIMP int __cdecl _umask ( int  umask)

Definition at line 3486 of file file.c.

3487{
3488 int old_umask = MSVCRT_umask;
3489 TRACE("(%d)\n",umask);
3491 return old_umask;
3492}
static int MSVCRT_umask
Definition: file.c:282
static int umask(int fd)
Definition: io.h:31

Referenced by umask().

◆ _wstat32()

_ACRTIMP int __cdecl _wstat32 ( const wchar_t path,
struct _stat32 result 
)

Definition at line 537 of file stat.cpp.

538{
539 return common_stat(path, result);
540}

◆ _wstat32i64()

_ACRTIMP int __cdecl _wstat32i64 ( const wchar_t path,
struct _stat32i64 result 
)

Definition at line 542 of file stat.cpp.

543{
544 return common_stat(path, result);
545}

◆ _wstat64()

_ACRTIMP int __cdecl _wstat64 ( const wchar_t path,
struct _stat64 buf 
)

Definition at line 3276 of file file.c.

3277{
3278 DWORD dw;
3280 unsigned short mode = ALL_S_IREAD;
3281 int plen;
3282
3283 TRACE(":file (%s) buf(%p)\n", debugstr_w(path), buf);
3284
3285 plen = wcslen(path);
3286 while (plen && path[plen-1]==' ')
3287 plen--;
3288
3289 if (plen==2 && path[1]==':')
3290 {
3291 *_errno() = ENOENT;
3292 return -1;
3293 }
3294
3295#if _MSVCR_VER<140
3296 if (plen>=2 && path[plen-2]!=':' && (path[plen-1]=='\\' || path[plen-1]=='/'))
3297 {
3298 *_errno() = ENOENT;
3299 return -1;
3300 }
3301#endif
3302
3304 {
3305 TRACE("failed (%ld)\n", GetLastError());
3306 *_errno() = ENOENT;
3307 return -1;
3308 }
3309
3310 memset(buf,0,sizeof(struct _stat64));
3311
3312 /* FIXME: rdev isn't drive num, despite what the docs says-what is it? */
3313 if (iswalpha(*path) && path[1] == ':')
3314 buf->st_dev = buf->st_rdev = towupper(*path) - 'A'; /* drive num */
3315 else
3316 buf->st_dev = buf->st_rdev = _getdrive() - 1;
3317
3318 /* Dir, or regular file? */
3320 mode |= (_S_IFDIR | ALL_S_IEXEC);
3321 else
3322 {
3323 mode |= _S_IFREG;
3324 /* executable? */
3325 if (plen > 6 && path[plen-4] == '.') /* shortest exe: "\x.exe" */
3326 {
3327 ULONGLONG ext = towlower(path[plen-1]) | (towlower(path[plen-2]) << 16) |
3328 ((ULONGLONG)towlower(path[plen-3]) << 32);
3329 if (ext == WCEXE || ext == WCBAT || ext == WCCMD || ext == WCCOM)
3330 mode |= ALL_S_IEXEC;
3331 }
3332 }
3333
3335 mode |= ALL_S_IWRITE;
3336
3337 buf->st_mode = mode;
3338 buf->st_nlink = 1;
3339 buf->st_size = ((__int64)hfi.nFileSizeHigh << 32) + hfi.nFileSizeLow;
3341 buf->st_atime = dw;
3343 buf->st_mtime = buf->st_ctime = dw;
3344 TRACE("%d %d %#I64x %I64d %I64d %I64d\n", buf->st_mode, buf->st_nlink,
3345 buf->st_size, buf->st_atime, buf->st_mtime, buf->st_ctime);
3346 return 0;
3347}
#define _S_IFDIR
Definition: stat.h:23
static const WCHAR *const ext[]
Definition: module.c:53
BOOL WINAPI GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation)
Definition: fileinfo.c:552
int CDECL _getdrive(void)
Definition: dir.c:819
int *CDECL _errno(void)
Definition: errno.c:215
#define ALL_S_IEXEC
Definition: file.c:73
static const ULONGLONG WCCMD
Definition: file.c:291
#define ALL_S_IREAD
Definition: file.c:71
static const ULONGLONG WCBAT
Definition: file.c:290
#define ALL_S_IWRITE
Definition: file.c:72
static const ULONGLONG WCCOM
Definition: file.c:292
static const ULONGLONG WCEXE
Definition: file.c:289
#define __int64
Definition: corecrt.h:72
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define ENOENT
Definition: errno.h:25
GLenum mode
Definition: glext.h:6217
#define debugstr_w
Definition: kernel32.h:32
@ GetFileExInfoStandard
Definition: minwinbase.h:356
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define iswalpha(_c)
Definition: ctype.h:664
#define towlower(c)
Definition: wctype.h:97
#define towupper(c)
Definition: wctype.h:99
uint64_t ULONGLONG
Definition: typedefs.h:67
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ _wstat64i32()

_ACRTIMP int __cdecl _wstat64i32 ( const wchar_t path,
struct _stat64i32 result 
)

Definition at line 552 of file stat.cpp.

553{
554 return common_stat(path, result);
555}

◆ fstat()

static int fstat ( int  fd,
struct stat ptr 
)
inlinestatic

Definition at line 218 of file stat.h.

218{ return _fstat(fd, (struct _stat*)ptr); }
static PVOID ptr
Definition: dispmode.c:27
#define _fstat
Definition: stat.h:144
Definition: stat.h:52

◆ stat()

static int stat ( const char path,
struct stat ptr 
)
inlinestatic

Definition at line 219 of file stat.h.

219{ return _stat(path, (struct _stat*)ptr); }
#define _stat
Definition: stat.h:146

◆ umask()

static int umask ( int  fd)
inlinestatic

Definition at line 221 of file stat.h.

221{ return _umask(fd); }
_ACRTIMP int __cdecl _umask(int)
Definition: file.c:3486