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


C++ GetCurrentDirectoryA函数代码示例

本文整理汇总了C++中GetCurrentDirectoryA函数的典型用法代码示例。如果您正苦于以下问题:C++ GetCurrentDirectoryA函数的具体用法?C++ GetCurrentDirectoryA怎么用?C++ GetCurrentDirectoryA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ResolveIgniteHome

        std::string ResolveIgniteHome(const std::string& path)
        {
            // 1. Check passed argument.
            if (IsValidDirectory(path))
                return path;

            // 2. Check environment variable.
            std::string home = GetEnv(IGNITE_HOME);

            if (IsValidDirectory(home))
                return home;

            // 3. Check current work dir.
            DWORD curDirLen = GetCurrentDirectoryA(0, NULL);

            if (!curDirLen)
                return std::string();

            FixedSizeArray<char> curDir(curDirLen);

            curDirLen = GetCurrentDirectoryA(curDir.GetSize(), curDir.GetData());

            if (!curDirLen)
                return std::string();

            std::string curDirStr(curDir.GetData());

            return ResolveIgniteHome0(curDirStr);
        }
开发者ID:gridgain,项目名称:gridgain,代码行数:29,代码来源:utils.cpp

示例2: error

/// Switches you into a working directory
void Window::cd( char *path )
{
  if( !path )
  {
    error( "You can't change directory to NULL, nothing done" ) ;
    return ;
  }

  // Save the current directory to the stack
  char *cwd = (char*)malloc( MAX_PATH ) ;
  GetCurrentDirectoryA( MAX_PATH, cwd ) ;
  directories.push( cwd ) ;
  
  if( !SetCurrentDirectoryA( path ) )
  {
    error( "Couldn't switch directory to %s", path ) ;
  }
  else
  {
    // This verifies the cd command worked
    char nowDir[MAX_PATH];
    GetCurrentDirectoryA( MAX_PATH, nowDir ) ;
    info( "Current working directory is '%s'", nowDir ) ;
  }
}
开发者ID:sdp0et,项目名称:gtp,代码行数:26,代码来源:WindowClass.cpp

示例3: getcwd

cv::String getcwd()
{
    CV_INSTRUMENT_REGION();
    cv::AutoBuffer<char, 4096> buf;
#if defined WIN32 || defined _WIN32 || defined WINCE
#ifdef WINRT
    return cv::String();
#else
    DWORD sz = GetCurrentDirectoryA(0, NULL);
    buf.allocate((size_t)sz);
    sz = GetCurrentDirectoryA((DWORD)buf.size(), buf.data());
    return cv::String(buf.data(), (size_t)sz);
#endif
#elif defined __linux__ || defined __APPLE__ || defined __HAIKU__ || defined __FreeBSD__
    for(;;)
    {
        char* p = ::getcwd(buf.data(), buf.size());
        if (p == NULL)
        {
            if (errno == ERANGE)
            {
                buf.allocate(buf.size() * 2);
                continue;
            }
            return cv::String();
        }
        break;
    }
    return cv::String(buf.data(), (size_t)strlen(buf.data()));
#else
    return cv::String();
#endif
}
开发者ID:JoeHowse,项目名称:opencv,代码行数:33,代码来源:filesystem.cpp

示例4: GetModuleBase

