diff options
Diffstat (limited to 'src/strip.c')
| -rw-r--r-- | src/strip.c | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/src/strip.c b/src/strip.c index f7474418..c114a170 100644 --- a/src/strip.c +++ b/src/strip.c @@ -110,11 +110,11 @@ static int process_file (const char *fname); /* Handle one ELF file. */ static int handle_elf (int fd, Elf *elf, const char *prefix, - const char *fname, mode_t mode, struct timespec tvp[2]); + const char *fname, mode_t mode); /* Handle all files contained in the archive. */ -static int handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, - struct timespec tvp[2]) __attribute__ ((unused)); +static int handle_ar (int fd, Elf *elf, const char *prefix, const char *fname) + __attribute__ ((unused)); static int debug_fd = -1; static char *tmp_debug_fname = NULL; @@ -298,7 +298,6 @@ process_file (const char *fname) now. We cannot use fstat() after opening the file since the open would change the access time. */ struct stat pre_st; - struct timespec tv[2]; again: if (preserve_dates) { @@ -307,15 +306,10 @@ process_file (const char *fname) error (0, errno, gettext ("cannot stat input file '%s'"), fname); return 1; } - - /* If we have to preserve the timestamp, we need it in the - format utimes() understands. */ - tv[0] = pre_st.st_atim; - tv[1] = pre_st.st_mtim; } /* Open the file. */ - int fd = open (fname, output_fname == NULL ? O_RDWR : O_RDONLY); + int fd = open (fname, output_fname == NULL ? (O_RDWR | O_BINARY) : (O_RDONLY | O_BINARY)); if (fd == -1) { error (0, errno, gettext ("while opening '%s'"), fname); @@ -347,8 +341,7 @@ process_file (const char *fname) switch (elf_kind (elf)) { case ELF_K_ELF: - result = handle_elf (fd, elf, NULL, fname, st.st_mode & ACCESSPERMS, - preserve_dates ? tv : NULL); + result = handle_elf (fd, elf, NULL, fname, st.st_mode & 0777); break; case ELF_K_AR: @@ -365,8 +358,7 @@ process_file (const char *fname) /* We would like to support ar archives, but currently it just doesn't work at all since we call elf_clone on the members which doesn't really support ar members. - result = handle_ar (fd, elf, NULL, fname, - preserve_dates ? tv : NULL); + result = handle_ar (fd, elf, NULL, fname); */ error (0, 0, gettext ("%s: no support for stripping archive"), fname); @@ -394,7 +386,7 @@ process_file (const char *fname) static int handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, - mode_t mode, struct timespec tvp[2]) + mode_t mode) { size_t prefix_len = prefix == NULL ? 0 : strlen (prefix); size_t fname_len = strlen (fname) + 1; @@ -440,14 +432,14 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); /* If we are not replacing the input file open a new file here. */ if (output_fname != NULL) { - fd = open (output_fname, O_RDWR | O_CREAT, mode); + fd = open (output_fname, O_RDWR | O_BINARY | O_CREAT, mode); if (unlikely (fd == -1)) { error (0, errno, gettext ("cannot open '%s'"), output_fname); @@ -2006,8 +1998,14 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, /* Create the real output file. First rename, then change the mode. */ - if (rename (tmp_debug_fname, debug_fname) != 0 - || fchmod (debug_fd, mode) != 0) + close (debug_fd); + int rename_result = rename (tmp_debug_fname, debug_fname); + debug_fd = open (debug_fname, O_RDONLY | O_BINARY); + if (rename_result != 0 || debug_fd == -1 +#if HAVE_DECL_FCHMOD + || fchmod (debug_fd, mode) != 0 +#endif + ) { error (0, errno, gettext ("while creating '%s'"), debug_fname); result = 1; @@ -2212,18 +2210,6 @@ while computing checksum for debug information")); cleanup_debug (); - /* If requested, preserve the timestamp. */ - if (tvp != NULL) - { - if (futimens (fd, tvp) != 0) - { - error (0, errno, gettext ("\ -cannot set access and modification date of '%s'"), - output_fname ?: fname); - result = 1; - } - } - /* Close the file descriptor if we created a new file. */ if (output_fname != NULL) close (fd); @@ -2248,8 +2234,7 @@ cleanup_debug (void) } static int -handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, - struct timespec tvp[2]) +handle_ar (int fd, Elf *elf, const char *prefix, const char *fname) { size_t prefix_len = prefix == NULL ? 0 : strlen (prefix); size_t fname_len = strlen (fname) + 1; @@ -2260,7 +2245,7 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); @@ -2275,9 +2260,9 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, Elf_Arhdr *arhdr = elf_getarhdr (subelf); if (elf_kind (subelf) == ELF_K_ELF) - result |= handle_elf (fd, subelf, new_prefix, arhdr->ar_name, 0, NULL); + result |= handle_elf (fd, subelf, new_prefix, arhdr->ar_name, 0); else if (elf_kind (subelf) == ELF_K_AR) - result |= handle_ar (fd, subelf, new_prefix, arhdr->ar_name, NULL); + result |= handle_ar (fd, subelf, new_prefix, arhdr->ar_name); /* Get next archive element. */ cmd = elf_next (subelf); @@ -2285,15 +2270,6 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, INTERNAL_ERROR (fname); } - if (tvp != NULL) - { - if (unlikely (futimens (fd, tvp) != 0)) - { - error (0, errno, gettext ("\ -cannot set access and modification date of '%s'"), fname); - result = 1; - } - } if (unlikely (close (fd) != 0)) error (EXIT_FAILURE, errno, gettext ("while closing '%s'"), fname); |
