当前位置: 首页>>代码示例>>C++>>正文


C++ PathCharString::OpenStringBuffer方法代码示例

本文整理汇总了C++中PathCharString::OpenStringBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ PathCharString::OpenStringBuffer方法的具体用法?C++ PathCharString::OpenStringBuffer怎么用?C++ PathCharString::OpenStringBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PathCharString的用法示例。


在下文中一共展示了PathCharString::OpenStringBuffer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WideCharToMultiByte

BOOL
PAL_GetPALDirectoryA(PathCharString& lpDirectoryName)
{
    BOOL bRet;
    PathWCharString directory;

    PERF_ENTRY(PAL_GetPALDirectoryA);

    bRet = PAL_GetPALDirectoryW(directory);

    if (bRet) 
    {
        
        int length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, NULL, 0, NULL, 0);
        LPSTR DirectoryName = lpDirectoryName.OpenStringBuffer(length);
        if (NULL == DirectoryName)
        {
            SetLastError( ERROR_INSUFFICIENT_BUFFER );
            bRet = FALSE;
        }
        
        length = WideCharToMultiByte(CP_ACP, 0, directory.GetString(), -1, DirectoryName, length, NULL, 0);

        if (0 == length)
        {
            bRet = FALSE;
            length++;
        }
    
        lpDirectoryName.CloseBuffer(length - 1);
    }

    PERF_EXIT(PAL_GetPALDirectoryA);
    return bRet;
}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:35,代码来源:miscpalapi.cpp

示例2: strlen

/*++
Function :

PAL_BindResources - bind the resource domain to the path where the coreclr resides

Returns TRUE if it succeeded, FALSE if it failed due to OOM
--*/
BOOL
PALAPI
PAL_BindResources(IN LPCSTR lpDomain)
{
#if HAVE_LIBINTL_H
    _ASSERTE(g_szCoreCLRPath != NULL);
    char * coreCLRDirectoryPath;
    PathCharString coreCLRDirectoryPathPS;
    int len = strlen(g_szCoreCLRPath);
    coreCLRDirectoryPath = coreCLRDirectoryPathPS.OpenStringBuffer(len);
    if (NULL == coreCLRDirectoryPath)
    {
        return FALSE;
    }
    DWORD size = FILEGetDirectoryFromFullPathA(g_szCoreCLRPath, len, coreCLRDirectoryPath);
    coreCLRDirectoryPathPS.CloseBuffer(size);

    LPCSTR boundPath = bindtextdomain(lpDomain, coreCLRDirectoryPath);

    return boundPath != NULL;
#else // HAVE_LIBINTL_H
    // UNIXTODO: Implement for Unixes without libintl if necessary
    return TRUE;
#endif // HAVE_LIBINTL_H
}
开发者ID:Hasithaerathna,项目名称:coreclr,代码行数:32,代码来源:unicode.cpp

示例3: strlen

/*++
Function :

PAL_BindResources - bind the resource domain to the path where the coreclr resides

Returns TRUE if it succeeded, FALSE if it failed due to OOM
--*/
BOOL
PALAPI
PAL_BindResources(IN LPCSTR lpDomain)
{
#ifndef __APPLE__
    _ASSERTE(g_szCoreCLRPath != NULL);
    char * coreCLRDirectoryPath;
    PathCharString coreCLRDirectoryPathPS;
    int len = strlen(g_szCoreCLRPath);
    coreCLRDirectoryPath = coreCLRDirectoryPathPS.OpenStringBuffer(len);
    if (NULL == coreCLRDirectoryPath)
    {
        return FALSE;
    }
    DWORD size = FILEGetDirectoryFromFullPathA(g_szCoreCLRPath, len, coreCLRDirectoryPath);
    coreCLRDirectoryPathPS.CloseBuffer(size);
    _ASSERTE(size <= MAX_LONGPATH);

    LPCSTR boundPath = bindtextdomain(lpDomain, coreCLRDirectoryPath);

    return boundPath != NULL;
#else // __APPLE__
    // UNIXTODO: Implement for OSX if necessary
    return TRUE;
#endif // __APPLE__
}
开发者ID:blackdwarf,项目名称:coreclr,代码行数:33,代码来源:unicode.cpp

