From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: How coould I know if two files are the same? Date: Fri, 29 Aug 1997 10:39:00 +0200 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 71 Message-ID: <34068AA4.22A0D53E@LSTM.Ruhr-UNI-Bochum.De> References: NNTP-Posting-Host: c64.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit CC: IBEC23 AT cc DOT uab DOT es To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Eli Zaretskii wrote: > > 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. I think this is not correct: stat() invents inodes for networked drives, i.e. it counts upwards from 65536. It remembers which filenames it has seen before, so that two calls to stat() with the identical name yields identical results. In the example above, however, the names are not identical. > > 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. What should work is something like _fixpath(fn1, fixed_fn1); _fixpath(fn2, fixed_fn2); _truename(fixed_fn1,canon_path1); _truename(fixed_fn2,canon_path2); if(!strcmp( canon_path1, canon_path2) ){ puts("Identical files"); } This in fact should work with all network drivers using the Network Redirector. I'm quite surprised that Xavier wrote in a mail to me that this didn't work. From (at least) DOS 6.22 command.com has the built-in command truename, so simply trying C:>truename m:\folder\filename.txt should yield something like \\SERVER\PATH\FOLDER\FILENAME.TXT and C:\>truename x:filename.txt should give the same. -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************