[M3devel] Reasoning for /usr/local/cm3 ?

Jay K jay.krell at cornell.edu
Thu Sep 24 01:25:09 CEST 2009


I don't believe that FS.GetAbsolutePathname(RTArgs.Get(1)) is correct.

 

mkdir /path /cwd

PATH=/path

cp /usr/bin/ls /path

cp /usr/bin/ls /cwd

cd /cwd

ls

 

 

You will return /cwd/ instead of the correct /path/lsh.

The code I have seen to handle this is roundabout.

You have to first check for dots and/or slashes. If they are present, you use GetAbsolutePathname like you do.

Else you split up $PATH on the appropriate character, appending argv[0] to each element and see if it exists and/or is executable.

On Windows that isn't right probably, due to "extensions", however on Windows there is a very simple way, just GetModuleFileName(NULL).

I expect there is a simple way on Mac too.

There might be a way to fish out the dynamic linker parameters on other systems. But I don't think Posix provides a correct simple way.

 

 - Jay

 
> Date: Wed, 23 Sep 2009 13:53:49 -0500
> From: rodney.m.bates at cox.net
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] Reasoning for /usr/local/cm3 ?
> 
> I've had this around for a while. Don't know how portable it is.
> It's mainly a main executable wrapper for, and
> delegates the real work to, FS.GetAbsolutePathname,
> which, if not fully portable, ought to be fixed so it is. 
> 
> It works on LINUXLIBC6 and AMD64_LINUX. 
> 
> It also changes backslashes to forward slashes.
> Maybe better for general script use if it returned
> a return code if things go awry. 
> 
> jay.krell at cornell.edu wrote:
> > Upon further thought symlink might not work. We can make it work on 
> > some systems e.g. Mac and cygwin. Problem I see is, how does one find 
> > the executable's fullpath? If the symlink source is in argv[0] then no 
> > posix portable way. I was looking at this for finding cm3.cfg.
> >
> > -jay/phone
> >
> 
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20090923/9515593f/attachment-0002.html>


More information about the M3devel mailing list