Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
filesystem.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Wildfire Games.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/*
24 * wchar_t versions of POSIX filesystem functions
25 */
26
27#ifndef INCLUDED_SYSDEP_FILESYSTEM
28#define INCLUDED_SYSDEP_FILESYSTEM
29
30#include "lib/os_path.h"
31#include "lib/posix/posix_filesystem.h" // mode_t
32
33
34//
35// dirent.h
36//
37
38struct WDIR;
39
40struct wdirent
41{
42 // note: SUSv3 describes this as a "char array" but of unspecified size.
43 // we declare as a pointer to avoid having to copy the string.
44 wchar_t* d_name;
45};
46
47extern WDIR* wopendir(const OsPath& path);
48
49extern wdirent* wreaddir(WDIR*);
50
51// return status for the file returned by the last successful
52// wreaddir call from the given directory stream.
53// currently sets st_size, st_mode, and st_mtime; the rest are zeroed.
54// non-portable, but considerably faster than stat(). used by dir_ForEachSortedEntry.
55extern int wreaddir_stat_np(WDIR*, struct stat*);
56
57extern int wclosedir(WDIR*);
58
59
60//
61// fcntl.h
62//
63
64// transfer directly to/from user's buffer.
65// treated as a request to enable aio.
66#ifndef O_DIRECT // i.e. Windows or OS X
67#define O_DIRECT 0x10000000 // (value does not conflict with any current Win32 _O_* flags.)
68#endif
69
70// Win32 _wsopen_s does not open files in a manner compatible with waio.
71// if its aio_read/aio_write are to be used, waio_open must (also) be called.
72// calling both is possible but wasteful and unsafe, since it prevents
73// file sharing restrictions, which are the only way to prevent
74// exposing previous data as a side effect of waio_Preallocate.
75// applications shouldn't mix aio and synchronous I/O anyway, so we
76// want wopen to call either waio_open or _wsopen_s.
77// since waio requires callers to respect the FILE_FLAG_NO_BUFFERING
78// restrictions (sector alignment), and IRIX/BSD/Linux O_DIRECT imposes
79// similar semantics, we treat that flag as a request to enable aio.
80extern int wopen(const OsPath& pathname, int oflag);
81extern int wopen(const OsPath& pathname, int oflag, mode_t mode);
82extern int wclose(int fd);
83
84
85//
86// unistd.h
87//
88
89// waio requires offsets and sizes to be multiples of the sector size.
90// to allow arbitrarily sized files, we truncate them after I/O.
91// however, ftruncate cannot be used since it is also subject to the
92// sector-alignment requirement. instead, the file must be closed and
93// this function called.
94int wtruncate(const OsPath& pathname, off_t length);
95
96int wunlink(const OsPath& pathname);
97
98int wrmdir(const OsPath& path);
99
100
101//
102// stdlib.h
103//
104
105OsPath wrealpath(const OsPath& pathname);
106
107
108//
109// sys/stat.h
110//
111
112int wstat(const OsPath& pathname, struct stat* buf);
113
114int wmkdir(const OsPath& path, mode_t mode);
115
116#endif // #ifndef INCLUDED_SYSDEP_FILESYSTEM
Definition: path.h:80
int wrmdir(const OsPath &path)
Definition: ufilesystem.cpp:133
int wopen(const OsPath &pathname, int oflag)
Definition: ufilesystem.cpp:106
int wtruncate(const OsPath &pathname, off_t length)
Definition: ufilesystem.cpp:123
int wreaddir_stat_np(WDIR *, struct stat *)
Definition: wfilesystem.cpp:187
WDIR * wopendir(const OsPath &path)
Definition: ufilesystem.cpp:76
int wmkdir(const OsPath &path, mode_t mode)
Definition: ufilesystem.cpp:157
int wclose(int fd)
Definition: ufilesystem.cpp:117
int wunlink(const OsPath &pathname)
Definition: ufilesystem.cpp:128
int wstat(const OsPath &pathname, struct stat *buf)
Definition: ufilesystem.cpp:152
OsPath wrealpath(const OsPath &pathname)
Definition: ufilesystem.cpp:143
wdirent * wreaddir(WDIR *)
Definition: ufilesystem.cpp:89
int wclosedir(WDIR *)
Definition: ufilesystem.cpp:98
Definition: ufilesystem.cpp:35
Definition: filesystem.h:41
wchar_t * d_name
Definition: filesystem.h:44
__int64 off_t
Definition: wposix_types.h:91