Fix configure dirname. Also streamline dirname usage.
authorNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 11 Jun 2015 19:21:54 +0000 (15:21 -0400)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Thu, 11 Jun 2015 19:21:54 +0000 (15:21 -0400)
commit74a31d33deff58c3b6aa664b3b43ccd53d567426
tree6bc2f7f8ccd69cb858d2d636a08ca71579719e9e
parent7a9be1a3ab4af6745629a3b1f7dbce581461d9e6
Fix configure dirname. Also streamline dirname usage.

POSIX 1003.1 states: "The dirname() function may modify the string
pointed to by path, and may return a pointer to static storage
that may then be overwritten by subsequent calls to dirname()."

Source: http://www.unix.com/man-page/POSIX/3posix/dirname/

Because of this the only sane way of using dirname is to allocate
our own copy of the argument, call dirname and then copy to the
result.

The interesting news is we don't call xdirname anywhere in our
code, yes, not even in Ffile_dirname.  In fact the contract as far
as the '/' termination and behavior on "non directory" is
completely different and actually changing it would break
build-autoloads.el and packages.el (easily fixed), and god knows
what other user code.

* m4/sxe-fs-funs.m4: Remove _SXE_CHECK_DIRNAME_SIDE_EFFECT,
_SXE_CHECK_DIRNAME_RETVAL_OWNER and
_SXE_CHECK_DIRNAME_RETVAL_OWNER tests since the change in xdirname
makes these checks not necessary.

* m4/sxe-fs-funs.m4 (SXE_CHECK_BROKEN_DIRNAME): Remove calls to
_SXE_CHECK_DIRNAME_SIDE_EFFECT, _SXE_CHECK_DIRNAME_RETVAL_OWNER
and _SXE_CHECK_DIRNAME_RETVAL_OWNER.

* src/sysdep.h (x__dirname): Provide only a POSIX-aware usage of
dirname.  This means copying the argument to the result buffer
before calling dirname and the result (if not at start of the
result buffer), using xstrncpy if non-overlapping, memmove if
overlapping.
m4/sxe-fs-funs.m4
src/sysdep.h