Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Core/Path.cpp: the limitation of GetCurrentDirectory for POSIX
Core/Path.cpp: the limitation of GetCurrentDirectory for POSIX [message #31503] Mon, 07 March 2011 12:27 Go to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello all,

Looking in the other projects, I see a limitation in U++ of get GetCurrentDirectory for POSIX.

This changes works perfectly for me for more than 1 month. I propose to implement this or to know motivation why this was done?

OK, Now to the source-code in the file Core/Path.cpp:

The old version:
#ifndef PLATFORM_WINCE
String GetCurrentDirectory() {
#if defined(PLATFORM_WIN32)
	if(IsWinNT()) {
		wchar h[MAX_PATH];
		UnicodeWin32().GetCurrentDirectoryW(MAX_PATH, h);
		return FromSystemCharsetW(h);
	}
	else {
		char h[MAX_PATH];
		::GetCurrentDirectory(MAX_PATH, h);
		return FromSystemCharset(h);
	}
#elif defined(PLATFORM_POSIX)
	char h[1024];
	getcwd(h, 1024);
	return FromSystemCharset(h);
#else
#error GetCurrentDirectory not implemented for this platform, comment this line to get Null
	return Null;
#endif//PLATFORM
}
#endif


and the new version:
#ifndef PLATFORM_WINCE
String GetCurrentDirectory() {
#if defined(PLATFORM_WIN32)
	if(IsWinNT()) {
		wchar h[MAX_PATH];
		UnicodeWin32().GetCurrentDirectoryW(MAX_PATH, h);
		return FromSystemCharsetW(h);
	}
	else {
		char h[MAX_PATH];
		::GetCurrentDirectory(MAX_PATH, h);
		return FromSystemCharset(h);
	}
#elif defined(PLATFORM_POSIX)
	//ILU: propose another get current directory realization
	/*
	char h[1024];
	getcwd(h, 1024);
	return FromSystemCharset(h);
	*/
	char *h = getcwd(NULL, 0);
	String str_final = FromSystemCharset(h);
	free(h);
	return str_final;
#else
#error GetCurrentDirectory not implemented for this platform, comment this line to get Null
	return Null;
#endif//PLATFORM
}
#endif


and a question: why the buffer h was set limited to 1024 chars?



Thank you in advance,
Ion Lupascu.
Re: Core/Path.cpp: the limitation of GetCurrentDirectory for POSIX [message #31506 is a reply to message #31503] Mon, 07 March 2011 16:32 Go to previous message
unknown user
Hi,

See http://linux.die.net/man/3/getcwd
If buf is NULL, the behaviour of getcwd() is undefined.

Andrei
Previous Topic: Optional serialization techniques
Next Topic: Value: why not float support?
Goto Forum:
  


Current Time: Thu Apr 25 08:02:48 CEST 2024

Total time taken to generate the page: 0.05140 seconds