> Hello there.
> I tested the following in hp unix as well as Red hat linux.
> I expect rename to fail in the following scenario.
> ===C program====
> main ()
> {
> printf ("rename returns %d\n",
> rename ("a", "b"));
> }
> let us say the compiled output a.out is available
> ======================
> $ touch a
> $ ln a b
> $ mv a b <== This fails and echo $? gives 1
> $ ./a.out <== The output is "rename returns 0"
> Both the files are availble as it is. Thus rename() in a.out should
> have returned -1 as per the man page. Why is this not happening?
The manpage does not agree with you. See below...
SYNOPSIS
#include <stdio.h>
int rename(const char *oldpath, const char *newpath);
DESCRIPTION
rename renames a file, moving it between directories if
required.
Any other hard links to the file (as created using
link(2)) are unaffected.
If newpath already exists it will be atomically replaced
(subject to a few conditions - see ERRORS below), so that
there is no point at which another process attempting to
access newpath will find it missing.
[snip]
Quote:> How does "mv" command identifies this problem and exits with 1?
rename doesn't recognize that there is a problem. It _replaces_ the
existing "b" file with the existing "a" file, renamed to "b".
Quote:> Any sure way to rename "a" to "b" irrespective of what "b" is, using a
> C program?
rename(2)
--
Lew Pitcher
Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.