X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=lib%2Fdup.c;h=51136db81d6835eca579cb4d183f750290a50597;hb=92249085071a973e2c0621b0415b93d2e48bb00d;hp=564d93ced2701d683bd0d21a7b08485ea5a79e2c;hpb=d57728a6ca2413a7c564d8b7bb13d9e5a5a180f3;p=debian%2Fgzip diff --git a/lib/dup.c b/lib/dup.c index 564d93c..51136db 100644 --- a/lib/dup.c +++ b/lib/dup.c @@ -1,6 +1,6 @@ /* Duplicate an open file descriptor. - Copyright (C) 2011-2013 Free Software Foundation, Inc. + Copyright (C) 2011-2018 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 @@ -13,7 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ #include @@ -22,7 +22,9 @@ #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #undef dup @@ -45,6 +47,31 @@ dup_nothrow (int fd) return result; } +#elif defined __KLIBC__ +# include +# include + +# include + +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