From patchwork Fri Aug 9 07:15:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1144455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506557-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="L0RBugB6"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 464c3S0cSjz9sND for ; Fri, 9 Aug 2019 17:16:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=XSv9rSOfovo59/vcdgb6FU1RIcIdkk+jTikYHanm2jUbS0icPX mLBqCqI5G9UWcoBaMBuXawsBMUR+H+RmAF0ougCBe9NaOPLg1iHOqr+BPCvLgJGI Z9y3c0pMlz8s9ysM+jYm94k/I05KMOt4oIOLsD5+QK9/78CXO4vwcUppw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=KATTHh2Cnlks8D1t9YQwHyUQw4I=; b=L0RBugB60N3+R9Fb4Ss3 9c2IU3cw+F0iD7eN7Q2XWr8ux6YkUcUhqbNVicZjSKdoPYup4mGfemtLR+g54xAP bgVE98a5047ljy6ZhA5hyZlHYjVKwXDNkytBrusLwzYlQJF1DMXDe3Kj0W9oZK+n 7FU0PwRg2Ym//J0j4+VMGW4= Received: (qmail 49209 invoked by alias); 9 Aug 2019 07:15:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 49023 invoked by uid 89); 9 Aug 2019 07:15:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Aug 2019 07:15:22 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BD8AAAEAC; Fri, 9 Aug 2019 07:15:18 +0000 (UTC) From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] Move is_valid_fd to filedescriptor.c file. To: gcc-patches@gcc.gnu.org Cc: Jakub Jelinek , Ian Lance Taylor Message-ID: Date: Fri, 9 Aug 2019 09:15:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi. As Jakub correctly noted, I used a piggy backing to put the new function to a file that is supposed to contain different functions. So that I'm suggesting a new file. Moreover, I'm also adding dup2 fallback. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin libiberty/ChangeLog: 2019-08-08 Martin Liska * Makefile.in: Add filedescriptor.c. * filedescriptor.c: New file. * lrealpath.c (is_valid_fd): Remove. --- libiberty/Makefile.in | 14 +++++++++++- libiberty/filedescriptor.c | 47 ++++++++++++++++++++++++++++++++++++++ libiberty/lrealpath.c | 16 ------------- 3 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 libiberty/filedescriptor.c diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index 0be45b4ae8e..f1628d4ee0d 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -127,7 +127,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \ calloc.c choose-temp.c clock.c concat.c cp-demangle.c \ cp-demint.c cplus-dem.c crc32.c \ d-demangle.c dwarfnames.c dyn-string.c \ - fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c \ + fdmatch.c ffs.c fibheap.c filedescriptor.c filename_cmp.c floatformat.c \ fnmatch.c fopen_unlocked.c \ getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c \ gettimeofday.c \ @@ -171,6 +171,7 @@ REQUIRED_OFILES = \ ./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext) \ ./dwarfnames.$(objext) ./dyn-string.$(objext) \ ./fdmatch.$(objext) ./fibheap.$(objext) \ + ./filedescriptor.$(objext) \ ./filename_cmp.$(objext) ./floatformat.$(objext) \ ./fnmatch.$(objext) ./fopen_unlocked.$(objext) \ ./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \ @@ -756,6 +757,17 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir else true; fi $(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION) +./filedescriptor.$(objext): $(srcdir)/filedescriptor.c config.h $(INCDIR)/ansidecl.h \ + $(INCDIR)/libiberty.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/filedescriptor.c -o pic/$@; \ + else true; fi + if [ x"$(NOASANFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/filedescriptor.c -o noasan/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/filedescriptor.c $(OUTPUT_OPTION) + + ./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/ansidecl.h \ $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ $(INCDIR)/safe-ctype.h diff --git a/libiberty/filedescriptor.c b/libiberty/filedescriptor.c new file mode 100644 index 00000000000..3a1a68d1eef --- /dev/null +++ b/libiberty/filedescriptor.c @@ -0,0 +1,47 @@ +/* File descriptor related functions. + + Copyright (C) 2019 Free Software Foundation, Inc. + + This file is part of the libiberty library. + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, + Boston, MA 02110-1301, USA. */ + +#include "config.h" +#include "ansidecl.h" +#include "libiberty.h" + +#ifdef HAVE_FCNTL_H +#include +#endif + +#if defined (_WIN32) +#define WIN32_LEAN_AND_MEAN +#include /* for GetFullPathName */ +#endif +/* Return true when FD file descriptor exists. */ + +int +is_valid_fd (int fd) +{ +#if defined(_WIN32) + HANDLE h = (HANDLE) _get_osfhandle (fd); + return h != (HANDLE) -1; +#elif defined(F_GETFD) + return fcntl (fd, F_GETFD) >= 0; +#else + return dup2 (fd, fd) < 0; +#endif +} diff --git a/libiberty/lrealpath.c b/libiberty/lrealpath.c index ac914a7a4f4..7f66dc2b1bd 100644 --- a/libiberty/lrealpath.c +++ b/libiberty/lrealpath.c @@ -49,9 +49,6 @@ components will be simplified. The returned value will be allocated using #ifdef HAVE_STRING_H #include #endif -#ifdef HAVE_FCNTL_H -#include -#endif /* On GNU libc systems the declaration is only visible with _GNU_SOURCE. */ #if defined(HAVE_CANONICALIZE_FILE_NAME) \ @@ -158,16 +155,3 @@ lrealpath (const char *filename) /* This system is a lost cause, just duplicate the filename. */ return strdup (filename); } - -/* Return true when FD file descriptor exists. */ - -int -is_valid_fd (int fd) -{ -#if defined(_WIN32) - HANDLE h = (HANDLE) _get_osfhandle (fd); - return h != (HANDLE) -1; -#else - return fcntl (fd, F_GETFD) >= 0; -#endif -}