commit 6a619bbabb16472cfc4e9ba41758a43cc8bbfd5e Author: Joel Brobecker Date: Tue Apr 27 11:12:43 2010 -0400 New general purpose routines in utils.c These are some general-purpose routines that were added for the VxWorks port... Hopefully other parts of the GDB code will make use of them. 2010-04-27 Joel Brobecker * utils.c (have_dos_based_filesystem, is_regular_file) (skip_whitespace, skip_until_character, skip_until_whitespace) (skip_space_delimited_token, get_space_delimited_token): New functions. * source.c (is_regular_file): Delete. Moved to utils.c. * defs.h (have_dos_based_filesystem, is_regular_file) (skip_whitespace, skip_until_character, skip_space_delimited_token) (get_space_delimited_token): Add declaration. diff --git a/gdb/defs.h b/gdb/defs.h index e8a1dd4..0d84170 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -432,6 +432,18 @@ extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); extern int parse_pid_to_attach (char *args); +extern int have_dos_based_filesystem (void); + +extern int is_regular_file (const char *name); + +extern char *skip_whitespace (char *str); + +extern char *skip_until_character (char *str, char delimiter); + +extern char *skip_space_delimited_token (char *str); + +extern char *get_space_delimited_token (char *str, char **token); + /* From demangle.c */ extern void set_demangling_style (char *); diff --git a/gdb/source.c b/gdb/source.c index 47caa14..1e4107b 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -622,24 +622,6 @@ source_info (char *ignore, int from_tty) } -/* Return True if the file NAME exists and is a regular file */ -static int -is_regular_file (const char *name) -{ - struct stat st; - const int status = stat (name, &st); - - /* Stat should never fail except when the file does not exist. - If stat fails, analyze the source of error and return True - unless the file does not exist, to avoid returning false results - on obscure systems where stat does not work as expected. - */ - if (status != 0) - return (errno != ENOENT); - - return S_ISREG (st.st_mode); -} - /* Open a file named STRING, searching path PATH (dir names sep by some char) using mode MODE in the calls to open. You cannot use this function to create files (O_CREAT). diff --git a/gdb/utils.c b/gdb/utils.c index e225a3f..cac312f 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3673,6 +3673,116 @@ parse_pid_to_attach (char *args) return pid; } +/* Return non-zero if the host has a dos-based file system. */ + +int +have_dos_based_filesystem (void) +{ +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + return 1; +#else + return 0; +#endif +} + +/* Return True if the file NAME exists and is a regular file. */ + +int +is_regular_file (const char *name) +{ + struct stat st; + const int status = stat (name, &st); + + /* Stat should never fail except when the file does not exist. + If stat fails, analyze the source of error and return True + unless the file does not exist, to avoid returning false results + on obscure systems where stat does not work as expected. */ + if (status != 0) + return (errno != ENOENT); + + return S_ISREG (st.st_mode); +} + +/* Return a pointer to the first non-whitepace character found + in the string. A whitespace is either a space or a tab. */ + +char * +skip_whitespace (char *str) +{ + char *index = str; + + while (*index == ' ' || *index == '\t') + index++; + + return index; +} + +/* Return a pointer to the first DELIMITER character in the given + string. Return a pointer to the end-of-line character if + DELIMITER was not found. */ + +char * +skip_until_character (char *str, char delimiter) +{ + char *index = str; + + while (*index != delimiter && *index != '\0') + index++; + + return index; +} + +/* return a pointer to the first whitespace character. If no whitespace + is found before the end of string, a pointer to the end of string + is returned. A whitespace is either a space or a tab. */ + +static char * +skip_until_whitespace (char *str) +{ + char *index = str; + + while (*index != ' ' && *index != '\t' && *index != '\0') + index++; + + return index; +} + +/* Return a pointer to the first white space after the next + whitespace-delimited token. */ + +char * +skip_space_delimited_token (char *str) +{ + char *index = str; + + index = skip_whitespace (index); + index = skip_until_whitespace (index); + + return index; +} + +/* Copy the next whitespace token into TOKEN. This string will be + allocated using malloc, and must be dealocated later. */ + +char * +get_space_delimited_token (char *str, char **token) +{ + char *start; + char *end; + char tmp; + + start = skip_whitespace (str); + end = skip_until_whitespace (start); + + tmp = *end; + *end = '\0'; + *token = xstrdup (start); + *end = tmp; + + return end; +} + + /* Provide a prototype to silence -Wmissing-prototypes. */ extern initialize_file_ftype _initialize_utils;