Commit Graph

38 Commits

Author SHA1 Message Date
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
The result of running etc/update-copyright.py --this-year, fixing all
the files whose mode is changed by the script, plus a build with
--enable-maintainer-mode --enable-cgen-maint=yes, then checking
out */po/*.pot which we don't update frequently.

The copy of cgen was with commit d1dd5fcc38ead reverted as that commit
breaks building of bfp opcodes files.
2022-01-02 12:04:28 +10:30
Alan Modra
47fcfcbadc PR28156, rename.c doesn't compile with MinGW
Guard against lack of struct timespec definition.

	PR 28156
	* rename.c (get_stat_atime, get_stat_mtime): Don't compile
	unless HAVE_UTIMENSAT is defined.
2021-08-04 14:44:08 +09:30
Nick Clifton
4dee4f3ea1 Fix compile time warning about unused functions.
binutils * rename.c: (get_stat_atime_ns): Add prototype.
	(get_stat_mtime_ns): Add prototype.
2021-04-19 09:41:04 +01:00
Alan Modra
ad7c46164f undefined reference to get_stat_atime
PR 27725
	* rename.c (get_stat_atime, get_stat_mtime): Make static.
	(get_stat_atime_ns, get_stat_mtime_ns): Likewise.
2021-04-16 12:12:50 +09:30
Pekka Seppänen
4c79248a46 PR27734, get_stat_atime_ns/get_stat_mtime_ns might not use parameter
PR 27725
	* rename.c (get_stat_atime_ns): Add ATTRIBUTE_UNUSED.
	(get_stat_mtime_ns): Likewise.
2021-04-16 00:09:26 +09:30
Alan Modra
985e026451 PR27725, better objcopy -p times
Nanosecond rather than second resolution.

	PR 27725
	* configure.ac: Check for sys/time.h and utimensat.  Use standard
	checks for mkstemp and mkdtemp.  Whitespace.  Check for nanosecond
	members of struct stat.
	* rename.c: Prefer sys/time.h for utimes over utime.h for utime.
	(STAT_TIMESPEC, STAT_TIMESPEC_NS): Define
	(get_stat_atime_ns, get_stat_mtime_ns): New inline functions.
	(get_stat_atime, get_stat_mtime): Likewise.
	(set_times): Choose first available of utimensat, utimes, utime.
	Use above inline functions to set timespec and timeval values.
	* configure: Regenerate.
	* config.in: Regenerate.
	* testsuite/binutils-all/objcopy.exp (objcopy_test): Add test of
	file timestamp when --preserve-dates is used.
2021-04-15 17:51:17 +09:30
Alan Modra
d0ecdcddc3 Make objcopy -p work when an output file is specified
More fallout from the PR27456 fixes.

	PR 27456
	* rename.c (smart_rename): When TO and FROM are equal, just set
	file timestamp.
	* objcopy.c (strip_main, copy_main): Always call smart_rename.
2021-04-15 14:16:55 +09:30
Alan Modra
015dc7e1f8 Use bool in binutils
* sysdep.h (POISON_BFD_BOOLEAN): Define.
	* addr2line.c, * ar.c, * arsup.c, * bfdtest2.c, * binemul.c,
	* binemul.h, * bucomm.c, * bucomm.h, * budbg.h, * coffgrok.c,
	* debug.c, * debug.h, * dlltool.c, * dwarf.c, * dwarf.h,
	* elfedit.c, * emul_aix.c, * mclex.c, * nm.c, * objcopy.c,
	* objdump.c, * od-macho.c, * prdbg.c, * rdcoff.c, * rddbg.c,
	* readelf.c, * rename.c, * stabs.c, * strings.c, * windint.h,
	* windmc.c, * windmc.h, * windres.c, * winduni.c,
	* wrstabs.c: Replace bfd_boolean with bool, FALSE with false,
	and TRUE with true throughout.
2021-03-31 10:49:23 +10:30
Alan Modra
40b02646ec Re: Use make_tempname file descriptor in smart_rename
PR 27456
	* rename.c (simple_copy): Mark target_stat ATTRIBUTE_UNUSED.
2021-02-25 09:48:17 +10:30
Alan Modra
c42c71a152 Use make_tempname file descriptor in smart_rename
This patch makes use of the temp file descriptor in smart_rename
rather than reopening the file.  I don't believe there is a security
issue in reopening the file, but this way is one less directory
operation.  The patch also attempts to preserve S_ISUID and S_ISGID.

	PR 27456
	* bucomm.h (smart_rename): Update prototype.
	* rename.c (smart_rename): Add fromfd and preserve_dates params.
	Pass fromfd and target_stat to simple_copy.  Call set_times
	when preserve_dates.
	(simple_copy): Accept fromfd rather than from filename.  Add
	target_stat param.  Rewind fromfd rather than opening.  Open
	"to" file without O_CREAT.  Try to preserve S_ISUID and S_ISGID.
	* ar.c (write_archive): Rename ofd to tmpfd.  Dup tmpfd before
	closing output temp file, and pass tmpfd to smart_rename.
	* arsup.c (temp_fd): Rename from real_fd.
	(ar_save): Dup temp_fd and pass to smart_rename.
	* objcopy.c (strip_main, copy_main): Likewise, and pass
	preserve_dates.
2021-02-24 09:34:42 +10:30
Alan Modra
cca8873dd5 PR27456, lstat in rename.c on MinGW
PR 27456
	* rename.c: Tidy throughout.
	(smart_rename): Always copy.  Remove windows specific code.
2021-02-24 09:33:01 +10:30
Siddhesh Poyarekar
3685de750e binutils: Avoid renaming over existing files
Renaming over existing files needs additional care to restore
permissions and ownership, which may not always succeed.
Additionally, other properties of the file such as extended attributes
may be lost, making the operation flaky.

For predictable results, resort to rename() only if the file does not
exist, otherwise copy the file contents into the existing file.  This
ensures that no additional tricks are needed to retain file
properties.

This also allows dropping of the redundant set_times on the tmpfile in
objcopy/strip since now we no longer rename over existing files.

binutils/

	* ar.c (write_archive): Remove TARGET_STAT.  Adjust call to
	SMART_RENAME.
	* arsup.c (ar_save): Likewise.
	* objcopy (strip_main): Don't copy TMPFD.  Don't set times on
	temporary file and adjust call to SMART_RENAME.
	(copy_main): Likewise.
	* rename.c [!S_ISLNK]: Remove definitions.
	(try_preserve_permissions): Remove function.
	(smart_rename): Remove FD, PRESERVE_DATES arguments.  Use
	rename system call only if TO does not exist.
	* bucomm.h (smart_rename): Adjust declaration.
2021-02-19 08:05:33 +05:30
Alan Modra
51a2525281 PR27349, ar breaks symlinks
PR 27349
	* rename.c (smart_rename): Test for existence and type of output
	file with lstat.
2021-02-06 07:28:21 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Siddhesh Poyarekar
014cc7f849 binutils: Make smart_rename safe too
smart_rename is capable of handling symlinks by copying and it also
tries to preserve ownership and permissions of files when they're
overwritten during the rename.  This is useful in objcopy where the
file properties need to be preserved.

However because smart_rename does this using file names, it leaves a
race window between renames and permission fixes.  This change removes
this race window by using file descriptors from the original BFDs that
were used to manipulate these files wherever possible.

The file that is to be renamed is also passed as a file descriptor so
that we use fchown/fchmod on the file descriptor, thus making sure
that we only modify the file we have opened to write.  Further, in
case the file is to be overwritten (as is the case in ar or objcopy),
the permissions that need to be restored are taken from the file
descriptor that was opened for input so that integrity of the file
status is maintained all the way through to the rename.

binutils/

	* rename.c
	* ar.c
	(write_archive) [!defined (_WIN32) || defined (__CYGWIN32__)]:
	Initialize TARGET_STAT and OFD to pass to SMART_RENAME.
	* arsup.c
	(ar_save) [defined (_WIN32) || defined (__CYGWIN32__)]:
	Likewise.
	* bucomm.h (smart_rename): Add new arguments to declaration.
	* objcopy.c
	(strip_main)[defined (_WIN32) || defined (__CYGWIN32__)]:
	Initialize COPYFD and pass to SMART_RENAME.
	(copy_main) [defined (_WIN32) || defined (__CYGWIN32__)]:
	Likewise.
	* rename.c (try_preserve_permissions): New function.
	(smart_rename): Use it and add new arguments.
2020-12-07 20:48:33 +05:30
Alan Modra
b3adc24a07 Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
Alan Modra
827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
Alan Modra
219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Alan Modra
2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra
6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Alan Modra
b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Alan Modra
4b95cf5c0c Update copyright years 2014-03-05 22:16:15 +10:30
Alan Modra
dbb7c4414b * sysdep.h: Include sys/stat.h here.
* ar.c: Don't include headers already included by sysdep.h.
	* bucomm.c: Likewise.
	* budbg.h: Likewise.
	* dlltool.h: Likewise.
	* elfedit.c: Likewise.
	* nlmconv.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* objdump.h: Likewise.
	* readelf.c: Likewise.
	* rename.c: Likewise.
	* resrc.c: Likewise.
	* strings.c: Likewise.
	* windres.c: Likewise.
	* od-macho.c: Ensure #include sysdep.h is first.
	* od-xcoff.c: Likewise.
	* dllwrap.c: Remove alloca pragma handled by sysdep.h, and
	remove duplicate headers.
	* dlltool.c: Likewise and ensure #include sysdep.h is first.
2012-02-09 04:51:44 +00:00
Alan Modra
aa820537ea update copyright dates 2009-09-02 07:25:43 +00:00
Alan Modra
216ff8b48e PR 6615
* rename.c (smart_rename): Punctuate error messages.
2008-08-09 13:05:11 +00:00
Nick Clifton
417ed8af83 PR binutils/6449
* objdump.c (slurp_file): Open the file in binary mode.
                * ar.c: Remove conditional definition of O_BINARY.
                * bin2.c: Likewise.
                * rename.c: Likewise.
                * strings.c: Likewise.
                * sysdep.h: Add conditional definition of O_BINARY.
2008-04-28 08:30:23 +00:00
Nick Clifton
32866df75e Change sources over to using GPLv3 2007-07-05 16:54:46 +00:00
Alan Modra
3db64b0092 bfd/
Many files: Include sysdep.h before bfd.h.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
binutils/
	* bucumm.h: Split off host dependencies to..
	* sysdep.h: ..here.
	Many files: Include sysdep.h.  Remove duplicate headers and reorder.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
ld/
	Many files: Include sysdep.h first.  Remove duplicate headers.
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
opcodes/
	* Makefile.am: Run "make dep-am".
	* Makefile.in: Regenerate.
	* ns32k-dis.c: Include sysdep.h first.
2007-04-26 14:47:00 +00:00
Nick Clifton
cbee2975a9 rename.c (simple_copy): Only define if it is going to be used.
(smart_rename): Mark the preserve_dates parameter as possibly	being unused.

resres.c (write_res_data): Prevent a potential compile time warning by casting
  the return value from fwrite.
2005-06-16 09:18:19 +00:00
Nick Clifton
b43b5d5f76 Update FSF address 2005-05-08 14:17:41 +00:00
Nick Clifton
195f52b5ec Ensure that we have write permission before overwriting a file. 2003-11-27 08:24:01 +00:00
Andreas Jaeger
2da42df615 * addr2line.c: Convert to ISO C90 prototypes, change PTR, remove
unneeded (void *) casts.
	* ar.c: Likewise.
	* arlex.l: Likewise.
	* arparse.y: Likewise.
	* arsup.c: Likewise.
	* binemul.c: Likewise.
	* binemul.h: Likewise.
	* bucomm.c: Likewise.
	* bucomm.h: Likewise.
	* budbg.h: Likewise.
	* budemang.c: Likewise.
	* budemang.h: Likewise.
	* coffdump.c: Likewise.
	* coffgrok.c: Likewise.
	* cxxfilt.c: Likewise.
	* debug.c: Likewise.
	* debug.h: Likewise.
	* deflex.l: Likewise.
	* dlltool.c: Likewise.
	* dlltool.h: Likewise.
	* dllwrap.c: Likewise.
	* emul_aix.c: Likewise.
	* filemode.c: Likewise.
	* ieee.c: Likewise.
	* nlmconv.c: Likewise.
	* nlmconv.h: Likewise.
	* nlmheader.y: Likewise.
	* nm.c: Likewise.
	* prdbg.c: Likewise.
	* rclex.l: Likewise.
	* rcparse.y: Likewise.
	* rdcoff.c: Likewise.
	* rddbg.c: Likewise.
	* rename.c: Likewise.
	* resbin.c: Likewise.
	* rescoff.c: Likewise.
	* resrc.c: Likewise.
	* size.c: Likewise.
	* srconv.c: Likewise.
	* stabs.c: Likewise.
	* strings.c: Likewise.
	* sysdump.c: Likewise.
	* sysinfo.y: Likewise.
	* syslex.l: Likewise.
	* unwind-ia64.c: Likewise.
	* unwind-ia64.h: Likewise.
	* version.c: Likewise.
	* windres.c: Likewise.
	* windres.h: Likewise.
	* winduni.c: Likewise.
	* wrstabs.c: Likewise.
2003-09-14 12:20:17 +00:00
Alan Modra
b34976b65a s/boolean/bfd_boolean/ s/true/TRUE/ s/false/FALSE/. Simplify
comparisons of bfd_boolean vars with TRUE/FALSE.  Formatting.
2002-11-30 08:39:46 +00:00
Kazu Hirata
53c7db4bbb * rdcoff.c: Fix formatting.
* rddbg.c: Likewise.
	* readelf.c: Likewise.
	* rename.c: Likewise.
	* resbin.c: Likewise.
	* resrc.c: Likewise.
	* resres.c: Likewise.
2002-05-23 04:11:57 +00:00
Nick Clifton
8c2bc6877d Fix typos in ChangeLogs and update copyright notices 2001-03-13 06:43:59 +00:00
Ian Lance Taylor
18226413df * rename.c (O_BINARY): Define as 0 if not defined.
(simple_copy): Open files with O_BINARY.
1999-06-12 16:04:07 +00:00
Ian Lance Taylor
82716b788e * rename.c (smart_rename): Fix test of whether file exists. 1999-05-06 11:03:33 +00:00
Richard Henderson
252b5132c7 19990502 sourceware import 1999-05-03 07:29:11 +00:00