/* rename.c -- rename a file, preserving symlinks.
- Copyright (C) 1999 Free Software Foundation, Inc.
+ Copyright 1999 Free Software Foundation, Inc.
This file is part of GNU Binutils.
#endif /* HAVE_UTIMES */
#endif /* ! HAVE_GOOD_UTIME_H */
+/* We need to open the file in binary modes on system where that makes
+ a difference. */
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
static int simple_copy PARAMS ((const char *, const char *));
/* The number of bytes to copy at once. */
int saved;
char buf[COPY_BUF];
- fromfd = open (from, O_RDONLY);
+ fromfd = open (from, O_RDONLY | O_BINARY);
if (fromfd < 0)
return -1;
+#ifdef O_CREAT
+ tofd = open (to, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0777);
+#else
tofd = creat (to, 0777);
+#endif
if (tofd < 0)
{
saved = errno;
ret = rename (from, to);
if (ret != 0)
{
- /* We have to clean up here. */
-
+ /* We have to clean up here. */
+
non_fatal (_("%s: rename: %s"), to, strerror (errno));
unlink (from);
}
}
else
{
- /* We have to clean up here. */
+ /* We have to clean up here. */
non_fatal (_("%s: rename: %s"), to, strerror (errno));
unlink (from);
}