示例4: ASSERT

/*++
Function:
LoadLibraryExW

See MSDN doc.
--*/
HMODULE
PALAPI
LoadLibraryExW(
    IN LPCWSTR lpLibFileName,
    IN /*Reserved*/ HANDLE hFile,
    IN DWORD dwFlags)
{
    if (dwFlags != 0) 
    {
        // UNIXTODO: Implement this!
        ASSERT("Needs Implementation!!!");
        return nullptr;
    }
    
    CHAR * lpstr;
    INT name_length;
    PathCharString pathstr;
    HMODULE hModule = nullptr;

    PERF_ENTRY(LoadLibraryExW);
    ENTRY("LoadLibraryExW (lpLibFileName=%p (%S)) \n",
          lpLibFileName ? lpLibFileName : W16_NULLSTRING,
          lpLibFileName ? lpLibFileName : W16_NULLSTRING);

    if (!LOADVerifyLibraryPath(lpLibFileName))
    {
        goto done;
    }

    lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
    if (nullptr == lpstr)
    {
        goto done;
    }
    if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
    {
        goto done;
    }

    /* do the Dos/Unix conversion on our own copy of the name */
    FILEDosToUnixPathA(lpstr);
    pathstr.CloseBuffer(name_length);

    /* let LOADLoadLibrary call SetLastError in case of failure */
    hModule = LOADLoadLibrary(lpstr, TRUE);

done:
    LOGEXIT("LoadLibraryExW returns HMODULE %p\n", hModule);
    PERF_EXIT(LoadLibraryExW);
    return hModule;
}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:57,代码来源:module.cpp

示例5: if

/*++
Function:
  GetCurrentDirectoryA

--*/
DWORD
GetCurrentDirectoryA(PathCharString& lpBuffer)
{
    DWORD dwDirLen = 0;
    DWORD dwLastError = 0;

    char  *current_dir;

    PERF_ENTRY(GetCurrentDirectoryA);
    ENTRY("GetCurrentDirectoryA(lpBuffer=%p)\n", lpBuffer.GetString());

    current_dir = lpBuffer.OpenStringBuffer(MAX_PATH);
    /* NULL first arg means getcwd will allocate the string */
    current_dir = PAL__getcwd( current_dir, MAX_PATH);

    if (current_dir != NULL )
    {
        dwDirLen = strlen( current_dir );
        lpBuffer.CloseBuffer(dwDirLen);
        goto done;
    }
    else if ( errno == ERANGE )
    {
        lpBuffer.CloseBuffer(0);
        current_dir = PAL__getcwd( NULL, 0);
    }

    if ( !current_dir )
    {
        WARN("Getcwd failed with errno=%d [%s]\n", errno, strerror(errno));
        dwLastError = DIRGetLastErrorFromErrno();
        dwDirLen = 0;
        goto done;
    }

    dwDirLen = strlen( current_dir );
    lpBuffer.Set(current_dir, dwDirLen);
    PAL_free(current_dir);
done:

    if ( dwLastError )
    {
        SetLastError(dwLastError);
    }

    LOGEXIT("GetCurrentDirectoryA returns DWORD %u\n", dwDirLen);
    PERF_EXIT(GetCurrentDirectoryA);
    return dwDirLen;
}
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:54,代码来源:directory.cpp

示例6: failure

