result_t path_base::fullpath(exlib::string path, exlib::string &retVal) { #ifdef _WIN32 exlib::wstring str = utf8to16String(path); exlib::wchar utf16_buffer[MAX_PATH]; DWORD utf16_len = GetFullPathNameW(str.c_str(), MAX_PATH, utf16_buffer, NULL); if (!utf16_len) return CHECK_ERROR(LastError()); retVal = utf16to8String(utf16_buffer, (int32_t)utf16_len); return 0; #else if (isPathSlash(path.c_str()[0])) return normalize(path, retVal); exlib::string str; process_base::cwd(str); str.append(1, PATH_SLASH); str.append(path); return normalize(str, retVal); #endif }
void Stat::fill(WIN32_FIND_DATAW &fd) { name = utf16to8String(fd.cFileName); size = ((int64_t)fd.nFileSizeHigh << 32 | fd.nFileSizeLow); mode = S_IREAD | S_IEXEC; mtime = FileTimeToJSTime(fd.ftLastWriteTime); atime = FileTimeToJSTime(fd.ftLastAccessTime); ctime = FileTimeToJSTime(fd.ftCreationTime); if ((m_isDirectory = (FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes) != 0) == true) mode |= S_IFDIR; if ((m_isFile = (FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes) == 0) == true) mode |= S_IFREG; m_isReadable = true; if ((m_isWritable = (FILE_ATTRIBUTE_READONLY & fd.dwFileAttributes) == 0) == true) mode |= S_IWRITE; m_isExecutable = true; m_isSymbolicLink = false; m_isMemory = false; m_isSocket = false; }
result_t os_base::get_execPath(std::string &retVal) { WCHAR szFileName[MAX_PATH]; GetModuleFileNameW(NULL, szFileName, MAX_PATH); retVal = utf16to8String(szFileName); return 0; }
result_t Buffer::toString(const char* codec, int32_t offset, int32_t end, std::string &retVal) { result_t hr; std::string str; int32_t str_length; if (!qstricmp(codec, "utf8") || !qstricmp(codec, "utf-8") || !qstricmp(codec, "undefined")) { str = m_data; hr = 0; } else { if (!qstrcmp(codec, "hex")) hr = hex_base::encode(this, str); else if (!qstrcmp(codec, "base64")) hr = base64_base::encode(this, str); else if (!qstrcmp(codec, "ascii")) { int32_t len, i; len = (int32_t)m_data.length(); str.resize(len); for (i = 0; i < len; i ++) str[i] = m_data[i] & 0x7f; hr = 0; } else if (!qstrcmp(codec, "ucs2") || !qstrcmp(codec, "ucs-2") || !qstrcmp(codec, "utf16le") || !qstrcmp(codec, "utf-16le")) str = utf16to8String((const wchar *)m_data.c_str(), m_data.length() / 2); else hr = iconv_base::decode(codec, this, str); } if (hr < 0) return hr; str_length = (int32_t)str.length(); if (end < 0) end = str_length + end + 1; if (offset < 0 || end < 0 || offset > end) return CHECK_ERROR(CALL_E_INVALIDARG); if (end > str_length) end = str_length; retVal = str.substr(offset, end - offset); return hr; }
result_t process_base::cwd(std::string &retVal) { DWORD utf16_len; wchar utf16_buffer[MAX_PATH]; utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer); if (utf16_len == 0) return CHECK_ERROR(LastError()); utf16_buffer[utf16_len] = L'\0'; if (utf16_buffer[utf16_len - 1] == L'\\' && !(utf16_len == 3 && utf16_buffer[1] == L':')) { utf16_len--; utf16_buffer[utf16_len] = L'\0'; } retVal = utf16to8String(utf16_buffer, (int32_t)utf16_len); return 0; }