gcc/ * alloc-pool.c, asan.c, auto-inc-dec.c, basic-block.h, bb-reorder.c, bitmap.c, bitmap.h, bt-load.c, builtins.c, calls.c, cfgcleanup.c, cfgexpand.c, cfghooks.c, cfgloop.c, cfgloopmanip.c, cfgrtl.c, cgraph.c, cgraph.h, cgraphbuild.c, cgraphclones.c, cgraphunit.c, collect2.c, combine-stack-adj.c, combine.c, compare-elim.c, context.c, context.h, cprop.c, cse.c, cselib.c, dbxout.c, dce.c, defaults.h, df-core.c, df-problems.c, df-scan.c, df.h, diagnostic.c, double-int.c, dse.c, dumpfile.c, dwarf2asm.c, dwarf2cfi.c, dwarf2out.c, emit-rtl.c, errors.c, except.c, expmed.c, expr.c, file-find.c, final.c, fixed-value.c, fold-const.c, function.c, fwprop.c, gcc-ar.c, gcc.c, gcov-io.c, gcov-io.h, gcov.c, gcse.c, genattr-common.c, genattr.c, genattrtab.c, genautomata.c, genconfig.c, genemit.c, genextract.c, genflags.c, gengenrtl.c, gengtype-state.c, gengtype.c, genmodes.c, genopinit.c, genoutput.c, genpeep.c, genpreds.c, genrecog.c, gensupport.c, ggc-common.c, ggc-page.c, gimple-fold.c, gimple-low.c, gimple-pretty-print.c, gimple-ssa-strength-reduction.c, gimple.c, gimple.h, godump.c, graphite-clast-to-gimple.c, graphite-optimize-isl.c, graphite-poly.h, graphite-sese-to-poly.c, graphite.c, haifa-sched.c, hash-table.c, hash-table.h, hwint.c, hwint.h, ifcvt.c, incpath.c, init-regs.c, input.h, intl.c, intl.h, ipa-cp.c, ipa-devirt.c, ipa-inline-analysis.c, ipa-inline.c, ipa-profile.c, ipa-pure-const.c, ipa-reference.c, ipa-split.c, ipa-utils.c, ipa.c, ira-build.c, ira.c, jump.c, loop-doloop.c, loop-init.c, loop-invariant.c, loop-iv.c, lower-subreg.c, lto-cgraph.c, lto-streamer-in.c, lto-streamer-out.c, lto-wrapper.c, mcf.c, mode-switching.c, modulo-sched.c, omp-low.c, optabs.c, opts.c, pass_manager.h, passes.c, plugin.c, postreload-gcse.c, postreload.c, predict.c, prefix.c, pretty-print.c, print-rtl.c, print-tree.c, profile.c, read-md.c, real.c, real.h, recog.c, ree.c, reg-stack.c, regcprop.c, reginfo.c, regmove.c, regrename.c, regs.h, regstat.c, reload1.c, reorg.c, rtl.c, rtl.h, rtlanal.c, sbitmap.c, sched-rgn.c, sdbout.c, sel-sched-ir.c, sel-sched.c, sparseset.c, stack-ptr-mod.c, statistics.c, stmt.c, stor-layout.c, store-motion.c, streamer-hooks.h, system.h, target-hooks-macros.h, targhooks.c, targhooks.h, toplev.c, tracer.c, trans-mem.c, tree-browser.c, tree-call-cdce.c, tree-cfg.c, tree-cfgcleanup.c, tree-complex.c, tree-data-ref.c, tree-data-ref.h, tree-eh.c, tree-emutls.c, tree-flow.h, tree-if-conv.c, tree-into-ssa.c, tree-iterator.c, tree-loop-distribution.c, tree-mudflap.c, tree-nested.c, tree-nomudflap.c, tree-nrv.c, tree-object-size.c, tree-optimize.c, tree-pass.h, tree-pretty-print.c, tree-profile.c, tree-scalar-evolution.c, tree-sra.c, tree-ssa-ccp.c, tree-ssa-coalesce.c, tree-ssa-copy.c, tree-ssa-copyrename.c, tree-ssa-dce.c, tree-ssa-dom.c, tree-ssa-dse.c, tree-ssa-forwprop.c, tree-ssa-ifcombine.c, tree-ssa-live.c, tree-ssa-loop-ch.c, tree-ssa-loop-im.c, tree-ssa-loop-ivopts.c, tree-ssa-loop-prefetch.c, tree-ssa-loop.c, tree-ssa-math-opts.c, tree-ssa-operands.c, tree-ssa-phiopt.c, tree-ssa-phiprop.c, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sink.c, tree-ssa-strlen.c, tree-ssa-structalias.c, tree-ssa-threadedge.c, tree-ssa-threadupdate.c, tree-ssa-uncprop.c, tree-ssa-uninit.c, tree-ssa.c, tree-ssanames.c, tree-stdarg.c, tree-switch-conversion.c, tree-tailcall.c, tree-vect-data-refs.c, tree-vect-generic.c, tree-vect-loop-manip.c, tree-vect-stmts.c, tree-vectorizer.c, tree-vectorizer.h, tree-vrp.c, tree.c, tree.h, tsan.c, tsystem.h, value-prof.c, var-tracking.c, varasm.c, vec.h, vmsdbgout.c, vtable-verify.c, web.c: Add missing whitespace before "(". From-SVN: r203004
194 lines
4.2 KiB
C
194 lines
4.2 KiB
C
/* Utility functions for finding files relative to GCC binaries.
|
|
Copyright (C) 1992-2013 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#include "filenames.h"
|
|
#include "file-find.h"
|
|
|
|
static bool debug = false;
|
|
|
|
void
|
|
find_file_set_debug (bool debug_state)
|
|
{
|
|
debug = debug_state;
|
|
}
|
|
|
|
char *
|
|
find_a_file (struct path_prefix *pprefix, const char *name, int mode)
|
|
{
|
|
char *temp;
|
|
struct prefix_list *pl;
|
|
int len = pprefix->max_len + strlen (name) + 1;
|
|
|
|
if (debug)
|
|
fprintf (stderr, "Looking for '%s'\n", name);
|
|
|
|
#ifdef HOST_EXECUTABLE_SUFFIX
|
|
len += strlen (HOST_EXECUTABLE_SUFFIX);
|
|
#endif
|
|
|
|
temp = XNEWVEC (char, len);
|
|
|
|
/* Determine the filename to execute (special case for absolute paths). */
|
|
|
|
if (IS_ABSOLUTE_PATH (name))
|
|
{
|
|
if (access (name, mode) == 0)
|
|
{
|
|
strcpy (temp, name);
|
|
|
|
if (debug)
|
|
fprintf (stderr, " - found: absolute path\n");
|
|
|
|
return temp;
|
|
}
|
|
|
|
#ifdef HOST_EXECUTABLE_SUFFIX
|
|
/* Some systems have a suffix for executable files.
|
|
So try appending that. */
|
|
strcpy (temp, name);
|
|
strcat (temp, HOST_EXECUTABLE_SUFFIX);
|
|
|
|
if (access (temp, mode) == 0)
|
|
return temp;
|
|
#endif
|
|
|
|
if (debug)
|
|
fprintf (stderr, " - failed to locate using absolute path\n");
|
|
}
|
|
else
|
|
for (pl = pprefix->plist; pl; pl = pl->next)
|
|
{
|
|
struct stat st;
|
|
|
|
strcpy (temp, pl->prefix);
|
|
strcat (temp, name);
|
|
|
|
if (stat (temp, &st) >= 0
|
|
&& ! S_ISDIR (st.st_mode)
|
|
&& access (temp, mode) == 0)
|
|
return temp;
|
|
|
|
#ifdef HOST_EXECUTABLE_SUFFIX
|
|
/* Some systems have a suffix for executable files.
|
|
So try appending that. */
|
|
strcat (temp, HOST_EXECUTABLE_SUFFIX);
|
|
|
|
if (stat (temp, &st) >= 0
|
|
&& ! S_ISDIR (st.st_mode)
|
|
&& access (temp, mode) == 0)
|
|
return temp;
|
|
#endif
|
|
}
|
|
|
|
if (debug && pprefix->plist == NULL)
|
|
fprintf (stderr, " - failed: no entries in prefix list\n");
|
|
|
|
free (temp);
|
|
return 0;
|
|
}
|
|
|
|
/* Add an entry for PREFIX to prefix list PPREFIX. */
|
|
|
|
void
|
|
add_prefix (struct path_prefix *pprefix, const char *prefix)
|
|
{
|
|
struct prefix_list *pl, **prev;
|
|
int len;
|
|
|
|
if (pprefix->plist)
|
|
{
|
|
for (pl = pprefix->plist; pl->next; pl = pl->next)
|
|
;
|
|
prev = &pl->next;
|
|
}
|
|
else
|
|
prev = &pprefix->plist;
|
|
|
|
/* Keep track of the longest prefix. */
|
|
|
|
len = strlen (prefix);
|
|
if (len > pprefix->max_len)
|
|
pprefix->max_len = len;
|
|
|
|
pl = XNEW (struct prefix_list);
|
|
pl->prefix = xstrdup (prefix);
|
|
|
|
if (*prev)
|
|
pl->next = *prev;
|
|
else
|
|
pl->next = (struct prefix_list *) 0;
|
|
*prev = pl;
|
|
}
|
|
|
|
/* Take the value of the environment variable ENV, break it into a path, and
|
|
add of the entries to PPREFIX. */
|
|
|
|
void
|
|
prefix_from_env (const char *env, struct path_prefix *pprefix)
|
|
{
|
|
const char *p;
|
|
p = getenv (env);
|
|
|
|
if (p)
|
|
prefix_from_string (p, pprefix);
|
|
}
|
|
|
|
void
|
|
prefix_from_string (const char *p, struct path_prefix *pprefix)
|
|
{
|
|
const char *startp, *endp;
|
|
char *nstore = XNEWVEC (char, strlen (p) + 3);
|
|
|
|
if (debug)
|
|
fprintf (stderr, "Convert string '%s' into prefixes, separator = '%c'\n", p, PATH_SEPARATOR);
|
|
|
|
startp = endp = p;
|
|
while (1)
|
|
{
|
|
if (*endp == PATH_SEPARATOR || *endp == 0)
|
|
{
|
|
strncpy (nstore, startp, endp-startp);
|
|
if (endp == startp)
|
|
{
|
|
strcpy (nstore, "./");
|
|
}
|
|
else if (! IS_DIR_SEPARATOR (endp[-1]))
|
|
{
|
|
nstore[endp-startp] = DIR_SEPARATOR;
|
|
nstore[endp-startp+1] = 0;
|
|
}
|
|
else
|
|
nstore[endp-startp] = 0;
|
|
|
|
if (debug)
|
|
fprintf (stderr, " - add prefix: %s\n", nstore);
|
|
|
|
add_prefix (pprefix, nstore);
|
|
if (*endp == 0)
|
|
break;
|
|
endp = startp = endp + 1;
|
|
}
|
|
else
|
|
endp++;
|
|
}
|
|
free (nstore);
|
|
}
|