From: Kai Tietz <ktietz70@googlemail.com>
To: Binutils <binutils@sourceware.org>,
gdb-patches@sourceware.org,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [patch libiberty include]: Add additional helper functions for directory-separator searching
Date: Tue, 08 Mar 2011 11:25:00 -0000 [thread overview]
Message-ID: <AANLkTimyJb-3jEaWbbmUj2ZAOYPzhGT_GX9QFwR4DBCh@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1130 bytes --]
Hello,
This patch introduce directory-separator search routines to libiberty.
IMHO filename_cmp.c is suiteable for those functions, but if there are
objections about that I can move it into a separate source-file. It
helps to avoid a commonly used pattern about dir-separator searching
in code, which requires #if-conditions to check if DOS paths are used
and introduces additional internal variables.
the pattern
const char *filename = strrchr (xloc.file, '/');
#ifdef HAVE_DOS_BASED_FILE_SYSTEM
const char *filename2 = strrchr (xloc.file, '\\');
if (!filename || (filename2 && filename2 > filename))
filename = filename2;
can be written by this patch as
const char *filename = filename_dirrchr (xloc.file);
ChangeLog include/
2011-03-08 Kai Tietz
* filenames.h (filename_dirchr): New prototype.
(filename_dirrchr): Likewise.
ChangeLog libiberty/
2011-03-08 Kai Tietz
* filename_cmp.c (filename_dirchr): New function.
(filename_dirrchr): Likewise.
* functions.texi: Regenerated.
Tested for x86_64-pc-linux-gnu and x86_64-w64-mingw32. Ok for apply?
Regards,
Kai
[-- Attachment #2: libiberty_dirsep.txt --]
[-- Type: text/plain, Size: 3386 bytes --]
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/filename_cmp.c
===================================================================
--- gcc.orig/libiberty/filename_cmp.c 2011-02-28 19:16:35.000000000 +0100
+++ gcc/libiberty/filename_cmp.c 2011-03-08 11:43:32.797198100 +0100
@@ -125,3 +125,70 @@ filename_ncmp (const char *s1, const cha
return 0;
#endif
}
+
+/*
+
+@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;
+}
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 11:43:42.314406700 +0100
@@ -296,6 +296,30 @@ and backward slashes are equal.
@end deftypefn
+@c filename_cmp.c:131
+@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_cmp.c:164
+@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})
next reply other threads:[~2011-03-08 10:56 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-08 11:25 Kai Tietz [this message]
2011-03-08 11:53 ` Eli Zaretskii
2011-03-08 11:55 ` Kai Tietz
2011-03-08 12:01 ` Eli Zaretskii
2011-03-08 12:48 ` Kai Tietz
2011-03-08 13:25 ` Pedro Alves
2011-03-08 13:33 ` Kai Tietz
2011-03-08 14:30 ` Pedro Alves
2011-03-08 14:45 ` Kai Tietz
2011-03-08 18:49 ` Eli Zaretskii
2011-03-08 18:54 ` Pedro Alves
2011-03-08 18:58 ` Kai Tietz
2011-03-08 19:59 ` Eli Zaretskii
[not found] ` <E1Pwupb-0001ns-M8__47566.5626036518$1299582745$gmane$org@fencepost.gnu.org>
2011-03-08 12:43 ` Andreas Schwab
2011-03-08 16:52 ` Kai Tietz
2011-03-08 17:02 ` Kai Tietz
2011-03-08 18:39 ` Eli Zaretskii
2011-03-08 19:51 ` DJ Delorie
2011-03-08 22:38 ` Eli Zaretskii
2011-03-08 23:10 ` Pedro Alves
2011-03-09 7:12 ` Eli Zaretskii
2011-03-09 12:40 ` Pedro Alves
2011-03-09 12:54 ` Eli Zaretskii
2011-03-09 13:39 ` Pedro Alves
2011-03-09 13:54 ` Eli Zaretskii
2011-03-12 22:59 ` Kai Tietz
2011-03-09 15:02 ` Build regression [Re: [patch libiberty include]: Add additional helper functions for directory-separator searching] Jan Kratochvil
2011-03-09 15:40 ` Pedro Alves
2011-03-09 16:09 ` Jan Kratochvil
2011-03-13 1:09 ` [patch libiberty include]: Add additional helper functions for directory-separator searching Kai Tietz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimyJb-3jEaWbbmUj2ZAOYPzhGT_GX9QFwR4DBCh@mail.gmail.com \
--to=ktietz70@googlemail.com \
--cc=binutils@sourceware.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox