LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2002, 10:14 AM   #1
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Rep: Reputation: 30
Resolving file paths...


How do I resolve file paths w/o also resolving symbolic
links (which is what the realpath function does)?
 
Old 10-01-2002, 11:38 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Ehh, when you use realpath() to find the 'resolved path', you are passing it the path you want as it's first argument. So if you are using realpath() you already know the path you are looking for...

(or do I understand you wrong? must be...)
 
Old 10-01-2002, 12:07 PM   #3
ugenn
Member
 
Registered: Apr 2002
Posts: 549

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by Hko
Ehh, when you use realpath() to find the 'resolved path', you are passing it the path you want as it's first argument. So if you are using realpath() you already know the path you are looking for...

(or do I understand you wrong? must be...)
I pass to realpath the relative path name of my symlink
and it returns me the resolved absolute name of the target.

eg.


~/
bar.txt
bar2.txt --> bar2.txt

realpath( "bar2.txt", buf ) (assuming CWD is ~) returns
/home/users/myacc/bar.txt

What I want is to resolve bar2.txt to
/home/users/myacc/bar2.txt
 
Old 10-01-2002, 02:27 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Ah OK,I understand. I didn't think of that.
There would be a problem with such a function. If it exists, that is. I wouldn;t know about any. Sorry.

The problem is that there will always be one, and only one real path, but it's very well possible to have 100 different paths to the same file through several symbolic links. A library function like realpath() only needs to follow all the relative directories (../ ./) and symlinks to find the one and only real path. But to find all possible "un-real" paths such a funtion would need to scan all of the mounted filesystems to search for all symlinks that might lead to your real path, as symlinks are not back-linked. And even then it doesn't know which one of them you would like to know.

So I'm afraid there isn't such a function or any feasible algorythm for that matter to do it. I might be wrong though.

If you are only looking for symlinks to the real file which reside in the same directory, it should be quite possible making your own function which reads all symlinks in the directory where the real file is, and then call realpath() for all of them (probably not too many) and check if which one(s) resolve to the real file.

Last edited by Hko; 10-01-2002 at 02:35 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering a file (taking paths) kornerr Programming 4 05-15-2005 09:22 AM
PHP include() file paths in Apache virtual hosts tawalker Linux - Software 0 09-23-2004 02:16 PM
/etc/hosts resolving before DNS resolving ? markraem Linux - Networking 4 11-02-2003 04:54 AM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 10:15 PM
file paths Mahoot Linux - Newbie 3 09-02-2003 11:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration