summaryrefslogtreecommitdiff
path: root/lib/utimens.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-09-26 23:01:00 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-09-26 23:01:00 +0000
commita6c8a8e6d461e63686572d0489a7f71dc554ecd7 (patch)
tree2d317a7e9439b0aa4db72cfe9d337c02a60a2c5c /lib/utimens.c
parenta49740f33b3657b2f0c7dce7e0d18183f2953011 (diff)
downloadcoreutils-a6c8a8e6d461e63686572d0489a7f71dc554ecd7.tar.xz
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.
Diffstat (limited to 'lib/utimens.c')
-rw-r--r--lib/utimens.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/utimens.c b/lib/utimens.c
index b60ec879a..7f88f2fa9 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -26,6 +26,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
#if HAVE_UTIME_H
# include <utime.h>
@@ -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;
}