Index: bfd/archive.c =================================================================== RCS file: /cvs/src/src/bfd/archive.c,v retrieving revision 1.58 diff -u -r1.58 archive.c --- bfd/archive.c 2 Sep 2009 07:18:35 -0000 1.58 +++ bfd/archive.c 8 Sep 2009 20:07:38 -0000 @@ -1295,7 +1295,7 @@ { const char *filename = strrchr (file, '/'); -#ifdef HAVE_DOS_BASED_FILE_SYSTEM + if (have_dos_based_file_system) { /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ char *bslash = strrchr (file, '\\'); @@ -1304,11 +1304,13 @@ if (filename == NULL && file[0] != '\0' && file[1] == ':') filename = file + 1; } -#endif - if (filename != NULL) - filename++; else - filename = file; + { + if (filename != NULL) + filename++; + else + filename = file; + } return filename; } #endif @@ -1820,7 +1822,7 @@ const char *filename = strrchr (pathname, '/'); size_t maxlen = ar_maxnamelen (abfd); -#ifdef HAVE_DOS_BASED_FILE_SYSTEM + if (have_dos_based_file_system) { /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ char *bslash = strrchr (pathname, '\\'); @@ -1829,7 +1831,6 @@ if (filename == NULL && pathname[0] != '\0' && pathname[1] == ':') filename = pathname + 1; } -#endif if (filename == NULL) filename = pathname; @@ -1868,7 +1869,7 @@ const char *filename = strrchr (pathname, '/'); size_t maxlen = ar_maxnamelen (abfd); -#ifdef HAVE_DOS_BASED_FILE_SYSTEM + if (have_dos_based_file_system) { /* We could have foo/bar\\baz, or foo\\bar, or d:bar. */ char *bslash = strrchr (pathname, '\\'); @@ -1878,7 +1879,6 @@ if (filename == NULL && pathname[0] != '\0' && pathname[1] == ':') filename = pathname + 1; } -#endif if (filename == NULL) filename = pathname; Index: gdb/completer.c =================================================================== RCS file: /cvs/src/src/gdb/completer.c,v retrieving revision 1.34 diff -u -r1.34 completer.c --- gdb/completer.c 25 Mar 2009 10:50:56 -0000 1.34 +++ gdb/completer.c 8 Sep 2009 20:07:45 -0000 @@ -232,13 +232,12 @@ else break; /* Hit the end of text. */ } -#if HAVE_DOS_BASED_FILE_SYSTEM /* If we have a DOS-style absolute file name at the beginning of TEXT, and the colon after the drive letter is the only colon we found, pretend the colon is not there. */ - else if (p < text + 3 && *p == ':' && p == text + 1 + quoted) + else if (have_dos_based_file_system + && p < text + 3 && *p == ':' && p == text + 1 + quoted) ; -#endif else if (*p == ':' && !colon) { colon = p; Index: gdb/source.c =================================================================== RCS file: /cvs/src/src/gdb/source.c,v retrieving revision 1.103 diff -u -r1.103 source.c --- gdb/source.c 23 Jul 2009 23:20:00 -0000 1.103 +++ gdb/source.c 8 Sep 2009 20:07:46 -0000 @@ -474,14 +474,20 @@ /* name is the start of the directory. p is the separator (or null) following the end. */ - while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */ -#ifdef HAVE_DOS_BASED_FILE_SYSTEM - /* On MS-DOS and MS-Windows, h:\ is different from h: */ - && !(p == name + 3 && name[1] == ':') /* "d:/" */ -#endif - && IS_DIR_SEPARATOR (p[-1])) - /* Sigh. "foo/" => "foo" */ - --p; + if (have_dos_based_file_system) { + while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */ + /* On MS-DOS and MS-Windows, h:\ is different from h: */ + && !(p == name + 3 && name[1] == ':') /* "d:/" */ + && IS_DIR_SEPARATOR (p[-1])) + /* Sigh. "foo/" => "foo" */ + --p; + } else { + while (!(IS_DIR_SEPARATOR (*name) && p <= name + 1) /* "/" */ + /* On MS-DOS and MS-Windows, h:\ is different from h: */ + && IS_DIR_SEPARATOR (p[-1])) + /* Sigh. "foo/" => "foo" */ + --p; + } *p = '\0'; while (p > name && p[-1] == '.') @@ -514,10 +520,9 @@ if (name[0] == '~') name = tilde_expand (name); -#ifdef HAVE_DOS_BASED_FILE_SYSTEM - else if (IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */ + else if (have_dos_based_file_system + && IS_ABSOLUTE_PATH (name) && p == name + 2) /* "d:" => "d:." */ name = concat (name, ".", (char *)NULL); -#endif else if (!IS_ABSOLUTE_PATH (name) && name[0] != '$') name = concat (current_directory, SLASH_STRING, name, (char *)NULL); else Index: gdb/top.c =================================================================== RCS file: /cvs/src/src/gdb/top.c,v retrieving revision 1.170 diff -u -r1.170 top.c --- gdb/top.c 31 Aug 2009 20:18:45 -0000 1.170 +++ gdb/top.c 8 Sep 2009 20:07:47 -0000 @@ -184,6 +184,9 @@ char *lim_at_start; #endif +/* Filesystem type */ +int have_dos_based_file_system = 0; + /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */ #ifndef STOP_SIGNAL @@ -676,6 +679,15 @@ value); } +static void +show_dos_based_file_system (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("\ +Whether the target has a DOS based file system is \"%s\".\n"), + value); +} + /* This is like readline(), but it has some gdb-specific behavior. gdb may want readline in both the synchronous and async modes during a single gdb invocation. At the ordinary top-level prompt we might @@ -1630,6 +1642,14 @@ show_history_filename, &sethistlist, &showhistlist); + add_setshow_boolean_cmd ("dos_based_file_system", class_support, + &have_dos_based_file_system, _("\ +Set whether the target has a DOS based file system"), _("\ +Show whether the target has a DOS based file system"), _("\ +whether the target has a DOS based file system"), NULL, + show_dos_based_file_system, + &setlist, &showlist); + add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\ Set whether to confirm potentially dangerous operations."), _("\ Show whether to confirm potentially dangerous operations."), NULL, Index: gdb/utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.219 diff -u -r1.219 utils.c --- gdb/utils.c 18 Aug 2009 16:17:16 -0000 1.219 +++ gdb/utils.c 8 Sep 2009 20:07:49 -0000 @@ -3280,15 +3280,14 @@ strncpy (dir_name, filename, base_name - filename); dir_name[base_name - filename] = '\000'; -#ifdef HAVE_DOS_BASED_FILE_SYSTEM /* We need to be careful when filename is of the form 'd:foo', which is equivalent of d:./foo, which is totally different from d:/foo. */ - if (strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':') + if (have_dos_based_file_system + && strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':') { dir_name[2] = '.'; dir_name[3] = '\000'; } -#endif /* Canonicalize the directory prefix, and build the resulting filename. If the dirname realpath already contains an ending Index: gdb/cli/cli-cmds.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v retrieving revision 1.92 diff -u -r1.92 cli-cmds.c --- gdb/cli/cli-cmds.c 11 Jul 2009 14:04:23 -0000 1.92 +++ gdb/cli/cli-cmds.c 8 Sep 2009 20:07:50 -0000 @@ -357,24 +357,27 @@ if (chdir (dir) < 0) perror_with_name (dir); -#ifdef HAVE_DOS_BASED_FILE_SYSTEM /* There's too much mess with DOSish names like "d:", "d:.", "d:./foo" etc. Instead of having lots of special #ifdef'ed code, simply get the canonicalized name of the current directory. */ - dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); -#endif + if (have_dos_based_file_system) + dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)); len = strlen (dir); if (IS_DIR_SEPARATOR (dir[len - 1])) { /* Remove the trailing slash unless this is a root directory (including a drive letter on non-Unix systems). */ - if (!(len == 1) /* "/" */ -#ifdef HAVE_DOS_BASED_FILE_SYSTEM - && !(len == 3 && dir[1] == ':') /* "d:/" */ -#endif - ) - len--; + if (have_dos_based_file_system) + { + if (!(len == 1) /* "/" */ && !(len == 3 && dir[1] == ':') /* "d:/" */) + len--; + } + else + { + if (!(len == 1)) /* "/" */ + len--; + } } dir = savestring (dir, len); Index: include/filenames.h =================================================================== RCS file: /cvs/src/src/include/filenames.h,v retrieving revision 1.5 diff -u -r1.5 filenames.h --- include/filenames.h 21 Mar 2008 23:40:18 -0000 1.5 +++ include/filenames.h 8 Sep 2009 20:07:52 -0000 @@ -5,7 +5,7 @@ use forward- and back-slash in path names interchangeably, and some of them have case-insensitive file names. - Copyright 2000, 2001, 2007 Free Software Foundation, Inc. + Copyright 2000, 2001, 2007, 2009 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -30,25 +30,36 @@ extern "C" { #endif -#if defined(__MSDOS__) || defined(_WIN32) || defined(__OS2__) || defined (__CYGWIN__) +/* Defined in gdb/top.c + + This determines whether we have + as a separator : / or \ + a prefix [a-z]: or not + Replaces HAVE_DOS_BASED_FILE_SYSTEM and FILENAME_PREFIX_LEN. + + Case sensitive/insensitive file name comparison is *not* influenced by this. */ + +extern int have_dos_based_file_system; + +#define _isalpha(c) (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) + +#define IS_DIR_SEPARATOR(c) \ + ((have_dos_based_file_system) ? \ + ((c == '/') || (c == '\\')) : \ + (c == '/')) -#ifndef HAVE_DOS_BASED_FILE_SYSTEM -#define HAVE_DOS_BASED_FILE_SYSTEM 1 +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 #endif -#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\') -/* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is - only semi-absolute. This is because the users of IS_ABSOLUTE_PATH - want to know whether to prepend the current working directory to - a file name, which should not be done with a name like d:foo. */ -#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (((f)[0]) && ((f)[1] == ':'))) - -#else /* not DOSish */ - -#define IS_DIR_SEPARATOR(c) ((c) == '/') -#define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0])) +#define IS_ABSOLUTE_PATH(f) \ + ((IS_DIR_SEPARATOR(f[0])) ? TRUE : \ + (have_dos_based_file_system ? (_isalpha(f[0]) && (f[1] == ':')) : FALSE)) -#endif /* not DOSish */ +#endif /* static inline functions */ extern int filename_cmp (const char *s1, const char *s2); #define FILENAME_CMP(s1, s2) filename_cmp(s1, s2)