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 » Linux and GetCurrentDirectory
Linux and GetCurrentDirectory [message #33878] Tue, 20 September 2011 23:25 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

GetCurrentDirectory() under linux is obtained via
getcwd(h, 1024)

Unfortunatly this function return a different directory depending whether the program is run typing in consolle or by a double click.
This make a BIG difference if the app run another executable that depends by the "real" current directory, i.e. where the exe file resides.
I wonder if there is a safer and better way under linux to achieve the wanted purpose.

Luigi
Re: Linux and GetCurrentDirectory [message #33879 is a reply to message #33878] Tue, 20 September 2011 23:54 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

GetCurrentDirectory() returns, as the name says, the current directory, which on most non-windows systems is the directory from where the binary was executed, non where it resides. To obtain the position of the binary, there is GetExeFilePath().

Best regards,
Honza

PS: Also, the current directory can change while the program is running.

[Updated on: Wed, 21 September 2011 07:16]

Report message to a moderator

Re: Linux and GetCurrentDirectory [message #33882 is a reply to message #33879] Wed, 21 September 2011 08:54 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
dolik.rce wrote on Tue, 20 September 2011 23:54

GetCurrentDirectory() returns, as the name says, the current directory, which on most non-windows systems is the directory from where the binary was executed, non where it resides. To obtain the position of the binary, there is GetExeFilePath().

Best regards,
Honza

PS: Also, the current directory can change while the program is running.


Ops... Thank you for this precious info!
It means GetExeFilePath() is what I need for both OS when the position of the executable is important to reach other files.

The change of current directory may happen even under windows?

Luigi
Re: Linux and GetCurrentDirectory [message #33883 is a reply to message #33878] Wed, 21 September 2011 09:27 Go to previous message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
Sure, but it can change only by direct action of the executable IIRC (calling change dir). Anyway, current directory doesn't depend on executable path at all.
Previous Topic: read/write to /dev/rtp is happening .. but a small problem
Next Topic: Serialize a VectorMap
Goto Forum:
  


Current Time: Thu Apr 25 17:28:16 CEST 2024

Total time taken to generate the page: 0.03451 seconds