Mail Archives: cygwin/2006/03/08/17:36:53
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Suppose "foo.tmp" is a symlink, and "foo" is a regular file.
Calling rename("foo.tmp", "foo") results in the very bizarre situation
where, as far as Cygwin is concerned, there are TWO files called "foo"
within the same directory.
Below is a small C program to reproduce this state of affairs.
Max.
=====================================================================
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define M1BAD(x) if ((x) == -1) { handle_error(#x); }
#define ZOK(x) if ((x) != 0) { handle_error(#x); }
static void handle_error(char *op)
{
fprintf(stderr, "E: %s: %s\n", op, strerror(errno));
exit(1);
}
int main(void)
{
int fd;
M1BAD(fd = open("foo", O_CREAT, 0644));
ZOK(close(fd));
ZOK(symlink("nonexistent", "foo.tmp"));
ZOK(rename("foo.tmp", "foo"));
return 0;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
iD8DBQFED1xzfFNSmcDyxYARAt9aAKCYNk2A4N0PNNv/Xi42WEE0h5ZJGgCfYfa/
F/Rm9fGDC1vQJKooGL/cYcs=
=+BiT
-----END PGP SIGNATURE-----
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -