public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch libiberty include]: Add additional helper functions for directory-separator searching
@ 2011-03-08 10:56 Kai Tietz
  2011-03-08 11:12 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Kai Tietz @ 2011-03-08 10:56 UTC (permalink / raw)
  To: Binutils, gdb-patches, GCC Patches

[-- 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})
 

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2011-03-12 16:44 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 10:56 [patch libiberty include]: Add additional helper functions for directory-separator searching Kai Tietz
2011-03-08 11:12 ` Eli Zaretskii
2011-03-08 11:25   ` Kai Tietz
2011-03-08 11:53     ` Eli Zaretskii
2011-03-08 12:01       ` Kai Tietz
2011-03-08 12:43         ` Pedro Alves
2011-03-08 12:48           ` Kai Tietz
2011-03-08 13:33             ` Pedro Alves
2011-03-08 13:37               ` Kai Tietz
2011-03-08 18:39               ` Eli Zaretskii
2011-03-08 18:50                 ` Pedro Alves
2011-03-08 18:51                 ` Kai Tietz
2011-03-08 19:54                   ` Eli Zaretskii
     [not found] ` <E1Pwupb-0001ns-M8__47566.5626036518$1299582745$gmane$org@fencepost.gnu.org>
2011-03-08 11:55   ` Andreas Schwab
2011-03-08 15:11 ` Kai Tietz
2011-03-08 15:30   ` Kai Tietz
2011-03-08 18:37     ` Eli Zaretskii
2011-03-08 19:41       ` DJ Delorie
2011-03-08 19:59         ` Eli Zaretskii
2011-03-08 22:38         ` Pedro Alves
2011-03-09  5:29           ` Eli Zaretskii
2011-03-09 11:46             ` Pedro Alves
2011-03-09 12:35               ` Eli Zaretskii
2011-03-09 12:58                 ` Pedro Alves
2011-03-09 13:36                   ` Eli Zaretskii
2011-03-12 16:40                     ` Kai Tietz
2011-03-09 14:37                   ` Build regression [Re: [patch libiberty include]: Add additional helper functions for directory-separator searching] Jan Kratochvil
2011-03-09 15:02                     ` Pedro Alves
2011-03-09 15:08                       ` Jan Kratochvil
2011-03-12 16:44         ` [patch libiberty include]: Add additional helper functions for directory-separator searching Kai Tietz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).