23 #include "precompiled.h"
72 if(d == &wdir_storage)
88 const DWORD fileAttributes = GetFileAttributesW(
OsString(path).c_str());
91 if(fileAttributes == INVALID_FILE_ATTRIBUTES)
95 if((fileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
121 OsPath searchPath = path/
"*";
126 if(d->
hFind != INVALID_HANDLE_VALUE)
128 if(GetLastError() == ERROR_NO_MORE_FILES)
147 if(d->
hFind == INVALID_HANDLE_VALUE)
159 if(GetLastError() == ERROR_NO_MORE_FILES)
169 if((d->
findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)) == 0)
185 FILETIME* filetime = &d->
findData.ftLastWriteTime;
187 memset(s, 0,
sizeof(*s));
189 s->st_mode = (
unsigned short)((d->
findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG);
210 ENSURE(!(oflag & O_CREAT));
211 return wopen(
OsString(pathname).c_str(), oflag, _S_IREAD|_S_IWRITE);
233 oflag |= O_CREAT|O_TRUNC;
235 errno_t ret = _wsopen_s(&fd,
OsString(pathname).c_str(), oflag, _SH_DENYRD, mode);
264 int read(
int fd,
void* buf,
size_t nbytes)
266 return _read(fd, buf, (
int)nbytes);
269 int write(
int fd,
void* buf,
size_t nbytes)
271 return _write(fd, buf, (
int)nbytes);
276 return _lseeki64(fd, ofs, whence);
284 HANDLE hFile = CreateFileW(
OsString(pathname).c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
285 ENSURE(hFile != INVALID_HANDLE_VALUE);
286 LARGE_INTEGER ofs; ofs.QuadPart = length;
296 return _wunlink(
OsString(pathname).c_str());
302 return _wrmdir(
OsString(path).c_str());
308 return _wrename(
OsString(pathnameOld).c_str(),
OsString(pathnameNew).c_str());
323 switch(GetLastError())
325 case ERROR_ALREADY_EXISTS:
327 case ERROR_PATH_NOT_FOUND:
329 case ERROR_ACCESS_DENIED:
331 case ERROR_WRITE_PROTECT:
333 case ERROR_DIRECTORY:
342 if(!CreateDirectoryW(
OsString(path).c_str(), (LPSECURITY_ATTRIBUTES)NULL))
354 return _wstat64(
OsString(pathname).c_str(), buf);
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
#define WARN_IF_ERR(expression)
static int ErrnoFromCreateDirectory()
some WinAPI functions SetLastError(0) on success, which is bad because it can hide previous errors...
WIN32_FIND_DATAW findData
LIB_API int wrmdir(const OsPath &path)
WDIR * wopendir(const OsPath &path)
LIB_API int wrename(const OsPath &pathnameOld, const OsPath &pathnameNew)
LIB_API int wtruncate(const OsPath &pathname, off_t length)
static volatile intptr_t wdir_in_use
static bool IsValidDirectory(const OsPath &path)
int ErrnoFromStatus(Status status)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
LIB_API int wunlink(const OsPath &pathname)
int read(int fd, void *buf, size_t nbytes)
LIB_API OsPath wrealpath(const OsPath &pathname)
int wreaddir_stat_np(WDIR *, struct stat *)
wdirent * wreaddir(WDIR *)
i64 Status
Error handling system.
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
off_t lseek(int fd, off_t ofs, int whence)
Status waio_open(const OsPath &pathname, int oflag,...)
LIB_API int wmkdir(const OsPath &path, mode_t mode)
int wopen(const OsPath &pathname, int oflag)
bool cpu_CAS(volatile intptr_t *location, intptr_t expected, intptr_t newValue)
atomic "compare and swap".
#define WARN_IF_FALSE(expression)
void write(OutputCB &output, const T &data)
Outputs a structure, using sizeof to get the size.
u64 u64_from_u32(u32 hi, u32 lo)
return lower 16-bits
time_t wtime_utc_filetime_to_time_t(FILETIME *ft)
static WDIR * wdir_alloc()
static void wdir_free(WDIR *d)
LIB_API int wstat(const OsPath &pathname, struct stat *buf)
Status waio_close(int fd)
static std::string OsString(const OsPath &path)