looking for searchpath function
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > looking for searchpath function




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    looking for searchpath function  
Mohun Biswas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:21 PM

Is there a standard C function, either in the classic Unix API or freely
available elsewhere, to search $PATH for a given executable file? This
seems like a really basic thing and not hard to do - in fact I've just
written my own - but I can't shake the feeling that there must be a more
standard, robust, and general-purpose solution out there.

I'm looking for basically the shell "whence" (or "which") function at
the C-library level. The ideal tool would let you specify the path (so
you could search MANPATH or LD_LIBRARY_PATH) and a filter (so you could
say "only find executable files" or "only find readable files").

Thanks,
MB






[ Post a follow-up to this message ]



    Re: looking for searchpath function  
Mohun Biswas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10:21 PM

Maurizio Loreti wrote:
quote:
> You may homebrew your own; "getenv" to get the environment variable, > "strtok" to get every component, "access" to test for the file.
I *did* say, in the sentence right after the one you quoted, that I've just finished writing my own. The point is, though it's easy to write it's not so easy to be sure you have a robust, portable implementation till a few years and platforms have gone by and a few bugs found. There are special cases involving empty path entries (":" appearing at beginning or end, or consecutively) and potential issues with symlinks and permissions and special files and NFS and .... By analogy: I could write my own getcwd() function. It's not hard, in concept. In practice it's much better to use a standard, well-tested, builtin function. That's why we have libraries. MB




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:29 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register