don't let bin2hex call strlen
[deliverable/binutils-gdb.git] / gdb / source.c
index de3fb7c5a34c5852e128c2410cd85a83ddcaa3ce..c1127656cbb2b6d7dabf606f78fd8119faa849b2 100644 (file)
@@ -1,5 +1,5 @@
 /* List lines of source files for GDB, the GNU debugger.
-   Copyright (C) 1986-2013 Free Software Foundation, Inc.
+   Copyright (C) 1986-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -30,8 +30,8 @@
 #include "filestuff.h"
 
 #include <sys/types.h>
-#include "gdb_string.h"
-#include "gdb_stat.h"
+#include <string.h>
+#include <sys/stat.h>
 #include <fcntl.h>
 #include "gdbcore.h"
 #include "gdb_regex.h"
@@ -574,17 +574,33 @@ add_path (char *dirname, char **which_path, int parse_separators)
        char tinybuf[2];
 
        p = *which_path;
-       /* FIXME: we should use realpath() or its work-alike
-          before comparing.  Then all the code above which
-          removes excess slashes and dots could simply go away.  */
-       if (!filename_cmp (p, name))
+       while (1)
          {
-           /* Found it in the search path, remove old copy.  */
-           if (p > *which_path)
-             p--;              /* Back over leading separator.  */
-           if (prefix > p - *which_path)
-             goto skip_dup;    /* Same dir twice in one cmd.  */
-           memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1); /* Copy from next \0 or  : */
+           /* FIXME: we should use realpath() or its work-alike
+              before comparing.  Then all the code above which
+              removes excess slashes and dots could simply go away.  */
+           if (!filename_ncmp (p, name, len)
+               && (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
+             {
+               /* Found it in the search path, remove old copy.  */
+               if (p > *which_path)
+                 {
+                   /* Back over leading separator.  */
+                   p--;
+                 }
+               if (prefix > p - *which_path)
+                 {
+                   /* Same dir twice in one cmd.  */
+                   goto skip_dup;
+                 }
+               /* Copy from next '\0' or ':'.  */
+               memmove (p, &p[len + 1], strlen (&p[len + 1]) + 1);
+             }
+           p = strchr (p, DIRNAME_SEPARATOR);
+           if (p != 0)
+             ++p;
+           else
+             break;
          }
 
        tinybuf[0] = DIRNAME_SEPARATOR;
@@ -689,10 +705,10 @@ is_regular_file (const char *name)
    and the file, sigh!  Emacs gets confuzzed by this when we print the
    source file name!!! 
 
-   If OPTS does not have OPF_DISABLE_REALPATH set return FILENAME_OPENED
-   resolved by gdb_realpath.  Even with OPF_DISABLE_REALPATH this function
-   still returns filename starting with "/".  If FILENAME_OPENED is NULL
-   this option has no effect.
+   If OPTS has OPF_RETURN_REALPATH set return FILENAME_OPENED resolved by
+   gdb_realpath.  Even without OPF_RETURN_REALPATH this function still returns
+   filename starting with "/".  If FILENAME_OPENED is NULL this option has no
+   effect.
 
    If a file is found, return the descriptor.
    Otherwise, return -1, with errno set for the last name we tried to open.  */
@@ -853,28 +869,10 @@ done:
       /* If a file was opened, canonicalize its filename.  */
       if (fd < 0)
        *filename_opened = NULL;
+      else if ((opts & OPF_RETURN_REALPATH) != 0)
+       *filename_opened = gdb_realpath (filename);
       else
-       {
-         char *(*realpath_fptr) (const char *);
-
-         realpath_fptr = ((opts & OPF_DISABLE_REALPATH) != 0
-                          ? xstrdup : gdb_realpath);
-
-         if (IS_ABSOLUTE_PATH (filename))
-           *filename_opened = realpath_fptr (filename);
-         else
-           {
-             /* Beware the // my son, the Emacs barfs, the botch that catch...  */
-
-             char *f = concat (current_directory,
-                               IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
-                               ? "" : SLASH_STRING,
-                               filename, (char *)NULL);
-
-             *filename_opened = realpath_fptr (f);
-             xfree (f);
-           }
-       }
+       *filename_opened = gdb_abspath (filename);
     }
 
   return fd;
@@ -897,8 +895,9 @@ source_full_path_of (const char *filename, char **full_pathname)
 {
   int fd;
 
-  fd = openp (source_path, OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH, filename,
-             O_RDONLY, full_pathname);
+  fd = openp (source_path,
+             OPF_TRY_CWD_FIRST | OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH,
+             filename, O_RDONLY, full_pathname);
   if (fd < 0)
     {
       *full_pathname = NULL;
@@ -1077,13 +1076,15 @@ find_and_open_source (const char *filename,
         }
     }
 
-  result = openp (path, OPF_SEARCH_IN_PATH, filename, OPEN_MODE, fullname);
+  result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
+                 OPEN_MODE, fullname);
   if (result < 0)
     {
       /* Didn't work.  Try using just the basename.  */
       p = lbasename (filename);
       if (p != filename)
-       result = openp (path, OPF_SEARCH_IN_PATH, p, OPEN_MODE, fullname);
+       result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, p,
+                       OPEN_MODE, fullname);
     }
 
   do_cleanups (cleanup);
This page took 0.024694 seconds and 4 git commands to generate.