static ULONG_ADDR CALLBACK GetModuleBase(HANDLE hProcess, ULONG_ADDR dwAddress)
{
    MEMORY_BASIC_INFORMATION memoryInfo;
    ULONG_ADDR dwAddrBase = SymGetModuleBase(hProcess, dwAddress);
    if (dwAddrBase) {
        return dwAddrBase;
    }
    if (VirtualQueryEx(hProcess, (void*)(GC_ULONG_PTR)dwAddress, &memoryInfo,
                       sizeof(memoryInfo))) {
        char filePath[_MAX_PATH];
        char curDir[_MAX_PATH];
        char exePath[_MAX_PATH];
        DWORD size = GetModuleFileNameA((HINSTANCE)memoryInfo.AllocationBase,
                                        filePath, sizeof(filePath));

        /* Save and restore current directory around SymLoadModule, see KB  */
        /* article Q189780.                                                 */
        GetCurrentDirectoryA(sizeof(curDir), curDir);
        GetModuleFileNameA(NULL, exePath, sizeof(exePath));
#if defined(_MSC_VER) && _MSC_VER == 1200
        /* use strcat for VC6 */
        strcat(exePath, "\\..");
#else
        strcat_s(exePath, sizeof(exePath), "\\..");
#endif /* _MSC_VER >= 1200 */
        SetCurrentDirectoryA(exePath);
#ifdef _DEBUG
        GetCurrentDirectoryA(sizeof(exePath), exePath);
#endif
        SymLoadModule(hProcess, NULL, size ? filePath : NULL, NULL,
                      (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase, 0);
        SetCurrentDirectoryA(curDir);
    }
    return (ULONG_ADDR)(GC_ULONG_PTR)memoryInfo.AllocationBase;
}
开发者ID:qykth-git,项目名称:bdwgc,代码行数:35,代码来源:msvc_dbg.c

示例5: fs_GetFullPath

/* take a path with a drive letter, possibly relative, and return a full path
 * without the drive letter.  This is the full path relative to the working
 * dir for that drive letter.  The input and output paths can be the same.
 */
long fs_GetFullPath(char *pathp, char *outPathp, long outSize)
{
	char tpath[1000];
	char origPath[1000];
    char *firstp;
    long code;
    int pathHasDrive;
    int doSwitch;
    char newPath[3];

	if (pathp[0] != 0 && pathp[1] == ':') {
		/* there's a drive letter there */
        firstp = pathp+2;
        pathHasDrive = 1;
    } else {
        firstp = pathp;
		pathHasDrive = 0;
	}

    if (*firstp == '\\' || *firstp == '/') {
		/* already an absolute pathname, just copy it back */
        strcpy(outPathp, firstp);
        return 0;
    }

    GetCurrentDirectoryA(sizeof(origPath), origPath);

	doSwitch = 0;
    if (pathHasDrive && (*pathp & ~0x20) != (origPath[0] & ~0x20)) {
		/* a drive has been specified and it isn't our current drive.
         * to get path, switch to it first.  Must case-fold drive letters
         * for user convenience.
         */
		doSwitch = 1;
        newPath[0] = *pathp;
        newPath[1] = ':';
        newPath[2] = 0;
        if (!SetCurrentDirectoryA(newPath)) {
			code = GetLastError();
            return code;
        }
    }

    /* now get the absolute path to the current wdir in this drive */
    GetCurrentDirectoryA(sizeof(tpath), tpath);
    strcpy(outPathp, tpath+2);	/* skip drive letter */
	/* if there is a non-null name after the drive, append it */
	if (*firstp != 0) {
        strcat(outPathp, "\\");
        strcat(outPathp, firstp);
	}

	/* finally, if necessary, switch back to our home drive letter */
    if (doSwitch) {
        SetCurrentDirectoryA(origPath);
    }

    return 0;
}
开发者ID:chanke,项目名称:openafs-osd,代码行数:63,代码来源:fs_utils.c

示例6: current_path

path current_path() {
	std::vector<char> buffer(GetCurrentDirectoryA(0, NULL));
	DWORD length = GetCurrentDirectoryA(buffer.size(), &buffer.front());
	if(length == 0 || length + 1 >= buffer.size()) {
		buffer[0] = '\0';
	}
	return path(&buffer.front());
}
开发者ID:hulu1528,项目名称:ArxLibertatis,代码行数:8,代码来源:FilesystemWindows.cpp

示例7: snewn

/*
* Get local current directory. Returns a string which must be
* freed.
*/
char *psftp_getcwd(void)
{
   char *ret = snewn(256, char);
   int len = GetCurrentDirectoryA(256, ret);
   if (len > 256)
      ret = sresize(ret, len, char);
   GetCurrentDirectoryA(len, ret);
   return ret;
}
开发者ID:identity0815,项目名称:os45,代码行数:13,代码来源:WINSFTP.C

示例8: CurrentDirectory

std::string CurrentDirectory(void) {
    DWORD bufferLength = 0;
    bufferLength = GetCurrentDirectoryA(0, NULL);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    std::string buffer(bufferLength - 1, '0');
    bufferLength = GetCurrentDirectoryA(bufferLength, &buffer[0]);
    CHECK_WIN_ERROR;
    assert(bufferLength);
    return buffer;
}
开发者ID:plainoldcj,项目名称:nubuck,代码行数:11,代码来源:common.cpp

示例9: iupdrvGetCurrentDirectory

char* iupdrvGetCurrentDirectory(void)
{
  char* cur_dir = NULL;

  int len = GetCurrentDirectoryA(0, NULL);
  if (len == 0) return NULL;

  cur_dir = iupStrGetMemory(len + 2);
  GetCurrentDirectoryA(len + 1, cur_dir);
  cur_dir[len] = '\\';
  cur_dir[len + 1] = 0;

  return cur_dir;
}
开发者ID:mwoz,项目名称:Hildim.Source,代码行数:14,代码来源:iupwindows_info.c

示例10: dbgGetCurrentDirectory

/** Implement the Lua function GetCurrentDirectory().
 * 
 * Discover the current directory name and return it to the caller.
 * 
 * \todo There is a low-probability memory leak here. The buffer used 
 * to hold the current directory string came from malloc() and is held 
 * across a call to lua_pushlstring() which can potentially throw an
 * error, which will leak the allocated buffer. The other bits of Win32
 * API wrappers could have similar issues, and should be inspected.
 * 
 * \param L Lua state context for the function.
 * \returns The number of values on the Lua stack to be returned
 * to the Lua caller.
 */
static int dbgGetCurrentDirectory(lua_State *L)
{
	char *buf = 0;
	DWORD len = 0;
	len = GetCurrentDirectoryA(0,NULL);
	if (!len)
		return luaL_error(L, "GetCurrentDirectory failed (%d)", GetLastError());
	buf = malloc(len+1);
	if (!buf)
		return luaL_error(L,"GetCurrentDirectory can't allocate %ld chars", len);
	GetCurrentDirectoryA(len+1, buf);
	lua_pushlstring(L, buf, len);
	free(buf);
	return 1;
}
开发者ID:luaforge,项目名称:luaservice,代码行数:29,代码来源:LuaMain.c

示例11: CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04_bad

void CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04_bad()
{
    if(STATIC_CONST_TRUE)
    {
        {
            char path[BAD_PATH_SIZE];
            DWORD length;
            length = GetCurrentDirectoryA(BAD_PATH_SIZE, path);
            if (length == 0 || length >= BAD_PATH_SIZE) /* failure conditions for this API call */
            {
                exit(1);
            }
            /* FLAW: PathAppend assumes the 'path' parameter is MAX_PATH */
            /* INCIDENTAL: CWE 121 stack based buffer overflow, which is intrinsic to
             * this example identified on the CWE webpage */
            if (!PathAppendA(path, "AAAAAAAAAAAA"))
            {
                exit(1);
            }
            printSizeTLine(strlen(path));
            printIntLine(BAD_PATH_SIZE);
            printLine(path);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:25,代码来源:CWE785_Path_Manipulation_Function_Without_Max_Sized_Buffer__w32_04.c

示例12: is_a_valid_directory

int
is_a_valid_directory(char* pcszDirectory){
#ifndef WIN32
	struct stat	statbuf;

	if ( pcszDirectory[0] == '\0' )
		return 0;
	
	lstat(pcszDirectory, &statbuf);

	if (S_ISDIR(statbuf.st_mode) == 1){
		return 1;
	}

	write_log(LT_BOTH, "Error: %s is not a valid path!\n", pcszDirectory);
	return 0;
#else
	char		szPath[MAX_PATH];
	int			nRet = 0;

    GetCurrentDirectoryA(MAX_PATH, szPath);
    if ( SetCurrentDirectoryA(pcszDirectory) )
		nRet = 1;
	
    SetCurrentDirectoryA(szPath);
	if ( nRet == 0 )
		write_log(LT_BOTH, "Error: %s is not a valid path!\n",
		pcszDirectory);

	return nRet;
#endif //WIN32
}
开发者ID:pkxpp,项目名称:Study,代码行数:32,代码来源:str_operate.cpp

示例13: test_setdir

/* Routine to test that SetCurrentDirectory behaves as expected. */
static void test_setdir(CHAR *olddir,CHAR *newdir,
                        CHAR *cmprstr, INT pass, const CHAR *errstr)
{
  CHAR tmppath[MAX_PATH], *dirptr;
  DWORD val,len,chklen;

  val=SetCurrentDirectoryA(newdir);
  len=GetCurrentDirectoryA(MAX_PATH,tmppath);
/* if 'pass' then the SetDirectoryA was supposed to pass */
  if(pass) {
    dirptr=(cmprstr==NULL) ? newdir : cmprstr;
    chklen=lstrlenA(dirptr);
    ok(val,"%s: SetCurrentDirectoryA failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(lstrcmpiA(dirptr,tmppath)==0,
       "%s: SetCurrentDirectory did not change the directory, though it passed\n",
       errstr);
    ok(SetCurrentDirectoryA(olddir),
       "%s: Couldn't set directory to it's original value\n",errstr);
  } else {
/* else thest that it fails correctly */
    chklen=lstrlenA(olddir);
    ok(val==0,
       "%s: SetCurrentDirectoryA passed when it should have failed\n",errstr);
    ok(len==chklen,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
    ok(lstrcmpiA(olddir,tmppath)==0,
       "%s: SetCurrentDirectory changed the directory, though it failed\n",
       errstr);
  }
}
开发者ID:howard5888,项目名称:wineT,代码行数:35,代码来源:path.c

示例14: getCurrentDrive

// Get current drive prefix "a:", if any
// This is the same method as used in VC++ CRT.
FXString FXSystem::getCurrentDrive(){
#ifdef WIN32
  FXchar buffer[MAXPATHLEN];
  if(GetCurrentDirectoryA(MAXPATHLEN,buffer) && Ascii::isLetter((FXuchar)buffer[0]) && buffer[1]==':') return FXString(buffer,2);
#endif
  return FXString::null;
  }
开发者ID:Tetimaru,项目名称:LLSIF-Helper,代码行数:9,代码来源:FXSystem.cpp

示例15: getIniValue

bool getIniValue(string filename,string section,string key,string defultValue,string& value){
	

	char lpBuffer[PATH_BUFFER_LENGTH];
	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	DWORD nBufferLength = GetCurrentDirectoryA(
									PATH_BUFFER_LENGTH,
									lpBuffer
								);
	string path = ""; 
	if (!nBufferLength) return false;

	path=lpBuffer;
	path+="\\";
	path+=filename;
	

	ZeroMemory(lpBuffer,PATH_BUFFER_LENGTH);

	nBufferLength=  GetPrivateProfileStringA(						  
						  section.c_str(),
						  key.c_str(),
						  defultValue.c_str(),
						  lpBuffer,
						  PATH_BUFFER_LENGTH,
						  path.c_str()
						);

	if (!nBufferLength) return false;

	value = lpBuffer;
	return true;

}
开发者ID:witwall,项目名称:planetariumfd,代码行数:35,代码来源:ConfigIni.cpp


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