comp.lang.ada
 help / color / mirror / Atom feed
* Re: Filename comparison ... HELP NEEDED!
@ 1994-12-05 18:27 Bennett, Chip (KTR) ~U
  0 siblings, 0 replies; 7+ messages in thread
From: Bennett, Chip (KTR) ~U @ 1994-12-05 18:27 UTC (permalink / raw)


In comp.lang.ada you wrote

> Does anybody know of an good solution to seeing if two filenames given
actually
> point at the same file in the file system?  (Probably a solution in C).

You could use stat or lstat to get info about a file that is the same (file
system and inode number) even if the aliases for the file are different.
 Your choice of stat or lstat depends on whether you want symbolic links to
act like "different" files or not.

Also, this can be easily done in Ada using the system interface package
provided with the compiler.  If your compiler doesn't have a UNIX system
interface package (most do), the bindings to stat and lstat and the
conversion of the "C" data structure to Ada is also straight forward.

I agree with another response to this post, that it was inappropriate for
you to splatter the news groups with this question.  However, I think I
saved your good name in THIS group by pointing out the "Ada" aspects.  :-)

*****************************************************************
* Chip Bennett, GDE Systems Inc | BennettC@j64.stratcom.af.mil  *
* USSTRATCOM/J64213             | Voice (402)294-7360           *
* 901 SAC Blvd, Suite 2B24      | FAX   (402)294-7912           *
* Offutt AFB, NE 68113-6600     | Proud member of Team Ada      *
* Opinions expressed here are my own _so_,  TTFWTW              *
*****************************************************************



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Filename comparison ... HELP NEEDED!
@ 1994-12-02 11:40 Nigel Jewell
  1994-12-02 15:14 ` Frank Pilhofer
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nigel Jewell @ 1994-12-02 11:40 UTC (permalink / raw)


Hi,

I apologise if this is irrelevant to any groups posted to, but I want as many
ideas/solutions as possible

I have a _small_ problem with an application that I am trying to write on a UNIX
platform using both C and Ada.  

Basically a user selects a file to load.  This file may point to other files.
For example:

file1:
	$HOME/test/file2
	../file3

file2:
	../file3

file3:

Each of these is loaded recursively therefore when a reference to file3 is seen
the file3 is loaded and processed in the same way.  Therefore I need to be able 
to check if a file has already been loaded.  In this case file3 from both files
1 and 2.

Here is the problem.

What if a user uses $HOME/test/file2 in one file and ~/test/file2 in another
file, I cannot check that the file hasn't already been loaded.  One
solution suggested to me is to scan the filename for environment variables and
then substitute them in the string, using $HOME for the tilde.  This is not
a perfect solution though.  What if the user uses $HOME/test/dir1/../file3 and
$HOME/test/file3 ... do I have to go through and convert every filename checking
for:

environment variables: both $var and ${var}
username specification: e.g ~bob
the use of "." and ".."
links could also cause a problem.

this is a very long winded way of doing it ... and it may cause considerable
delays the more files there are to load.  Also I can't believe there isn't an
easier way than this!

Does anybody know of an good solution to seeing if two filenames given actually
point at the same file in the file system?  (Probably a solution in C).

Any help would be REALLY REALLY appreciated.

Thanks in advance.

Nige.

PS. Replies by email would be prefered.

===============================================================================
E-mail : jewell@cci.de                               Tel. : +49 (0)5931-805-463
     Competence Center Informatik GmbH, Lohberg 10, 49716 Meppen. Germany.

**** Any views expressed may not be those shared by my employer, CCI GmbH. ****
===============================================================================





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1994-12-12 15:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-12-05 18:27 Filename comparison ... HELP NEEDED! Bennett, Chip (KTR) ~U
  -- strict thread matches above, loose matches on Subject: below --
1994-12-02 11:40 Nigel Jewell
1994-12-02 15:14 ` Frank Pilhofer
1994-12-02 16:53 ` Tanmoy Bhattacharya
1994-12-05  8:00   ` Nigel Jewell
1994-12-12  7:50 ` Lachlan Roche
1994-12-12 15:28   ` David Emery

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox