Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Better realpath
@ 2008-06-14 11:09 Vladimir Prus
  2008-06-14 11:30 ` Pierre Muller
  2008-06-14 14:29 ` Eli Zaretskii
  0 siblings, 2 replies; 18+ messages in thread
From: Vladimir Prus @ 2008-06-14 11:09 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]


GDB has a function to get real path of a file, gdb_realpath. Unfortunately,
that function is essentially a copy-paste of libiberty's lrealpath, with
the extra bonus that gdb_realpath *does not* have any Windows-specific
code. As result, GDB is not capable to simplify ".." in windows paths,
and among other problems, breakpoints set using full file names containing
".." will not work.

This patch makes GDB use libibery's lrealpath. OK?

- Volodya

       gdb/
       * utils.c (gdb_realpath): Use lrealpath.

[-- Attachment #2: commit.diff --]
[-- Type: text/x-diff, Size: 2723 bytes --]

Index: gdb/utils.c
===================================================================
--- gdb/utils.c	(revision 211706)
+++ gdb/utils.c	(revision 211707)
@@ -2872,73 +2872,10 @@
 char *
 gdb_realpath (const char *filename)
 {
-  /* Method 1: The system has a compile time upper bound on a filename
-     path.  Use that and realpath() to canonicalize the name.  This is
-     the most common case.  Note that, if there isn't a compile time
-     upper bound, you want to avoid realpath() at all costs.  */
-#if defined(HAVE_REALPATH)
-  {
-# if defined (PATH_MAX)
-    char buf[PATH_MAX];
-#  define USE_REALPATH
-# elif defined (MAXPATHLEN)
-    char buf[MAXPATHLEN];
-#  define USE_REALPATH
-# endif
-# if defined (USE_REALPATH)
-    const char *rp = realpath (filename, buf);
-    if (rp == NULL)
-      rp = filename;
-    return xstrdup (rp);
-# endif
-  }
-#endif /* HAVE_REALPATH */
-
-  /* Method 2: The host system (i.e., GNU) has the function
-     canonicalize_file_name() which malloc's a chunk of memory and
-     returns that, use that.  */
-#if defined(HAVE_CANONICALIZE_FILE_NAME)
-  {
-    char *rp = canonicalize_file_name (filename);
-    if (rp == NULL)
-      return xstrdup (filename);
-    else
-      return rp;
-  }
-#endif
-
-  /* FIXME: cagney/2002-11-13:
-
-     Method 2a: Use realpath() with a NULL buffer.  Some systems, due
-     to the problems described in in method 3, have modified their
-     realpath() implementation so that it will allocate a buffer when
-     NULL is passed in.  Before this can be used, though, some sort of
-     configure time test would need to be added.  Otherwize the code
-     will likely core dump.  */
-
-  /* Method 3: Now we're getting desperate!  The system doesn't have a
-     compile time buffer size and no alternative function.  Query the
-     OS, using pathconf(), for the buffer limit.  Care is needed
-     though, some systems do not limit PATH_MAX (return -1 for
-     pathconf()) making it impossible to pass a correctly sized buffer
-     to realpath() (it could always overflow).  On those systems, we
-     skip this.  */
-#if defined (HAVE_REALPATH) && defined (HAVE_UNISTD_H) && defined(HAVE_ALLOCA)
-  {
-    /* Find out the max path size.  */
-    long path_max = pathconf ("/", _PC_PATH_MAX);
-    if (path_max > 0)
-      {
-	/* PATH_MAX is bounded.  */
-	char *buf = alloca (path_max);
-	char *rp = realpath (filename, buf);
-	return xstrdup (rp ? rp : filename);
-      }
-  }
-#endif
-
-  /* This system is a lost cause, just dup the buffer.  */
-  return xstrdup (filename);
+  char *r = lrealpath (filename);
+  if (!r)
+    nomem (0);
+  return r;
 }
 
 /* Return a copy of FILENAME, with its directory prefix canonicalized

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

end of thread, other threads:[~2008-06-19 18:58 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-14 11:09 Better realpath Vladimir Prus
2008-06-14 11:30 ` Pierre Muller
2008-06-14 12:14   ` Vladimir Prus
2008-06-14 14:29 ` Eli Zaretskii
2008-06-14 15:10   ` Vladimir Prus
2008-06-14 22:05     ` Eli Zaretskii
2008-06-14 22:26       ` Vladimir Prus
2008-06-15 17:37         ` Eli Zaretskii
2008-06-15 17:43           ` Daniel Jacobowitz
2008-06-15 21:04             ` Eli Zaretskii
2008-06-16  3:17               ` Daniel Jacobowitz
2008-06-16  3:32                 ` Eli Zaretskii
2008-06-18 18:39               ` Stan Shebs
2008-06-18 20:47                 ` DJ Delorie
2008-06-18 15:22           ` Vladimir Prus
2008-06-18 21:08             ` Eli Zaretskii
2008-06-19  7:27               ` Vladimir Prus
2008-06-20  2:49                 ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox