11 #include <sys/ioctl.h>
30#if __DCL_HAVE_ALLOC_DEBUG
31#undef __DCL_ALLOC_LEVEL
32#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
53 return _waccess(_path, types) == 0;
73#define __rename _wrename
76 StringBuilder sb = _oldpath;
90#define __remove _wremove
102#define __unlink _wunlink
124 if (
__stat(_path, &sb) == -1) {
127 return (sb.st_mode & S_IFMT) == S_IFDIR;
142 time_t* _atime, time_t* _mtime, time_t* _ctime)
146 if (
__stat(_path, &sb) == -1) {
150 *_atime = sb.st_atime;
153 *_mtime = sb.st_mtime;
156 *_ctime = sb.st_ctime;
166 WIN32_FIND_DATAW findData;
167 HANDLE h = FindFirstFileW(_path, &findData);
172 size.HighPart = findData.nFileSizeHigh;
173 size.LowPart = findData.nFileSizeLow;
174 return size.QuadPart;
177 if (
__stat(_path, &sb) == -1)
188#define __chdir _wchdir
198 CharBuffer*
buf = CharBuffer::create(PATH_MAX);
199 wchar_t* s = _wgetcwd(
buf->data(), PATH_MAX);
204 buf->__dataLength = String::length(
buf->data());
208 r =
r.replace(
'\\',
'/');
241#define __rmdir _wrmdir
250 return _c == L
'/' || _c == L
'\\' || _c == L
':';
257 const wchar_t* end = _path.data() + _path.length();
261 return _path.right(_path.length() - (end + 1 - _path));
263 }
while (_path.data() <= end);
273 const wchar_t* end = _path.data() + _path.length();
277 return _path.left(end - _path + 1);
279 }
while (_path.data() <= end);
287 const wchar_t* psz = _path;
301 const String& _dirname,
302 const String& _basename
307 String str = _dirname;
308 if (!str.isEmpty()) {
312 str = str + _basename;
322 if ((env = _wgetenv(L
"TMP"))
323 || (env = _wgetenv(L
"TEMP"))) {
327 CharBuffer*
buf = CharBuffer::create(PATH_MAX);
328 DWORD
n = GetTempPathW(PATH_MAX,
buf->data());
330 buf->__dataLength =
n;
334 r =
r.replace(
'\\',
'/');
344 if (!
r.endsWith(L
"/")) {
356 CharBuffer*
buf = CharBuffer::create(PATH_MAX);
357 wchar_t* pFilePart =
NULL;
358 DWORD dwLen = ::GetFullPathNameW(_path, PATH_MAX,
buf->data(), &pFilePart);
363 buf->__dataLength = dwLen;
364 String resolved =
buf;
378 return _path.replace(L
'\\', L
'/');
383 const wchar_t* pszPath = _path;
384 if (*pszPath == L
'/' || *pszPath == L
'\\')
388 if (iswalpha(*pszPath)
389 && *(pszPath + 1) == L
':'
390 && (*(pszPath + 2) == L
'\\' || (*(pszPath + 2) == L
'/'))
405 size_t n =
__MIN(_n - total,
sizeof(
buf));
406 if (
n && (
n = _input.read(
buf,
n))) {
414 return out.toByteString();
421 File file(_filename);
422 File::off_t totalBytes = _n == (size_t) -1 ? file.
size() : _n;
423 ByteBuffer*
buf = ByteBuffer::create(totalBytes);
425 size_t n = file.
read(
buf->data(), totalBytes);
426 buf->__dataLength =
n;
427 *(
buf->data() +
n) =
'\0';
444 size_t readcCount = 0;
446 writer.write(
buf, readcCount);
463 writer.write(
buf,
n);
468 File file(_filename);
469 File::off_t totalBytes = file.
size();
472 CharBuffer* outBuf = CharBuffer::create(totalBytes);
473 wchar_t* outCur = outBuf->data();
474 wchar_t* outEnd = outCur + outBuf->__allocLength;
476#define BUFFER_SIZE 4096
479 size_t extraCount = 0;
482 size_t inCount = readCount + extraCount;
483 size_t inCountSave = inCount;
484 size_t outCount = outEnd - outCur;
485 int r = _decoder.decode(inBuf, inCount, outCur, outCount);
486 extraCount = inCountSave - inCount;
493 memmove(inBuf, inBuf + inCount, extraCount);
506 __DCL_TRACE1(
__T(
"Warning! Illegal sequence at the end of the text. [%d]\n"),
512 outBuf->__dataLength = outCur - outBuf->data();
526 while ((read = _input.read(
buf,
sizeof(
buf))) > 0) {
527 _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)
void CharsetConvertException *size_t n
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)