This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [patch/libiberty] IS_ABSOLUTE_PATH to handle both DOS and POS IX p ath styles
- From: Aleksandar Ristovski <ARistovski at qnx dot com>
- To: DJ Delorie <dj at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, drow at false dot org, Ryan Mansfield <RMansfield at qnx dot com>
- Date: Fri, 4 Jan 2008 16:13:18 -0500
- Subject: RE: [patch/libiberty] IS_ABSOLUTE_PATH to handle both DOS and POS IX p ath styles
> Perhaps we should have a similar comment on the new ones, or at least
> a "see comment for ..." comment.
Ok, here is the revised patch with more (hopefully clearer) comments and
full POSIX spelling.
Thank you,
Aleksandar Ristovski
QNX Software Systems
============================================================================
ChangeLog:
2008-01-04 Aleksandar Ristovski <aristovski@qnx.com>
* filenames.h (IS_DIR_SEPARATOR_DOS): New macro.
(IS_ABSOLUTE_PATH_DOS): New macro.
(IS_DIR_SEPARATOR_POSIX): New macro.
(IS_ABSOLUTE_PATH_POSIX): New macro.
(IS_DIR_SEPARATOR_ANY): New macro.
(IS_ABSOLUTE_PATH_ANY): New macro.
Index: include/filenames.h
===================================================================
RCS file: /cvs/src/src/include/filenames.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 filenames.h
--- include/filenames.h 29 Mar 2007 21:03:43 -0000 1.4
+++ include/filenames.h 4 Jan 2008 21:06:09 -0000
@@ -26,6 +26,33 @@ Foundation, Inc., 51 Franklin Street - F
#ifndef FILENAMES_H
#define FILENAMES_H
+/* For DOS style paths. */
+
+#define IS_DIR_SEPARATOR_DOS(c) ((c) == '/' || (c) == '\\')
+
+/*Note that IS_ABSOLUTE_PATH_DOS macro does not recognize
+ path starting with '/' as an absolute path. Otherwise, it behaves
+ as IS_DIR_SEPARATOR macro when configured for DOS-like
+ file system (see comment for IS_ABSOLUTE_PATH below). */
+
+#define IS_ABSOLUTE_PATH_DOS(f) (((f)[0]) && ((f)[1] == ':'))
+
+/* For POSIX style paths. */
+
+#define IS_DIR_SEPARATOR_POSIX(c) ((c) == '/')
+#define IS_ABSOLUTE_PATH_POSIX(f) (IS_DIR_SEPARATOR_POSIX((f)[0]))
+
+/* Universal macros, to be used on paths that could be either
+ POSIX or DOS. As a rule of thumb, these are the macros to be
+ used when dealing with paths coming from/going to binaries, debug
+ info and such. When dealing with paths from the host filesystem (i.e.
+ paths from the filesystem where our application is running),
+ IS_ABSOLUTE_PATH should be used. */
+
+#define IS_DIR_SEPARATOR_ANY(c) (IS_DIR_SEPARATOR_DOS(c))
+#define IS_ABSOLUTE_PATH_ANY(f) (IS_ABSOLUTE_PATH_POSIX(f) \
+ || IS_ABSOLUTE_PATH_DOS(f))
+
#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined
(__CYGWIN__)
#ifndef HAVE_DOS_BASED_FILE_SYSTEM