/*
Function:
  PAL_RegisterLibraryDirect

  Registers a system handle to a loaded library with the module list.

  Returns a PAL handle to the loaded library, or nullptr upon failure (error is set via SetLastError()).
*/
HMODULE
PALAPI
PAL_RegisterLibraryDirect(
    IN void *dl_handle,
    IN LPCWSTR lpLibFileName)
{
    PathCharString pathstr;
    CHAR * lpstr = nullptr;
    INT name_length;
    HMODULE hModule = nullptr;

    PERF_ENTRY(RegisterLibraryDirect);
    ENTRY("RegisterLibraryDirect (lpLibFileName=%p (%S)) \n",
        lpLibFileName ? lpLibFileName : W16_NULLSTRING,
        lpLibFileName ? lpLibFileName : W16_NULLSTRING);

    if (!LOADVerifyLibraryPath(lpLibFileName))
    {
        goto done;
    }

    lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
    if (nullptr == lpstr)
    {
        goto done;
    }
    if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
    {
        goto done;
    }

    /* do the Dos/Unix conversion on our own copy of the name */
    FILEDosToUnixPathA(lpstr);
    pathstr.CloseBuffer(name_length);

    /* let LOADRegisterLibraryDirect call SetLastError in case of failure */
    LockModuleList();
    hModule = LOADRegisterLibraryDirect((void *)dl_handle, lpstr, true /* fDynamic */);
    UnlockModuleList();

done:
    LOGEXIT("RegisterLibraryDirect returns HMODULE %p\n", hModule);
    PERF_EXIT(RegisterLibraryDirect);
    return hModule;
}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:53,代码来源:module.cpp

示例7: ENTRY

PALAPI
PAL_LoadLibraryDirect(
    IN LPCWSTR lpLibFileName)
{
    PathCharString pathstr;
    CHAR * lpstr = nullptr;
    INT name_length;
    void *dl_handle = nullptr;

    PERF_ENTRY(LoadLibraryDirect);
    ENTRY("LoadLibraryDirect (lpLibFileName=%p (%S)) \n",
          lpLibFileName ? lpLibFileName : W16_NULLSTRING,
          lpLibFileName ? lpLibFileName : W16_NULLSTRING);

    if (!LOADVerifyLibraryPath(lpLibFileName))
    {
        goto done;
    }
    
    lpstr = pathstr.OpenStringBuffer((PAL_wcslen(lpLibFileName)+1) * MaxWCharToAcpLength);
    if (nullptr == lpstr)
    {
        goto done;
    }
    if (!LOADConvertLibraryPathWideStringToMultibyteString(lpLibFileName, lpstr, &name_length))
    {
        goto done;
    }

    /* do the Dos/Unix conversion on our own copy of the name */
    FILEDosToUnixPathA(lpstr);
    pathstr.CloseBuffer(name_length);

    dl_handle = LOADLoadLibraryDirect(lpstr);

done:
    LOGEXIT("LoadLibraryDirect returns HMODULE %p\n", dl_handle);
    PERF_EXIT(LoadLibraryDirect);
    return dl_handle;
}
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:40,代码来源:module.cpp

示例8: ENTRY

/*++
Function:
  SetCurrentDirectoryW

See MSDN doc.
--*/
BOOL
PALAPI
SetCurrentDirectoryW(
            IN LPCWSTR lpPathName)
{
    BOOL bRet;
    DWORD dwLastError = 0;
    PathCharString dirPathString;
    int  size;
    size_t length;
    char * dir;
    
    PERF_ENTRY(SetCurrentDirectoryW);
    ENTRY("SetCurrentDirectoryW(lpPathName=%p (%S))\n",
          lpPathName?lpPathName:W16_NULLSTRING,
          lpPathName?lpPathName:W16_NULLSTRING);

   /*check if the given path is null. If so
     return FALSE*/
    if (lpPathName == NULL )
    {
        ERROR("Invalid path/directory name\n");
        dwLastError = ERROR_INVALID_NAME;
        bRet = FALSE;
        goto done;
    }

    length = (PAL_wcslen(lpPathName)+1) * 3;
    dir = dirPathString.OpenStringBuffer(length);
    if (NULL == dir)
    {
        dwLastError = ERROR_NOT_ENOUGH_MEMORY;
        bRet = FALSE;
        goto done;
    }
    
    size = WideCharToMultiByte( CP_ACP, 0, lpPathName, -1, dir, length,
                                NULL, NULL );
    dirPathString.CloseBuffer(size);
    
    if( size == 0 )
    {
        dwLastError = GetLastError();
        if( dwLastError == ERROR_INSUFFICIENT_BUFFER )
        {
            WARN("lpPathName is larger than MAX_LONGPATH (%d)!\n", MAX_LONGPATH);
            dwLastError = ERROR_FILENAME_EXCED_RANGE;
        }
        else
        {
            ASSERT("WideCharToMultiByte failure! error is %d\n", dwLastError);
            dwLastError = ERROR_INTERNAL_ERROR;
        }
        bRet = FALSE;
        goto done;
    }

    bRet = SetCurrentDirectoryA(dir);
done:
    if( dwLastError )
    {
        SetLastError(dwLastError);
    }

    LOGEXIT("SetCurrentDirectoryW returns BOOL %d\n", bRet);
    PERF_EXIT(SetCurrentDirectoryW);
    return bRet;
}
开发者ID:Rastaban,项目名称:ChakraCore,代码行数:74,代码来源:directory.cpp

