From patchwork Tue Mar 8 15:29:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 86019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 6CF59B70CE for ; Wed, 9 Mar 2011 02:30:17 +1100 (EST) Received: (qmail 17520 invoked by alias); 8 Mar 2011 15:30:03 -0000 Received: (qmail 17355 invoked by uid 22791); 8 Mar 2011 15:30:00 -0000 X-SWARE-Spam-Status: No, hits=1.6 required=5.0 tests=AWL, BAYES_99, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Mar 2011 15:29:53 +0000 Received: by qyk35 with SMTP id 35so3008402qyk.20 for ; Tue, 08 Mar 2011 07:29:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.135.82 with SMTP id m18mr1586669qct.82.1299598191616; Tue, 08 Mar 2011 07:29:51 -0800 (PST) Received: by 10.229.89.197 with HTTP; Tue, 8 Mar 2011 07:29:51 -0800 (PST) In-Reply-To: References: Date: Tue, 8 Mar 2011 16:29:51 +0100 Message-ID: Subject: Re: [patch libiberty include]: Add additional helper functions for directory-separator searching From: Kai Tietz To: Binutils , gdb-patches@sourceware.org, GCC Patches X-IsSubscribed: yes 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 Umm, sorry. I found a wrong copy & paste. So I re-sent the corrected patch. Additionally I adjuste the changes in Makefile.in so, that alphabetic order remains. Kai Index: gcc/include/filenames.h =================================================================== --- gcc.orig/include/filenames.h 2011-02-28 19:16:35.000000000 +0100 +++ gcc/include/filenames.h 2011-03-08 11:11:10.909109700 +0100 @@ -75,6 +75,8 @@ extern int filename_cmp (const char *s1, extern int filename_ncmp (const char *s1, const char *s2, size_t n); +extern char *filename_dirchr (const char *p); +extern char *filename_dirrchr (const char *p); #ifdef __cplusplus } Index: gcc/libiberty/functions.texi =================================================================== --- gcc.orig/libiberty/functions.texi 2011-02-28 19:16:35.000000000 +0100 +++ gcc/libiberty/functions.texi 2011-03-08 16:26:29.547971700 +0100 @@ -296,6 +296,30 @@ and backward slashes are equal. @end deftypefn +@c filename_chr.c:32 +@deftypefn Extension int filename_dirchr (const char *@var{p}) + +The returned value is similar to what @code{strchr} would return for +searching for a directory separator. + +This function does not normalize file name. However, it does handle +the fact that on DOS-like file systems, forward and backward slashes +are directory separators. + +@end deftypefn + +@c filename_chr.c:65 +@deftypefn Extension int filename_dirrchr (const char *@var{p}) + +The returned value is similar to what @code{strrchr} would return for +searching for a directory separator. + +This function does not normalize file name. However, it does handle +the fact that on DOS-like file systems, forward and backward slashes +are directory separators. + +@end deftypefn + @c filename_cmp.c:81 @deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n}) Index: gcc/libiberty/Makefile.in =================================================================== --- gcc.orig/libiberty/Makefile.in 2010-11-21 14:28:05.000000000 +0100 +++ gcc/libiberty/Makefile.in 2011-03-08 16:24:17.703229600 +0100 @@ -127,8 +127,8 @@ CFILES = alloca.c argv.c asprintf.c atex calloc.c choose-temp.c clock.c concat.c cp-demangle.c \ cp-demint.c cplus-dem.c crc32.c \ dyn-string.c \ - fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c \ - fnmatch.c fopen_unlocked.c \ + fdmatch.c ffs.c fibheap.c filename_chr.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 \ hashtab.c hex.c \ @@ -168,7 +168,8 @@ REQUIRED_OFILES = \ ./choose-temp.$(objext) ./concat.$(objext) \ ./cp-demint.$(objext) ./crc32.$(objext) ./dyn-string.$(objext) \ ./fdmatch.$(objext) ./fibheap.$(objext) \ - ./filename_cmp.$(objext) ./floatformat.$(objext) \ + ./filename_chr.$(objext) ./filename_cmp.$(objext) \ + ./floatformat.$(objext) \ ./fnmatch.$(objext) ./fopen_unlocked.$(objext) \ ./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \ ./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \ @@ -646,6 +647,13 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION) +./filename_chr.$(objext): $(srcdir)/filename_chr.c config.h $(INCDIR)/filenames.h \ + $(INCDIR)/safe-ctype.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/filename_chr.c -o pic/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/filename_chr.c $(OUTPUT_OPTION) + ./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/filenames.h \ $(INCDIR)/safe-ctype.h if [ x"$(PICFLAG)" != x ]; then \ Index: gcc/libiberty/filename_chr.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gcc/libiberty/filename_chr.c 2011-03-08 16:22:51.303258200 +0100 @@ -0,0 +1,95 @@ +/* File name character searching routines. + + Copyright (C) 2011 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 + the Free Software Foundation; either version 2, 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. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#include "filenames.h" +#include "safe-ctype.h" + +/* + +@deftypefn Extension int filename_dirchr (const char *@var{p}) + +The returned value is similar to what @code{strchr} would return for +searching for a directory separator. + +This function does not normalize file name. However, it does handle +the fact that on DOS-like file systems, forward and backward slashes +are directory separators. + +@end deftypefn + +*/ + +char * +filename_dirchr (const char *p) +{ + char *r; +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + char *r2; +#endif + if (!p) + return NULL; + r = strchr (p, '/'); +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + r2 = strchr (p, '\\'); + if (!r || (r2 && r2 < r)) + r = r2; +#endif + return r; +} + +/* + +@deftypefn Extension int filename_dirrchr (const char *@var{p}) + +The returned value is similar to what @code{strrchr} would return for +searching for a directory separator. + +This function does not normalize file name. However, it does handle +the fact that on DOS-like file systems, forward and backward slashes +are directory separators. + +@end deftypefn + +*/ + +char * +filename_dirrchr (const char *p) +{ + char *r; +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + char *r2; +#endif + + if (!p) + return NULL; + r = strrchr (p, '/'); +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + r2 = strrchr (p, '\\'); + if (!r || (r2 && r2 > r)) + r = r2; +#endif + return r; +}