Beispiel #1
0
int env_set_pwd() {
    wcstring res = wgetcwd();
    if (res.empty()) {
        debug(0,
              _(L"Could not determine current working directory. Is your locale set correctly?"));
        return 0;
    }
    env_set(L"PWD", res.c_str(), ENV_EXPORT | ENV_GLOBAL);
    return 1;
}
Beispiel #2
0
int env_set_pwd()
{
    wchar_t dir_path[4096];
    wchar_t *res = wgetcwd(dir_path, 4096);
    if (!res)
    {
        return 0;
    }
    env_set(L"PWD", dir_path, ENV_EXPORT | ENV_GLOBAL);
    return 1;
}
Beispiel #3
0
int env_set_pwd()
{
    wchar_t dir_path[4096];
    wchar_t *res = wgetcwd(dir_path, 4096);
    if (!res)
    {
        debug(0, _(L"Could not determine current working directory. Is your locale set correctly?"));
        return 0;
    }
    env_set(L"PWD", dir_path, ENV_EXPORT | ENV_GLOBAL);
    return 1;
}
	const std::wstring FileSystem::getCurrentDirectory()
	{
		m_currentDirectory = L"";
		wgetcwd(m_currentDirectory, element_of(m_currentDirectory));
		uint32 pathLength = m_currentDirectory.size();
		
		if (pathLength > 1 && (pathLength < element_of(m_currentDirectory) - 2) && (m_currentDirectory[pathLength - 1] != '/' || m_currentDirectory[pathLength - 1] != '\\'))
		{
			m_currentDirectory += L"/";
		}
		
		return m_currentDirectory;
	}
