From: Mark Hobley on
I am using Linux.

Is there a C library function to search along a path to locate a file?

Supposing I have an environment variable FOOPATH as follows:

BARPATH=/var/test/dir1:/var/test/dir2:/dirdoesnotexist:/home/fooser

I want to open the file foo.txt, which may be located in one of the
directories in BARPATH.

Is there a library function that will provide that facility, or do I need
to create a buffer, and start slicing and splicing the pathname and filename
from within my program?

This is a core program, so /usr/lib may not yet be mounted when the search
takes place, so ideally a function from a library normally found in the /lib
directory is preferred.

Also, some directories within BARPATH may not yet exist. Will the library
function skip over the non-existent ones?

Mark.

--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/

From: Ramon F Herrera on
On Feb 28, 8:08 pm, markhob...(a)hotpop.donottypethisbit.com (Mark
Hobley) wrote:
> I am using Linux.
>
> Is there a C library function to search along a path to locate a file?
>
> Supposing I have an environment variable FOOPATH as follows:
>
> BARPATH=/var/test/dir1:/var/test/dir2:/dirdoesnotexist:/home/fooser
>
> I want to open the file foo.txt, which may be located in one of the
> directories in BARPATH.
>
> Is there a library function that will provide that facility, or do I need
> to create a buffer, and start slicing and splicing the pathname and filename
> from within my program?
>
> This is a core program, so /usr/lib may not yet be mounted when the search
> takes place, so ideally a function from a library normally found in the /lib
> directory is preferred.
>
> Also, some directories within BARPATH may not yet exist. Will the library
> function skip over the non-existent ones?
>
> Mark.
>
> --
> Mark Hobley
> Linux User: #370818  http://markhobley.yi.org/

An educated guess is that what you want is too specialized. The most
you could find is a path splitter.

-Ramon

From: Barry Margolin on
In article
<9491c2b9-a6ca-47fa-93ad-9055920796ce(a)f8g2000yqn.googlegroups.com>,
Ramon F Herrera <ramon(a)conexus.net> wrote:

> On Feb 28, 8:08�pm, markhob...(a)hotpop.donottypethisbit.com (Mark
> Hobley) wrote:
> > I am using Linux.
> >
> > Is there a C library function to search along a path to locate a file?
> >
> > Supposing I have an environment variable FOOPATH as follows:
> >
> > BARPATH=/var/test/dir1:/var/test/dir2:/dirdoesnotexist:/home/fooser
> >
> > I want to open the file foo.txt, which may be located in one of the
> > directories in BARPATH.
> >
> > Is there a library function that will provide that facility, or do I need
> > to create a buffer, and start slicing and splicing the pathname and filename
> > from within my program?
> >
> > This is a core program, so /usr/lib may not yet be mounted when the search
> > takes place, so ideally a function from a library normally found in the /lib
> > directory is preferred.
> >
> > Also, some directories within BARPATH may not yet exist. Will the library
> > function skip over the non-existent ones?
> >
> > Mark.
> >
> > --
> > Mark Hobley
> > Linux User: #370818 �http://markhobley.yi.org/
>
> An educated guess is that what you want is too specialized. The most
> you could find is a path splitter.

It's actually a pretty common operation (MANPATH, LD_LIBRARY_PATH,
PATH). But AFAIK there's no standard library function to do it.
Perhaps the problem is that each of them has restrictions on the types
of files they're looking for; for instance, when searching MANPATH, it
actually has to go into subdirectories, and append a suffix dependent on
the subdirectory. PATH only cares about executables, and
LD_LIBRARY_PATH allows for a variety of suffixes because of version
numbers.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Ramon F Herrera on
On Feb 28, 9:34 pm, Barry Margolin <bar...(a)alum.mit.edu> wrote:
> In article
> <9491c2b9-a6ca-47fa-93ad-905592079...(a)f8g2000yqn.googlegroups.com>,
>  Ramon F Herrera <ra...(a)conexus.net> wrote:
>
>
>
> > On Feb 28, 8:08 pm, markhob...(a)hotpop.donottypethisbit.com (Mark
> > Hobley) wrote:
> > > I am using Linux.
>
> > > Is there a C library function to search along a path to locate a file?
>
> > > Supposing I have an environment variable FOOPATH as follows:
>
> > > BARPATH=/var/test/dir1:/var/test/dir2:/dirdoesnotexist:/home/fooser
>
> > > I want to open the file foo.txt, which may be located in one of the
> > > directories in BARPATH.
>
> > > Is there a library function that will provide that facility, or do I need
> > > to create a buffer, and start slicing and splicing the pathname and filename
> > > from within my program?
>
> > > This is a core program, so /usr/lib may not yet be mounted when the search
> > > takes place, so ideally a function from a library normally found in the /lib
> > > directory is preferred.
>
> > > Also, some directories within BARPATH may not yet exist. Will the library
> > > function skip over the non-existent ones?
>
> > > Mark.
>
> > > --
> > > Mark Hobley
> > > Linux User: #370818http://markhobley.yi.org/
>
> > An educated guess is that what you want is too specialized. The most
> > you could find is a path splitter.
>
> It's actually a pretty common operation (MANPATH, LD_LIBRARY_PATH,
> PATH).  But AFAIK there's no standard library function to do it.  
> Perhaps the problem is that each of them has restrictions on the types
> of files they're looking for; for instance, when searching MANPATH, it
> actually has to go into subdirectories, and append a suffix dependent on
> the subdirectory.  PATH only cares about executables, and
> LD_LIBRARY_PATH allows for a variety of suffixes because of version
> numbers.
>


I was about to suggest the OP to take a look at the program
"which.exe", Barry.

-Ramon

From: Mark Hobley on
In comp.unix.programmer Ramon F Herrera <ramon(a)conexus.net> wrote:
> An educated guess is that what you want is too specialized. The most
> you could find is a path splitter.

I am shocked that there is no path walker. A path splitter would be of some
help, if there is one.

> I was about to suggest the OP to take a look at the program
> "which.exe", Barry.

On my system which is a shell script. I wonder if there is a C implementation
of it though ...

I looked at the man pager, but the path walker bit was written in perl, and
has the added complication of using an indexed database, rather than a direct
path walk. (even the heirloom version did this).

Mark.

--
Mark Hobley
Linux User: #370818 http://markhobley.yi.org/