示例9: EnsureDirectoryExists

bool SharedMemoryHelpers::EnsureDirectoryExists(
    const char *path,
    bool isGlobalLockAcquired,
    bool createIfNotExist,
    bool isSystemDirectory)
{
    _ASSERTE(path != nullptr);
    _ASSERTE(!(isSystemDirectory && createIfNotExist)); // should not create or change permissions on system directories
    _ASSERTE(SharedMemoryManager::IsCreationDeletionProcessLockAcquired());
    _ASSERTE(!isGlobalLockAcquired || SharedMemoryManager::IsCreationDeletionFileLockAcquired());

    // Check if the path already exists
    struct stat statInfo;
    int statResult = stat(path, &statInfo);
    if (statResult != 0 && errno == ENOENT)
    {
        if (!createIfNotExist)
        {
            return false;
        }

        // The path does not exist, create the directory. The permissions mask passed to mkdir() is filtered by the process'
        // permissions umask, so mkdir() may not set all of the requested permissions. We need to use chmod() to set the proper
        // permissions. That creates a race when there is no global lock acquired when creating the directory. Another user's
        // process may create the directory and this user's process may try to use it before the other process sets the full
        // permissions. In that case, create a temporary directory first, set the permissions, and rename it to the actual
        // directory name.

        if (isGlobalLockAcquired)
        {
            if (mkdir(path, PermissionsMask_AllUsers_ReadWriteExecute) != 0)
            {
                throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
            }
            if (chmod(path, PermissionsMask_AllUsers_ReadWriteExecute) != 0)
            {
                rmdir(path);
                throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
            }
            return true;
        }

        PathCharString tempPath;
        BuildSharedFilesPath(tempPath, SHARED_MEMORY_UNIQUE_TEMP_NAME_TEMPLATE);

        if (mkdtemp(tempPath.OpenStringBuffer()) == nullptr)
        {
            throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
        }
        if (chmod(tempPath, PermissionsMask_AllUsers_ReadWriteExecute) != 0)
        {
            rmdir(tempPath);
            throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
        }
        if (rename(tempPath, path) == 0)
        {
            return true;
        }

        // Another process may have beaten us to it. Delete the temp directory and continue to check the requested directory to
        // see if it meets our needs.
        rmdir(tempPath);
        statResult = stat(path, &statInfo);
    }

    // If the path exists, check that it's a directory
    if (statResult != 0 || !(statInfo.st_mode & S_IFDIR))
    {
        throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
    }

    if (isSystemDirectory)
    {
        // For system directories (such as TEMP_DIRECTORY_PATH), require sufficient permissions only for the
        // current user. For instance, "docker run --mount ..." to mount /tmp to some directory on the host mounts the
        // destination directory with the same permissions as the source directory, which may not include some permissions for
        // other users. In the docker container, other user permissions are typically not relevant and relaxing the permissions
        // requirement allows for that scenario to work without having to work around it by first giving sufficient permissions
        // for all users.
        if ((statInfo.st_mode & PermissionsMask_CurrentUser_ReadWriteExecute) == PermissionsMask_CurrentUser_ReadWriteExecute)
        {
            return true;
        }
        throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
    }

    // For non-system directories (such as gSharedFilesPath/SHARED_MEMORY_RUNTIME_TEMP_DIRECTORY_NAME),
    // require sufficient permissions for all users and try to update them if requested to create the directory, so that
    // shared memory files may be shared by all processes on the system.
    if ((statInfo.st_mode & PermissionsMask_AllUsers_ReadWriteExecute) == PermissionsMask_AllUsers_ReadWriteExecute)
    {
        return true;
    }
    if (!createIfNotExist || chmod(path, PermissionsMask_AllUsers_ReadWriteExecute) != 0)
    {
        throw SharedMemoryException(static_cast<DWORD>(SharedMemoryError::IO));
    }
    return true;
}
开发者ID:A-And,项目名称:coreclr,代码行数:99,代码来源:sharedmemory.cpp