//! Returns the string of the current working directory
const core::string<c16>& CFileSystem::getWorkingDirectory()
{
	EFileSystemType type = FileSystemType;

	if (type != FILESYSTEM_NATIVE)
	{
		type = FILESYSTEM_VIRTUAL;
	}
	else
	{
		const s32 FILE_SYSTEM_MAX_PATH = 1024;
		WorkingDirectory[type].reserve(FILE_SYSTEM_MAX_PATH);
		c16* r = (c16*) WorkingDirectory[type].c_str();

		#if defined(_IRR_USE_WINDOWS_CE_DEVICE_)
		#elif defined(_IRR_WINDOWS_API_)
			#if defined(_IRR_WCHAR_FILESYSTEM )
				_wgetcwd(r, FILE_SYSTEM_MAX_PATH);
			#else
				_getcwd(r, FILE_SYSTEM_MAX_PATH);
			#endif
		#endif

		#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))

			#if defined(_IRR_WCHAR_FILESYSTEM )
				wgetcwd(r, FILE_SYSTEM_MAX_PATH);
			#else
				getcwd(r, (size_t)FILE_SYSTEM_MAX_PATH);
			#endif
		#endif

		WorkingDirectory[type].validate();
	}

	return WorkingDirectory[type];
}
Beispiel #6
0
/**
@SYMTestCaseID          SYSLIB-STDLIB-CT-1047
@SYMTestCaseDesc	    Tests for operations on directory 
@SYMTestPriority 	    High
@SYMTestActions  	    Tests by creating directory with invalid name,existing directory name,wide characters
                        Tests for the error code returned while creating directories.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/		
void make_tree()
	{
	int err;
	char namebuf[MAXPATHLEN], namebuf2[MAXPATHLEN];
	char toobig[MAXPATHLEN+MAXPATHLEN+1];
	char *p;
	wchar_t *wp;

	
	wchar_t widenamebuf[MAXPATHLEN+1];
	wchar_t widename[] = WIDENAME;



	test_Next("Create Directory Tree - relative paths");

	err=mkdir("***", 0777);
	test_errno(err==-1,EINVAL);	/* bad directory name */


	err=mkdir("top", 0777);
	test(err==0);

	err=mkdir("top", 0777);
	test_errno(err==-1,EEXIST);	/* directory already exists */

	
	//make a dir with a wide character in the name
	err = wcstombs(namebuf, widename, MAXPATHLEN);
	test(err!=-1);
	
	err=mkdir(namebuf, 0777);
	test(err==0);
	

	err=mkdir("top/middle1/bottom1", 0777);
	test_errno(err==-1,ENOENT);	/* missing middle bit of path */

	err=mkdir("top/middle1", 0777);
	test(err==0);

	err=chdir("./top//\\/.\\.\\../top/.");
	test(err==0);

	p = getcwd(rootpath,sizeof(rootpath));	/* save name of toplevel directory */
	test(p==rootpath);

	err=chdir("middle1");
	test(err==0);

	err=chdir("bottom2");
	test_errno(err==-1,ENOENT);	/* directory doesn't exist yet */

	p = getcwd(namebuf,sizeof(namebuf));	/* prepare name for tests later */
	test(p==namebuf);

	err=mkdir("bottom1",0777);
	test(err==0);

	err=mkdir("read-only",0444);
	test(err==0);

	err=mkdir("read-only/sub-read-only",0444);
	/* test_errno(err==-1,EACCES); */
	test(err==0);	/* Omission - EPOC32 has Win32 semantics for read-only directories */

	err=chdir("../../top/middle1/bottom1");
	test(err==0);

	test_Next("Create Directory Tree - absolute paths");

	p = strcat(namebuf,"/bottom2");
	test(p==namebuf);	/* .../top/middle1/bottom2 */

	err=chdir(namebuf);
	test_errno(err==-1,ENOENT);	/* directory doesn't exist yet */
	
	err=mkdir(namebuf, 0777);
	test(err==0);

	err=chdir(namebuf);
	test(err==0);

	p = getcwd(namebuf,sizeof(namebuf));
	test(p==namebuf);

	err=mkdir("../../middle2", 0777);
	test(err==0);

	p = getcwd(namebuf2,sizeof(namebuf2));
	test(p==namebuf2);
	test(strcmp(namebuf,namebuf2)==0);	/* mkdir shouldn't change cwd */

	memset(toobig,'a', sizeof(toobig));
	toobig[sizeof(toobig)-1]='\0';

	err=mkdir(toobig,0777);
	test_errno(err<0,ENAMETOOLONG);


	test_Next("Test getcwd");
	
	//size too small
	p = getcwd(namebuf, 4);
	test_errno(0==p, ERANGE);

	//make it alloc a buffer
	p = getcwd(NULL, 300);
	test (NULL != p);
	free(p);

	//alloc a buffer then fail with a too small size
	p = getcwd(NULL, 10);
	test_errno(0==p, ERANGE);

	wp = wgetcwd(widenamebuf, MAXPATHLEN-1);
	test (NULL != wp);

	p = getcwd(namebuf2, MAXPATHLEN-1);
	test (NULL != p);

	wcstombs(namebuf, widenamebuf, MAXPATHLEN-1);
	test(strcmp(namebuf, namebuf2) == 0);
	
	
	//test realpath
	strcpy(namebuf,"bobby.dog");
	test( (0==strcmp("C:\\top\\", realpath("/top/../top/../top/./",namebuf))) || 
		  (0==strcmp("D:\\top\\", realpath("/top/../top/../top/./",namebuf))));

	

}
//! Returns the string of the current working directory
const io::path& CFileSystem::getWorkingDirectory()
{
	EFileSystemType type = FileSystemType;

	if (type != FILESYSTEM_NATIVE)
	{
		type = FILESYSTEM_VIRTUAL;
	}
	else
	{
		#if defined(_IRR_WINDOWS_CE_PLATFORM_)

		#elif defined(_IRR_WINDOWS_API_)
			#if defined(_IRR_WCHAR_FILESYSTEM )
				wchar_t tmp[_MAX_PATH];
				_wgetcwd(tmp, _MAX_PATH);
			#else
				c8 tmp[_MAX_PATH];
				_getcwd(tmp, _MAX_PATH);
			#endif
			WorkingDirectory[FILESYSTEM_NATIVE] = tmp;
		#endif

		#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_))

			//! getting the CWD is rather complex as we do not know the size
			//! so try it until the call was successful
			//! Note that neither the first nor the second parameter may be 0 according to POSIX

			#if defined(_IRR_WCHAR_FILESYSTEM )
				u32 pathSize=256;
				wchar_t *tmpPath = new wchar_t[pathSize];
				while ((pathSize < (1<<16)) && !(wgetcwd(tmpPath,pathSize)))
				{
					delete [] tmpPath;
					pathSize *= 2;
					tmpPath = new char[pathSize];
				}
				if (tmpPath)
				{
					WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
					delete [] tmpPath;
				}
			#else
				u32 pathSize=256;
				char *tmpPath = new char[pathSize];
				while ((pathSize < (1<<16)) && !(getcwd(tmpPath,pathSize)))
				{
					delete [] tmpPath;
					pathSize *= 2;
					tmpPath = new char[pathSize];
				}
				if (tmpPath)
				{
					WorkingDirectory[FILESYSTEM_NATIVE] = tmpPath;
					delete [] tmpPath;
				}
			#endif
		#endif

		WorkingDirectory[type].validate();
	}

	return WorkingDirectory[type];
}
Beispiel #8
0
/**
@SYMTestCaseID          SYSLIB-STDLIB-CT-1092
@SYMTestCaseDesc	    Tests for operations on pipes
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for command line arguments,directory operations,environment variables.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
int do_main(int argc, wchar_t* argv[])
{
    test_Data;
    int i;
    wchar_t* var;
    wchar_t* varname;
    wchar_t cwd[MAXPATHLEN];
    char buf[200];
    char buf1[200];

    test_Title("PIPE");

    test_Next("Command line arguments");
    test(argc>0);
    test(argv!=0);
    printf("  argc=%d\r\n", argc);
    for (i=0; i<argc; i++)
    {
        test(argv[i]!=0);
        test(-1 != wcstombs(buf, argv[i], sizeof(buf)));
        printf("  argv[%d]=\"%s\" length %d\r\n", i, buf, strlen(buf));
    }
    printf("\r\n");

    test_Next("Current working directory");
    var=wgetcwd(cwd,sizeof(cwd)/2);
    test(var==cwd);
    test(-1 != wcstombs(buf, cwd, sizeof(buf)));
    printf("  %s\r\n\n", buf);

    test_Next("Change directory");
    i=wchdir((wchar_t*)L"z:/system");
    test(i==0);
    var=wgetcwd(cwd,sizeof(cwd)/2);
    test(var==cwd);
    test(-1 != wcstombs(buf, cwd, sizeof(buf)));
    printf("  %s\r\n\n", buf);

    test_Next("Environment variables");

    varname=(wchar_t*)L"CLASSPATH";
    var=wgetenv(varname);
    test(var!=0);
    test(-1 != wcstombs(buf, var, sizeof(buf)));
    test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
    printf("  %s=%s\r\n", buf1, buf);

    varname=(wchar_t*)"VARIABLE2";
    var=wgetenv(varname);
    if (var!=0)
    {
        test(-1 != wcstombs(buf, var, sizeof(buf)));
        test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
        printf("  %s=%s\r\n", buf1, buf);
        wunsetenv((wchar_t*)"VARIABLE2");
    }

    varname=(wchar_t*)L"USER";
    var=wgetenv(varname);
    test(var!=0);
    test(-1 != wcstombs(buf, var, sizeof(buf)));
    test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
    printf("  %s=%s\r\n", buf1, buf);

    sleep(5);

    test_Close();
    return 0;
}