delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/28/05:24:23

Date: Thu, 28 Aug 1997 12:21:08 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: IBEC23 AT cc DOT uab DOT es
cc: djgpp AT delorie DOT com
Subject: Re: How coould I know if two files are the same?
In-Reply-To: <01IMY1B3EI4I00G6WZ@cc.uab.es>
Message-ID: <Pine.SUN.3.91.970828122008.10704A-100000@is>
MIME-Version: 1.0

On Wed, 27 Aug 1997 IBEC23 AT cc DOT uab DOT es wrote:

> When a network disk drive X:\ is the same as M:\FOLDER,
> my program "believes" that
>   X:\FILENAME.TXT
> is different from
>   M:\FOLDER\FILENAME.TXT
> but it is the same file.
[snip]
> Is there some way to detect it using DJGPP?

Yes, use the library function `_truename'.  It should return the
same canonical string for each of these cases.

Another way would be to call `stat' on both files and compare the
st_dev and st_ino members of struct stat: if both of them are
identical, the two names refer to the same file.

The second way is more portable (since `stat' is a POSIX function,
whereas `_truename' was invented for DJGPP), at least if your program
will need to run on Unix (DOS and MS-Windows compilers usually return
zero st_ino for all files, since Microsoft filesystems don't have
inodes).  The call to `stat' is also much more expensive (in DJGPP),
so if you need to compare hundreds of files, `_truename' would be much
faster.

If any of these two methods doesn't work for you, please post the
details here.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019