示例10: ENTRY

/*++
Function:
  CreateDirectoryA

Note:
  lpSecurityAttributes always NULL.

See MSDN doc.
--*/
BOOL
PALAPI
CreateDirectoryA(
    IN LPCSTR lpPathName,
    IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
{
    BOOL  bRet = FALSE;
    DWORD dwLastError = 0;
    PathCharString realPath;
    char* realPathBuf;
    LPSTR unixPathName = NULL;
    int pathLength;
    int i;
    const int mode = S_IRWXU | S_IRWXG | S_IRWXO;

    PERF_ENTRY(CreateDirectoryA);
    ENTRY("CreateDirectoryA(lpPathName=%p (%s), lpSecurityAttr=%p)\n",
          lpPathName?lpPathName:"NULL",
          lpPathName?lpPathName:"NULL", lpSecurityAttributes);

    if ( lpSecurityAttributes )
    {
        ASSERT("lpSecurityAttributes is not NULL as it should be\n");
        dwLastError = ERROR_INVALID_PARAMETER;
        goto done;
    }

    // Windows returns ERROR_PATH_NOT_FOUND when called with NULL.
    // If we don't have this check, strdup(NULL) segfaults.
    if (lpPathName == NULL)
    {
        ERROR("CreateDirectoryA called with NULL pathname!\n");
        dwLastError = ERROR_PATH_NOT_FOUND;
        goto done;
    }

    unixPathName = PAL__strdup(lpPathName);
    if (unixPathName == NULL )
    {
        ERROR("PAL__strdup() failed\n");
        dwLastError = ERROR_NOT_ENOUGH_MEMORY;
        goto done;
    }
    FILEDosToUnixPathA( unixPathName );
    // Remove any trailing slashes at the end because mkdir might not
    // handle them appropriately on all platforms.
    pathLength = strlen(unixPathName);
    i = pathLength;
    while(i > 1)
    {
        if(unixPathName[i - 1] =='/')
        {
            unixPathName[i - 1]='\0';
            i--;
        }
        else
        {
            break;
        }
    }


    // Get an absolute path.
    if (unixPathName[0] == '/')
    {
        realPathBuf = unixPathName;
    }
    else
    {

        DWORD len = GetCurrentDirectoryA(realPath);
        if (len == 0 || !realPath.Reserve(realPath.GetCount() + pathLength + 1 ))
        {
            dwLastError = DIRGetLastErrorFromErrno();
            WARN("Getcwd failed with errno=%d \n", dwLastError);
            goto done;
        }

        realPath.Append("/", 1);
        realPath.Append(unixPathName, pathLength);
        realPathBuf = realPath.OpenStringBuffer(realPath.GetCount());
    }

    // Canonicalize the path so we can determine its length.
    FILECanonicalizePath(realPathBuf);

    if ( mkdir(realPathBuf, mode) != 0 )
    {
        TRACE("Creation of directory [%s] was unsuccessful, errno = %d.\n",
              unixPathName, errno);

//.........这里部分代码省略.........
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:101,代码来源:directory.cpp


注:本文中的PathCharString::OpenStringBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。