summaryrefslogtreecommitdiff
path: root/sed
diff options
context:
space:
mode:
authorPaolo Bonzini <bonzini@gnu.org>2007-08-14 13:26:47 +0000
committerPaolo Bonzini <bonzini@gnu.org>2008-01-09 16:12:28 +0100
commit95792f701c5797ae07f5784f1b5cc989355be7ff (patch)
treec845c90940389e77d148a9d173e6fb40fb661b3c /sed
parent235425fdd4f54bd19fffda8e7775e573e7d6e914 (diff)
downloadsed-95792f701c5797ae07f5784f1b5cc989355be7ff.tar.gz
fix cross-device links with --follow-symlinks
2007-08-14 Paolo Bonzini <bonzini@gnu.org> * sed/execute.c (open_next_file): Follow symlink here... (closedown): ... not here. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-96
Diffstat (limited to 'sed')
-rw-r--r--sed/execute.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/sed/execute.c b/sed/execute.c
index e33c7f8..490d3b7 100644
--- a/sed/execute.c
+++ b/sed/execute.c
@@ -707,16 +707,20 @@ open_next_file(name, input)
if (in_place_extension)
{
int input_fd, output_fd;
- char *tmpdir = ck_strdup(name), *p;
+ char *tmpdir, *p;
struct stat st;
+ if (follow_symlinks)
+ input->in_file_name = follow_symlink (name);
+ else
+ input->in_file_name = name;
+
/* get the base name */
+ tmpdir = ck_strdup(input->in_file_name);
if (p = strrchr(tmpdir, '/'))
*(p + 1) = 0;
else
strcpy(tmpdir, ".");
-
- input->in_file_name = name;
if (isatty (fileno (input->fp)))
panic(_("couldn't edit %s: is a terminal"), input->in_file_name);
@@ -762,11 +766,7 @@ closedown(input)
const char *target_name;
ck_fclose (output_file.fp);
- if (follow_symlinks)
- target_name = follow_symlink (input->in_file_name);
- else
- target_name = input->in_file_name;
-
+ target_name = input->in_file_name;
if (strcmp(in_place_extension, "*") != 0)
{
char *backup_file_name = get_backup_file_name(target_name);