COMPILER_RT_VISIBILITY void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix, size_t PrefixLen, int PrefixStrip) { const char *Ptr; int Level; const char *StrippedPathStr = PathStr; for (Level = 0, Ptr = PathStr + 1; Level < PrefixStrip; ++Ptr) { if (*Ptr == '\0') break; if (!IS_DIR_SEPARATOR(*Ptr)) continue; StrippedPathStr = Ptr; ++Level; } memcpy(Dest, Prefix, PrefixLen); if (!IS_DIR_SEPARATOR(Prefix[PrefixLen - 1])) Dest[PrefixLen++] = DIR_SEPARATOR; memcpy(Dest + PrefixLen, StrippedPathStr, strlen(StrippedPathStr) + 1); }
/* If T begins with any of the partial pathnames listed in d->vpathv, then advance T to point beyond that pathname. */ static const char * apply_vpath (struct deps *d, const char *t) { if (d->vpathv) { unsigned int i; for (i = 0; i < d->nvpaths; i++) { if (!strncmp (d->vpathv[i], t, d->vpathlv[i])) { const char *p = t + d->vpathlv[i]; if (!IS_DIR_SEPARATOR (*p)) goto not_this_one; /* Do not simplify $(vpath)/../whatever. ??? Might not be necessary. */ if (p[1] == '.' && p[2] == '.' && IS_DIR_SEPARATOR (p[3])) goto not_this_one; /* found a match */ t = t + d->vpathlv[i] + 1; break; } not_this_one:; } } /* Remove leading ./ in any case. */ while (t[0] == '.' && IS_DIR_SEPARATOR (t[1])) t += 2; return t; }
int mkdir_p (const char *path, int mode) { int len; char *new_path; int ret = 0; new_path = (char *) malloc (strlen(path) + 1); strcpy (new_path, path); len = strlen (new_path); while (len > 0 && IS_DIR_SEPARATOR(new_path[len-1])) { new_path[len-1] = 0; len--; } #if defined(_MSC_VER) || defined(__MINGW32__) while (!_mkdir (new_path)) #else while (!mkdir (new_path, mode)) #endif { char *slash; int last_error = errno; if (last_error == EEXIST) break; if (last_error != ENOENT) { ret = -1; break; } slash = new_path + strlen (new_path); while (slash > new_path && !IS_DIR_SEPARATOR(*slash)) slash--; if (slash == new_path) { ret = -1; break; } len = slash - new_path; new_path[len] = 0; if (!mkdir_p (new_path, mode)) { ret = -1; break; } new_path[len] = '/'; } free (new_path); return ret; }
static char * strip_path_and_suffix (const char *full_name, const char *new_suffix) { char *name; char *p; if (!full_name || !new_suffix) return NULL; /* Strip path name. */ p = (char *)full_name + strlen (full_name); while (p != full_name && !IS_DIR_SEPARATOR (p[-1])) --p; /* Now 'p' is a file name with suffix. */ name = (char *) malloc (strlen (p) + 1 + strlen (new_suffix)); strcpy (name, p); p = name + strlen (name); while (p != name && *p != '.') --p; /* If did not reach at the beginning of name then '.' is found. Replace '.' with NULL. */ if (p != name) *p = '\0'; strcat (name, new_suffix); return name; }
void add_new_plugin (const char* plugin_name) { struct plugin_name_args *plugin; void **slot; char *base_name; bool name_is_short; const char *pc; flag_plugin_added = true; /* Replace short names by their full path when relevant. */ name_is_short = !IS_ABSOLUTE_PATH (plugin_name); for (pc = plugin_name; name_is_short && *pc; pc++) if (*pc == '.' || IS_DIR_SEPARATOR (*pc)) name_is_short = false; if (name_is_short) { base_name = CONST_CAST (char*, plugin_name); /* FIXME: the ".so" suffix is currently builtin, since plugins only work on ELF host systems like e.g. Linux or Solaris. When plugins shall be available on non ELF systems such as Windows or MacOS, this code has to be greatly improved. */ plugin_name = concat (default_plugin_dir_name (), "/", plugin_name, ".so", NULL); if (access (plugin_name, R_OK)) fatal_error ("inacessible plugin file %s expanded from short plugin name %s: %m", plugin_name, base_name); } else
static bfd_boolean is_sysrooted_pathname (const char *name, bfd_boolean notsame) { char * realname = ld_canon_sysroot ? lrealpath (name) : NULL; int len; bfd_boolean result; if (! realname) return FALSE; len = strlen (realname); if (((! notsame && len == ld_canon_sysroot_len) || (len >= ld_canon_sysroot_len && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len]) && (realname[ld_canon_sysroot_len] = '\0') == '\0')) && FILENAME_CMP (ld_canon_sysroot, realname) == 0) result = TRUE; else result = FALSE; if (realname) free (realname); return result; }
const char * child_path (const char *parent, const char *child) { /* The child path must start with the parent path. */ size_t parent_len = strlen (parent); if (filename_ncmp (parent, child, parent_len) != 0) return NULL; /* The parent path must be a directory and the child must contain at least one component underneath the parent. */ const char *child_component; if (IS_DIR_SEPARATOR (parent[parent_len - 1])) { /* The parent path ends in a directory separator, so it is a directory. The first child component starts after the common prefix. */ child_component = child + parent_len; } else { /* The parent path does not end in a directory separator. The first character in the child after the common prefix must be a directory separator. Note that CHILD must hold at least parent_len characters for filename_ncmp to return zero. If the character at parent_len is nul due to CHILD containing the same path as PARENT, the IS_DIR_SEPARATOR check will fail here. */ if (!IS_DIR_SEPARATOR (child[parent_len])) return NULL; /* The first child component starts after the separator after the common prefix. */ child_component = child + parent_len + 1; } /* The child must contain at least one non-separator character after the parent. */ while (*child_component != '\0') { if (!IS_DIR_SEPARATOR (*child_component)) return child_component; child_component++; } return NULL; }
/* Define IS_DIR_SEPARATOR. */ #ifndef DIR_SEPARATOR_2 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) #else /* DIR_SEPARATOR_2 */ # define IS_DIR_SEPARATOR(ch) \ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) #endif /* DIR_SEPARATOR_2 */ char *basename (const char *name) { const char *base; for (base = name; *name; name++) { if (IS_DIR_SEPARATOR (*name)) { base = name + 1; } } return (char *) base; }
/* For preprocessed files, if the tokens following the first filename line is of the form # <line> "/path/name//", handle the directive so we know the original current directory. */ static void read_original_directory (cpp_reader *pfile) { const cpp_token *hash, *token; /* Lex ahead; if the first tokens are of the form # NUM, then process the directive, otherwise back up. */ hash = _cpp_lex_direct (pfile); if (hash->type != CPP_HASH) { _cpp_backup_tokens (pfile, 1); return; } token = _cpp_lex_direct (pfile); if (token->type != CPP_NUMBER) { _cpp_backup_tokens (pfile, 2); return; } token = _cpp_lex_direct (pfile); if (token->type != CPP_STRING || ! (token->val.str.len >= 5 && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-2]) && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-3]))) { _cpp_backup_tokens (pfile, 3); return; } if (pfile->cb.dir_change) { char *debugdir = (char *) alloca (token->val.str.len - 3); memcpy (debugdir, (const char *) token->val.str.text + 1, token->val.str.len - 4); debugdir[token->val.str.len - 4] = '\0'; pfile->cb.dir_change (pfile, debugdir); } }
static int get_prog_name_len (const char *prog) { int result = 0; const char *progend = prog + strlen(prog); const char *progname = progend; while (progname != prog && !IS_DIR_SEPARATOR (progname[-1])) --progname; return progend-progname; }
static int create_file_directory (char *filename) { #if !defined(TARGET_POSIX_IO) && !defined(_WIN32) (void) filename; return -1; #else char *s; s = filename; if (HAS_DRIVE_SPEC(s)) s += 2; if (IS_DIR_SEPARATOR(*s)) ++s; for (; *s != '\0'; s++) if (IS_DIR_SEPARATOR(*s)) { char sep = *s; *s = '\0'; /* Try to make directory if it doesn't already exist. */ if (access (filename, F_OK) == -1 #ifdef TARGET_POSIX_IO && mkdir (filename, 0755) == -1 #else && mkdir (filename) == -1 #endif /* The directory might have been made by another process. */ && errno != EEXIST) { fprintf (stderr, "profiling:%s:Cannot create directory\n", filename); *s = sep; return -1; }; *s = sep; }; return 0; #endif }
bool contains_dir_separator (const char *path) { for (; *path != '\0'; path++) { if (IS_DIR_SEPARATOR (*path)) return true; } return false; }
/**************************************************************************** * split_dir_and_file: * Takes a string and fills one pre-allocated array with any path prior to * the file name, and fills another pre-allocated array with the file name * The path name will include a trailing directory separator * The path name will be the empty string if there was no path in the input */ void split_dir_and_file(const char *inString, char *dirName, char *fileName) { int ii; /* Start at end of inString. */ ii = strlen(inString) - 1; /* Work backwards until we hit a directory separator. */ while ((ii>0) && !IS_DIR_SEPARATOR(inString[ii])) { ii--; } /* ii could be -1, if the input string was empty */ if (ii < 0) ii = 0; if (IS_DIR_SEPARATOR(inString[ii])) { ii++; } strcpy(dirName, inString); dirName[ii] = '\0'; strcpy(fileName, &inString[ii]); }
/** * returns a pointer on the basename part of name */ const char* filebasename(const char* name) { #if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* Skip over the disk name in MSDOS pathnames. */ if (isalpha(name[0]) && name[1] == ':') name += 2; #endif const char* base; for (base = name; *name; name++) { if (IS_DIR_SEPARATOR(*name)) { base = name + 1; } } return base; }
const char * base_name (const char *name) { const char *base; #if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* Skip over the disk name in MSDOS pathnames. */ if (isalpha ((unsigned char) name[0]) && name[1] == ':') name += 2; #endif for (base = name; *name; name++) if (IS_DIR_SEPARATOR (*name)) base = name + 1; return base; }
/* ============ CreatePath ============ */ void CreatePath (char *path) { char *ofs, c; if (!path || !*path) return; ofs = path; if (HAS_DRIVE_SPEC(ofs)) ofs = STRIP_DRIVE_SPEC(ofs); if (IS_DIR_SEPARATOR(*ofs)) ofs++; for ( ; *ofs; ofs++) { c = *ofs; if (IS_DIR_SEPARATOR(c)) { *ofs = 0; Q_mkdir (path); *ofs = c; } } }
/* Standard plugin API registerable hook. */ static enum ld_plugin_status onclaim_file (const struct ld_plugin_input_file *file, int *claimed) { /* Let's see if we want to claim this file. */ claim_file_t *claimfile = claimfiles_list; size_t len = strlen (file->name); char *name = xstrdup (file->name); char *p = name + len; bfd_boolean islib; /* Only match the file name without the directory part. */ islib = *p == 'a' && *(p - 1) == '.'; for (; p != name; p--) if (IS_DIR_SEPARATOR (*p)) { p++; break; } while (claimfile) { /* Claim the file only if the file name and size match and don't match the whole library. */ if (!strcmp (p, claimfile->file.name) && claimfile->file.filesize == file->filesize && (!islib || file->offset != 0)) break; claimfile = claimfile->next; } free (name); /* If we decided to claim it, record that fact, and add any symbols that were defined for it by plugin options. */ *claimed = (claimfile != 0); if (claimfile) { claimfile->claimed = TRUE; claimfile->file = *file; if (claimfile->n_syms_used && !tv_add_symbols) return LDPS_ERR; else if (claimfile->n_syms_used) return (*tv_add_symbols) (claimfile->file.handle, claimfile->n_syms_used, claimfile->symbols); } return claim_file_ret; }
const char * trim_filename (const char *name) { static const char this_file[] = __FILE__; const char *p = name, *q = this_file; /* Skip any parts the two filenames have in common. */ while (*p == *q && *p != 0 && *q != 0) p++, q++; /* Now go backwards until the previous directory separator. */ while (p > name && !IS_DIR_SEPARATOR (p[-1])) p--; return p; }
COMPILER_RT_VISIBILITY void __llvm_profile_recursive_mkdir(char *path) { int i; for (i = 1; path[i] != '\0'; ++i) { char save = path[i]; if (!IS_DIR_SEPARATOR(path[i])) continue; path[i] = '\0'; #ifdef _WIN32 _mkdir(path); #else mkdir(path, 0755); /* Some of these will fail, ignore it. */ #endif path[i] = save; } }
gdb::unique_xmalloc_ptr<char> gdb_abspath (const char *path) { gdb_assert (path != NULL && path[0] != '\0'); if (path[0] == '~') return gdb_tilde_expand_up (path); if (IS_ABSOLUTE_PATH (path)) return gdb::unique_xmalloc_ptr<char> (xstrdup (path)); /* Beware the // my son, the Emacs barfs, the botch that catch... */ return gdb::unique_xmalloc_ptr<char> (concat (current_directory, IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) ? "" : SLASH_STRING, path, (char *) NULL)); }
static void add_entry (struct entry **entp, const char *filename, int is_system) { int len; struct entry *n; n = XNEW (struct entry); n->flags = is_system ? FLAG_SYSTEM : 0; n->next = NULL; len = strlen (filename); if (len > 4 && (FILENAME_CMP (filename + len - 4, ".zip") == 0 || FILENAME_CMP (filename + len - 4, ".jar") == 0)) { n->flags |= FLAG_ZIP; /* If the user uses -classpath then he'll have to include libgcj.jar in the value. We check for this in a simplistic way. Symlinks will fool this test. This is only used for -MM and -MMD, so it probably isn't terribly important. */ if (! FILENAME_CMP (filename, LIBGCJ_ZIP_FILE)) n->flags |= FLAG_SYSTEM; } /* Note that we add a trailing separator to `.zip' names as well. This is a little hack that lets the searching code in jcf-io.c work more easily. Eww. */ if (! IS_DIR_SEPARATOR (filename[len - 1])) { char *f2 = (char *) alloca (len + 2); strcpy (f2, filename); f2[len] = DIR_SEPARATOR; f2[len + 1] = '\0'; n->name = xstrdup (f2); ++len; } else n->name = xstrdup (filename); if (len > longest_path) longest_path = len; append_entry (entp, n); }
/* Initialization of the front end environment, before command line options are parsed. Signal handlers, internationalization etc. ARGV0 is main's argv[0]. */ static void general_init (const char *argv0) { const char *p; p = argv0 + strlen (argv0); while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) --p; progname = p; xmalloc_set_program_name (progname); hex_init (); gcc_init_libintl (); line_table = XNEW (struct line_maps); linemap_init (line_table); line_table->reallocator = xrealloc; }
const char * file_basename (const char *name, const char sep) { const char *base; #if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* Skip over the disk name in MSDOS pathnames. */ if (isalpha (name[0]) && name[1] == ':') name += 2; #endif for (base = name; *name; name++) { if ((sep != '\0' && *name == sep) || IS_DIR_SEPARATOR (*name)) { base = name + 1; } } return base; }
gdb::unique_xmalloc_ptr<char> gdb_realpath_keepfile (const char *filename) { const char *base_name = lbasename (filename); char *dir_name; char *result; /* Extract the basename of filename, and return immediately a copy of filename if it does not contain any directory prefix. */ if (base_name == filename) return gdb::unique_xmalloc_ptr<char> (xstrdup (filename)); dir_name = (char *) alloca ((size_t) (base_name - filename + 2)); /* Allocate enough space to store the dir_name + plus one extra character sometimes needed under Windows (see below), and then the closing \000 character. */ 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] == ':') { 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 directory separator, avoid doubling it. */ gdb::unique_xmalloc_ptr<char> path_storage = gdb_realpath (dir_name); const char *real_path = path_storage.get (); if (IS_DIR_SEPARATOR (real_path[strlen (real_path) - 1])) result = concat (real_path, base_name, (char *) NULL); else result = concat (real_path, SLASH_STRING, base_name, (char *) NULL); return gdb::unique_xmalloc_ptr<char> (result); }
static bfd_boolean is_sysrooted_pathname (const char *name) { char *realname; int len; bfd_boolean result; if (ld_canon_sysroot == NULL) return FALSE; realname = lrealpath (name); len = strlen (realname); result = FALSE; if (len > ld_canon_sysroot_len && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len])) { realname[ld_canon_sysroot_len] = '\0'; result = FILENAME_CMP (ld_canon_sysroot, realname) == 0; } free (realname); return result; }
void cd_command (char *dir, int from_tty) { int len; /* Found something other than leading repetitions of "/..". */ int found_real_path; char *p; /* If the new directory is absolute, repeat is a no-op; if relative, repeat might be useful but is more likely to be a mistake. */ dont_repeat (); if (dir == 0) error_no_arg (_("new working directory")); dir = tilde_expand (dir); make_cleanup (xfree, dir); 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 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--; } dir = savestring (dir, len); if (IS_ABSOLUTE_PATH (dir)) current_directory = dir; else { if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])) current_directory = concat (current_directory, dir, (char *)NULL); else current_directory = concat (current_directory, SLASH_STRING, dir, (char *)NULL); xfree (dir); } /* Now simplify any occurrences of `.' and `..' in the pathname. */ found_real_path = 0; for (p = current_directory; *p;) { if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && (p[2] == 0 || IS_DIR_SEPARATOR (p[2]))) strcpy (p, p + 2); else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.' && (p[3] == 0 || IS_DIR_SEPARATOR (p[3]))) { if (found_real_path) { /* Search backwards for the directory just before the "/.." and obliterate it and the "/..". */ char *q = p; while (q != current_directory && !IS_DIR_SEPARATOR (q[-1])) --q; if (q == current_directory) /* current_directory is a relative pathname ("can't happen"--leave it alone). */ ++p; else { strcpy (q - 1, p + 3); p = q - 1; } } else /* We are dealing with leading repetitions of "/..", for example "/../..", which is the Mach super-root. */ p += 3; } else { found_real_path = 1; ++p; } } forget_cached_source_info (); if (from_tty) pwd_command ((char *) 0, 1); }
static char* path_get_dirname (const char *file_name) { register char *base; register int len; base = strrchr (file_name, DIR_SEPARATOR[0]); #ifdef _WIN32 { char *q = strrchr (file_name, '/'); if (base == NULL || (q != NULL && q > base)) base = q; } #endif if (!base) { #ifdef _WIN32 if (is_utf8_alpha (file_name) && file_name[1] == ':') { char drive_colon_dot[4]; drive_colon_dot[0] = file_name[0]; drive_colon_dot[1] = ':'; drive_colon_dot[2] = '.'; drive_colon_dot[3] = '\0'; return safe_strdup (drive_colon_dot); } #endif return safe_strdup ("."); } while (base > file_name && IS_DIR_SEPARATOR (*base)) base--; #ifdef _WIN32 /* base points to the char before the last slash. * * In case file_name is the root of a drive (X:\) or a child of the * root of a drive (X:\foo), include the slash. * * In case file_name is the root share of an UNC path * (\\server\share), add a slash, returning \\server\share\ . * * In case file_name is a direct child of a share in an UNC path * (\\server\share\foo), include the slash after the share name, * returning \\server\share\ . */ if (base == file_name + 1 && is_utf8_alpha (file_name) && file_name[1] == ':') base++; else if (IS_DIR_SEPARATOR (file_name[0]) && IS_DIR_SEPARATOR (file_name[1]) && file_name[2] && !IS_DIR_SEPARATOR (file_name[2]) && base >= file_name + 2) { const char *p = file_name + 2; while (*p && !IS_DIR_SEPARATOR (*p)) p++; if (p == base + 1) { len = (int) strlen (file_name) + 1; base = (char *)malloc(len + 1); strcpy (base, file_name); base[len-1] = DIR_SEPARATOR[0]; base[len] = 0; return base; } if (IS_DIR_SEPARATOR (*p)) { p++; while (*p && !IS_DIR_SEPARATOR (*p)) p++; if (p == base + 1) base++; } } #endif len = (int) 1 + base - file_name; base = (char *)malloc(len + 1); memmove (base, file_name, len); base[len] = 0; return base; }
static _TCHAR* findLibrary(_TCHAR* library, _TCHAR* program) { _TCHAR* c; _TCHAR* path; _TCHAR* fragment; _TCHAR* result; _TCHAR* dot = _T_ECLIPSE("."); size_t progLength, pathLength; size_t fragmentLength; struct _stat stats; if (library != NULL) { path = checkPath(library, programDir, 1); if (_tstat(path, &stats) == 0 && (stats.st_mode & S_IFDIR) != 0) { /* directory, find the highest version eclipse_* library */ result = findFile(path, _T_ECLIPSE("eclipse")); } else { /* file, return it */ result = _tcsdup(path); } if (path != library) free(path); return result; } /* build the equinox.launcher fragment name */ fragmentLength = _tcslen(DEFAULT_EQUINOX_STARTUP) + 1 + _tcslen(wsArg) + 1 + _tcslen(osArg) + 1 + _tcslen(osArchArg) + 1; fragment = malloc(fragmentLength * sizeof(_TCHAR)); _tcscpy(fragment, DEFAULT_EQUINOX_STARTUP); _tcscat(fragment, dot); _tcscat(fragment, wsArg); _tcscat(fragment, dot); _tcscat(fragment, osArg); //!(fragmentOS.equals(Constants.OS_MACOSX) && !Constants.ARCH_X86_64.equals(fragmentArch)) #if !(defined(MACOSX) && !defined(__x86_64__)) /* The Mac fragment covers both archs and does not have that last segment */ _tcscat(fragment, dot); _tcscat(fragment, osArchArg); #endif progLength = pathLength = _tcslen(programDir); #ifdef MACOSX pathLength += 9; #endif path = malloc( (pathLength + 1 + 7 + 1) * sizeof(_TCHAR)); _tcscpy(path, programDir); if (!IS_DIR_SEPARATOR(path[progLength - 1])) { path[progLength] = dirSeparator; path[progLength + 1] = 0; } #ifdef MACOSX _tcscat(path, _T_ECLIPSE("../../../")); #endif _tcscat(path, _T_ECLIPSE("plugins")); c = findFile(path, fragment); free(fragment); if (c == NULL) return c; fragment = c; result = findFile(fragment, _T_ECLIPSE("eclipse")); free(fragment); free(path); return result; }
/* Standard plugin API registerable hook. */ static enum ld_plugin_status onclaim_file (const struct ld_plugin_input_file *file, int *claimed) { /* Let's see if we want to claim this file. */ claim_file_t *claimfile = claimfiles_list; size_t len = strlen (file->name); char *name = xstrdup (file->name); char *p = name + len; bfd_boolean islib; /* Only match the file name without the directory part. */ islib = *p == 'a' && *(p - 1) == '.'; for (; p != name; p--) if (IS_DIR_SEPARATOR (*p)) { p++; break; } while (claimfile) { /* Claim the file only if the file name and size match and don't match the whole library. */ if (!strcmp (p, claimfile->file.name) && claimfile->file.filesize == file->filesize && (!islib || file->offset != 0)) break; claimfile = claimfile->next; } free (name); /* If we decided to claim it, record that fact, and add any symbols that were defined for it by plugin options. */ *claimed = (claimfile != 0); if (claimfile) { char buffer[30]; int fd; TV_MESSAGE (LDPL_INFO, "Claimed: %s [@%ld/%ld]", file->name, (long)file->offset, (long)file->filesize); claimfile->claimed = TRUE; claimfile->file = *file; if (claimfile->n_syms_used && !tv_add_symbols) claim_file_ret = LDPS_ERR; else if (claimfile->n_syms_used) claim_file_ret = (*tv_add_symbols) (claimfile->file.handle, claimfile->n_syms_used, claimfile->symbols); fd = claimfile->file.fd; name = xstrdup (claimfile->file.name); claim_file_ret = tv_release_input_file (claimfile->file.handle); if (claim_file_ret != LDPS_OK) { free (name); return claim_file_ret; } if (read (fd, buffer, sizeof (buffer)) >= 0) { claim_file_ret = LDPS_ERR; TV_MESSAGE (LDPL_FATAL, "Unreleased file descriptor on: %s", name); } free (name); } return claim_file_ret; }
/* Compute the locations of init files that GDB should source and return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If there is no system gdbinit (resp. home gdbinit and local gdbinit) to be loaded, then SYSTEM_GDBINIT (resp. HOME_GDBINIT and LOCAL_GDBINIT) is set to NULL. */ static void get_init_files (const char **system_gdbinit, const char **home_gdbinit, const char **local_gdbinit) { static const char *sysgdbinit = NULL; static char *homeinit = NULL; static const char *localinit = NULL; static int initialized = 0; if (!initialized) { struct stat homebuf, cwdbuf, s; char *homedir; if (SYSTEM_GDBINIT[0]) { int datadir_len = strlen (GDB_DATADIR); int sys_gdbinit_len = strlen (SYSTEM_GDBINIT); char *relocated_sysgdbinit; /* If SYSTEM_GDBINIT lives in data-directory, and data-directory has been provided, search for SYSTEM_GDBINIT there. */ if (gdb_datadir_provided && datadir_len < sys_gdbinit_len && filename_ncmp (SYSTEM_GDBINIT, GDB_DATADIR, datadir_len) == 0 && IS_DIR_SEPARATOR (SYSTEM_GDBINIT[datadir_len])) { /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR to gdb_datadir. */ char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len); char *p; for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p) continue; relocated_sysgdbinit = concat (gdb_datadir, SLASH_STRING, p, (char *) NULL); xfree (tmp_sys_gdbinit); } else { relocated_sysgdbinit = relocate_path (gdb_program_name, SYSTEM_GDBINIT, SYSTEM_GDBINIT_RELOCATABLE); } if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0) sysgdbinit = relocated_sysgdbinit; else xfree (relocated_sysgdbinit); } homedir = getenv ("HOME"); /* If the .gdbinit file in the current directory is the same as the $HOME/.gdbinit file, it should not be sourced. homebuf and cwdbuf are used in that purpose. Make sure that the stats are zero in case one of them fails (this guarantees that they won't match if either exists). */ memset (&homebuf, 0, sizeof (struct stat)); memset (&cwdbuf, 0, sizeof (struct stat)); if (homedir) { homeinit = xstrprintf ("%s/%s", homedir, gdbinit); if (stat (homeinit, &homebuf) != 0) { xfree (homeinit); homeinit = NULL; } } if (stat (gdbinit, &cwdbuf) == 0) { if (!homeinit || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat))) localinit = gdbinit; } initialized = 1; } *system_gdbinit = sysgdbinit; *home_gdbinit = homeinit; *local_gdbinit = localinit; }