/*----------------------------------------------------------------------
|   NPT_File::RemoveDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::RemoveDir(const char* path)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    BOOL result = RemoveDirectoryW(NPT_WIN32_A2W(path));
    if (result == 0) {
        return MapError(GetLastError());
    }
    return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   NPT_Win32DynamicLibrary::FindSymbol
+---------------------------------------------------------------------*/
NPT_Result 
NPT_Win32DynamicLibrary::FindSymbol(const char* name, void*& symbol)
{
    if (name == NULL) return NPT_ERROR_INVALID_PARAMETERS;
    symbol = NULL;
    if (m_Library == NULL) return NPT_ERROR_NO_SUCH_ITEM;

    NPT_LOG_FINE_1("finding symbol %s", name);
#if defined(_WIN32_WCE)
    NPT_WIN32_USE_CHAR_CONVERSION;
    symbol = GetProcAddress(m_Library, NPT_WIN32_A2W(name));
#else
    symbol = GetProcAddress(m_Library, name);
#endif
    return symbol?NPT_SUCCESS:NPT_ERROR_NO_SUCH_ITEM;
}
/*----------------------------------------------------------------------
|   NPT_File::ListDir
+---------------------------------------------------------------------*/
NPT_Result 
NPT_File::ListDir(const char*           path, 
                  NPT_List<NPT_String>& entries, 
                  NPT_Ordinal           start /* = 0 */, 
                  NPT_Cardinal          max   /* = 0 */)
{
    NPT_WIN32_USE_CHAR_CONVERSION;

    // default return value
    entries.Clear();

    // check the arguments
    if (path == NULL || path[0] == '\0') return NPT_ERROR_INVALID_PARAMETERS;

    // construct a path name with a \* wildcard at the end
    NPT_String path_pattern = path;
    if (path_pattern.EndsWith("\\") || path_pattern.EndsWith("/")) {
        path_pattern += "*";
    } else {
        path_pattern += "\\*";
    }

    // list the entries
    WIN32_FIND_DATAW find_data;
    HANDLE find_handle = FindFirstFileW(NPT_WIN32_A2W(path_pattern.GetChars()), &find_data);
    if (find_handle == INVALID_HANDLE_VALUE) return MapError(GetLastError());
    NPT_Cardinal count = 0;
    do {
        if (NPT_File_ProcessFindData(&find_data)) {
            // continue if we still have entries to skip
            if (start > 0) {
                --start;
                continue;
            }
            entries.Add(NPT_WIN32_W2A(find_data.cFileName));

            // stop when we have reached the maximum requested
            if (max && ++count == max) return NPT_SUCCESS;
        }
    } while (FindNextFileW(find_handle, &find_data));
    DWORD last_error = GetLastError();
    FindClose(find_handle);
    if (last_error != ERROR_NO_MORE_FILES) return MapError(last_error);

    return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   NPT_fsopen_utf8
+---------------------------------------------------------------------*/
FILE*
NPT_fsopen_utf8(const char* path, const char* mode, int sh_flags)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    return _wfsopen(NPT_WIN32_A2W(path), NPT_WIN32_A2W(mode), sh_flags);
}
/*----------------------------------------------------------------------
|   NPT_stat_utf8
+---------------------------------------------------------------------*/
int
NPT_stat_utf8(const char* path, struct __stat64* info)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    return _wstat64(NPT_WIN32_A2W(path), info);
}
/*----------------------------------------------------------------------
|   NPT_fopen_utf8
+---------------------------------------------------------------------*/
FILE*
NPT_fopen_utf8(const char* path, const char* mode)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    return _wfopen(NPT_WIN32_A2W(path), NPT_WIN32_A2W(mode));
}
Exemplo n.º 7
0
/*----------------------------------------------------------------------
|   NPT_fsopen_utf8
+---------------------------------------------------------------------*/
FILE*
NPT_fsopen_utf8(const char* path, const char* mode, int sh_flags)
{
    NPT_WIN32_USE_CHAR_CONVERSION;
    return _wfsopen(NPT_WIN32_A2W(path), NPT_WIN32_A2W(mode + NPT_String(", ccs=UNICODE")), sh_flags);
}