Proposal: Add getFullProgName
Simon Marlow
marlowsd at gmail.com
Wed Jun 13 11:05:05 CEST 2012
On 13/06/2012 05:49, Johan Tibell wrote:
> On Tue, Jun 12, 2012 at 8:08 PM, Bardur Arantsson<spam at scientician.net> wrote:
>> Not saying it's not an improvement over getProgName (definitely is), but
>> if the intent is to provide the most accurate name of the executable
>> which is running, then...
>>
>> You should probably read the /proc/self/exe symlink on Linux. (Of course
>> /proc may not be mounted so you'll need a fallback in any case...)
>>
>> I believe FreeBSD and Solaris have similar methods using /proc.
>>
>> On Win32 it seems that using GetModuleFileName with a NULL first
>> parameter is the way to go:
>>
>> http://msdn.microsoft.com/en-us/library/ms683197%28VS.85%29.aspx
>
> Good ideas. If we do that, do we also want a way to access the raw argv[0]?
I suggest we should have a
getExecutablePath :: IO FilePath
in System.Environment. We have an implementation for Windows in GHC
that we use to find GHC's files relative to ghc.exe. This SO question
has some good references for ways to do it on different platforms:
http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
We should also have something in System.Posix to return the original
argv[0], unfortunately we forgot about this when adding
System.Posix.ByteString.getArgs which returns argv[1..].
Maybe
System.Posix.ByteString.getProgName :: IO ByteString
Cheers,
Simon
More information about the Libraries
mailing list