From: Paul Eggert Date: Mon, 26 Sep 2005 23:01:00 +0000 (+0000) Subject: Include unistd.h, for dup2. X-Git-Tag: v5.90~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6c8a8e6d461e63686572d0489a7f71dc554ecd7;p=thirdparty%2Fcoreutils.git Include unistd.h, for dup2. (futimens): Fix typo: HAVE_FUTIMESAT was misspelled in an #if. (futimens) [! HAVE_FUTIMESAT]: If !file, set errno before returning -1. --- diff --git a/lib/utimens.c b/lib/utimens.c index b60ec879a3..7f88f2fa96 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -26,6 +26,7 @@ #include #include +#include #if HAVE_UTIME_H # include @@ -113,11 +114,24 @@ futimens (int fd ATTRIBUTE_UNUSED, # endif #endif -#if ! HAVE_FUTIMES_AT +#if ! HAVE_FUTIMESAT if (!file) { +# if ! (HAVE_WORKING_UTIMES && HAVE_FUTIMES) errno = ENOSYS; +# endif + + /* Prefer EBADF to ENOSYS if both error numbers apply. */ + if (errno == ENOSYS) + { + int fd2 = dup (fd); + int dup_errno = errno; + if (0 <= fd2) + close (fd2); + errno = (fd2 < 0 && dup_errno == EBADF ? EBADF : ENOSYS); + } + return -1; }