11 #include <sys/ioctl.h>
30#if __DCL_HAVE_ALLOC_DEBUG
31#undef __DCL_ALLOC_LEVEL
32#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
35#if __DCL_HAVE_THIS_FILE__
53 return _waccess(_path, types) == 0;
73#define __rename _wrename
76 StringBuilder sb = _oldpath;
90#define __remove _wremove
102#define __unlink _wunlink
123 if (
__stat(_path, &sb) == -1) {
126 return (sb.st_mode & S_IFMT) == S_IFDIR;
141 time_t* _atime, time_t* _mtime, time_t* _ctime)
145 if (
__stat(_path, &sb) == -1) {
149 *_atime = sb.st_atime;
152 *_mtime = sb.st_mtime;
155 *_ctime = sb.st_ctime;
165 WIN32_FIND_DATAW findData;
166 HANDLE h = FindFirstFileW(_path, &findData);
171 size.HighPart = findData.nFileSizeHigh;
172 size.LowPart = findData.nFileSizeLow;
173 return size.QuadPart;
176 if (
__stat(_path, &sb) == -1)
187#define __chdir _wchdir
197 CharBuffer* buf = CharBuffer::create(PATH_MAX);
198 wchar_t* s = _wgetcwd(buf->data(), PATH_MAX);
203 buf->__dataLength = String::length(buf->data());
207 r =
r.replace(
'\\',
'/');
240#define __rmdir _wrmdir
249 return _c == L
'/' || _c == L
'\\' || _c == L
':';
256 const wchar_t* end = _path.data() + _path.length();
260 return _path.right(_path.length() - (end + 1 - _path));
262 }
while (_path.data() <= end);
272 const wchar_t* end = _path.data() + _path.length();
276 return _path.left(end - _path + 1);
278 }
while (_path.data() <= end);
286 const wchar_t* psz = _path;
300 const String& _dirname,
301 const String& _basename
306 String str = _dirname;
307 if (!str.isEmpty()) {
311 str = str + _basename;
321 if ((env = _wgetenv(L
"TMP"))
322 || (env = _wgetenv(L
"TEMP"))) {
326 CharBuffer* buf = CharBuffer::create(PATH_MAX);
327 DWORD n = GetTempPathW(PATH_MAX, buf->data());
329 buf->__dataLength = n;
333 r =
r.replace(
'\\',
'/');
343 if (!
r.endsWith(L
"/")) {
355 CharBuffer* buf = CharBuffer::create(PATH_MAX);
356 wchar_t* pFilePart =
NULL;
357 DWORD dwLen = ::GetFullPathNameW(_path, PATH_MAX, buf->data(), &pFilePart);
362 buf->__dataLength = dwLen;
363 String resolved = buf;
377 return _path.replace(L
'\\', L
'/');
382 const wchar_t* pszPath = _path;
383 if (*pszPath == L
'/' || *pszPath == L
'\\')
387 if (iswalpha(*pszPath)
388 && *(pszPath + 1) == L
':'
389 && (*(pszPath + 2) == L
'\\' || (*(pszPath + 2) == L
'/'))
404 size_t n =
__MIN(_n - total,
sizeof(buf));
405 if (n && (n = _input.read(buf, n))) {
413 return out.toByteString();
420 File file(_filename);
421 size_t totalBytes = _n == (size_t) -1 ? file.
size() : _n;
422 ByteBuffer* buf = ByteBuffer::create(totalBytes);
424 size_t read = file.
read(buf->data(), totalBytes);
425 buf->__dataLength = read;
426 *(buf->data() + read) =
'\0';
442 size_t readcCount = 0;
443 while ((readcCount = reader.
read(buf,
__countof(buf,
wchar_t))) > 0) {
444 writer.write(buf, readcCount);
461 writer.write(buf, n);
466 File file(_filename);
467 File::off_t totalBytes = file.
size();
470 CharBuffer* outBuf = CharBuffer::create(totalBytes);
471 wchar_t* outCur = outBuf->data();
472 wchar_t* outEnd = outCur + outBuf->__allocLength;
474#define BUFFER_SIZE 4096
477 size_t extraCount = 0;
480 size_t inCount = readCount + extraCount;
481 size_t inCountSave = inCount;
482 size_t outCount = outEnd - outCur;
483 int r = _decoder.decode(inBuf, inCount, outCur, outCount);
484 extraCount = inCountSave - inCount;
491 memmove(inBuf, inBuf + inCount, extraCount);
504 __DCL_TRACE1(
__T(
"Warning! Illegal sequence at the end of the text. [%d]\n"),
510 outBuf->__dataLength = outCur - outBuf->data();
524 while ((read = _input.read(buf,
sizeof(buf))) > 0) {
525 _output.write(buf, read);
DCLCAPI int __mkdir(const String &_path, mode_t _mode)
DCLCAPI int __stat(const String &_path, struct stat *_buf)
DCLCAPI int __remove(const String &_path)
DCLCAPI int __rename(const char *_oldpath, const char *_newpath)
DCLCAPI int __getenv(const String &_name, String &_value)
DCLCAPI int __realpath(const String &_path, String &_resolved)
DCLCAPI int __chdir(const String &_path)
DCLCAPI int __access(const String &_path, int _type)
DCLCAPI int __rmdir(const String &_path)
DCLCAPI int __unlink(const String &_path)
DCLCAPI int __getcwd(String &_r)
#define __countof(array, type)
#define INVALID_HANDLE_VALUE
bool __is_dir_delimiter(wchar_t _c)
#define __DCL_TRACE1(fmt, arg1)
#define __DCL_ASSERT(expr)
virtual size_t read(void *_buf, size_t _n) __DCL_THROWS1(IOException *)
off_t size() const __DCL_THROWS1(IOException *)
static void chdir(const String &_path) __DCL_THROWS1(IOException *)
static bool time(const String &_path, time_t *_atime, time_t *_mtime, time_t *_ctime)
static void mkdir(const String &_path, int _mode=0755) __DCL_THROWS1(IOException *)
static String dirname(const String &_path)
static bool exists(const String &_path)
static String basename(const String &_path)
static void remove(const String &_path) __DCL_THROWS1(IOException *)
static String filename(const String &_dirname, const String &_basename)
static bool isDirectory(const String &_path)
static uint64_t size(const String &_path) __DCL_THROWS1(IOException *)
static bool isAbsPath(const String &_path)
static void rmdir(const String &_path) __DCL_THROWS1(IOException *)
static void rename(const String &_oldpath, const String &_newpath) __DCL_THROWS1(IOException *)
static size_t copy(InputStream &_input, OutputStream &_output) __DCL_THROWS1(IOException *)
static ByteString readBytes(InputStream &_input, size_t _n=(size_t) -1) __DCL_THROWS1(IOException *)
static DateTime mtime(const String &_path) __DCL_THROWS1(IOException *)
static String readText(const String &_filename) __DCL_THROWS1(IOException *)
static String getcwd() __DCL_THROWS1(IOException *)
static void unlink(const String &_path) __DCL_THROWS1(IOException *)
static String realpath(const String &_path) __DCL_THROWS1(IOException *)
static bool access(const String &_path, int _mode)
static wchar_t delimiter(const String &_path)
static String unixpath(const String &_path)
virtual String toString() const
size_t __MIN(size_t x, size_t y)