summaryrefslogtreecommitdiff
path: root/gettext-tools/gnulib-tests/dup.c
diff options
context:
space:
mode:
Diffstat (limited to 'gettext-tools/gnulib-tests/dup.c')
-rw-r--r--gettext-tools/gnulib-tests/dup.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/gettext-tools/gnulib-tests/dup.c b/gettext-tools/gnulib-tests/dup.c
index 20f0453..034fcf8 100644
--- a/gettext-tools/gnulib-tests/dup.c
+++ b/gettext-tools/gnulib-tests/dup.c
@@ -1,6 +1,6 @@
/* Duplicate an open file descriptor.
- Copyright (C) 2011-2015 Free Software Foundation, Inc.
+ Copyright (C) 2011-2016 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -45,6 +45,31 @@ dup_nothrow (int fd)
return result;
}
+#elif defined __KLIBC__
+# include <fcntl.h>
+# include <sys/stat.h>
+
+# include <InnoTekLIBC/backend.h>
+
+static int
+dup_nothrow (int fd)
+{
+ int dupfd;
+ struct stat sbuf;
+
+ dupfd = dup (fd);
+ if (dupfd == -1 && errno == ENOTSUP \
+ && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode))
+ {
+ char path[_MAX_PATH];
+
+ /* Get a path from fd */
+ if (!__libc_Back_ioFHToPath (fd, path, sizeof (path)))
+ dupfd = open (path, O_RDONLY);
+ }
+
+ return dupfd;
+}
#else
# define dup_nothrow dup
#endif