public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* unexpected rename() behaviour
@ 2008-03-29  0:07 Ketil Froyn
  2008-03-29  0:16 ` J.A. Magallón
  0 siblings, 1 reply; 5+ messages in thread
From: Ketil Froyn @ 2008-03-29  0:07 UTC (permalink / raw)
  To: linux-kernel

Hi,

The following behaviour was unexpected (tested on Debian/ext3):

$ echo 1 > 1
$ ln 1 2
$ cat 2
1
$ ./rename 2 1
$ echo $?
0
$ cat 2
1

The code for ./rename is simple:

---
/* compile: gcc -o rename rename.c */
#include <stdio.h>
int main(int argc, char *argv[]) { return rename(argv[1], argv[2]); }
---

I thought this must be wrong behaviour, but I have been unable to 
confirm what the correct result should be in this special case. rename() 
returns success, but the source file is intact, which seems odd. The 
"mv" command specifically checks for cases like this and calls 
unlink("2") instead of rename("2", "1"). Are all applications meant to 
do this? What standards describe what rename() should do in cases like this?

Regards,
Ketil Froyn

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

end of thread, other threads:[~2008-03-29 12:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-29  0:07 unexpected rename() behaviour Ketil Froyn
2008-03-29  0:16 ` J.A. Magallón
2008-03-29 10:56   ` Ketil Froyn
2008-03-29 12:36     ` Andreas Schwab
2008-03-29 12:57     ` David Newall

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