// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright 2007 Jon Loeliger, Freescale Semiconductor, Inc.
*/
#ifndef _GNU_SOURCE #define _GNU_SOURCE #endif
#include <stdio.h>
#include"dtc.h" #include"srcpos.h"
/* A node in our list of directories to search for source/include files */ struct search_path { struct search_path *next; /* next node in list, NULL for end */ constchar *dirname; /* name of directory to search */
};
/* This is the list of directories that we search for source files */ staticstruct search_path *search_path_head, **search_path_tail;
/** * Try to open a file in a given directory. * * If the filename is an absolute path, then dirname is ignored. If it is a * relative path, then we look in that directory for the file. * * @param dirname Directory to look in, or NULL for none * @param fname Filename to look for * @param fp Set to NULL if file did not open * @return allocated filename on success (caller must free), NULL on failure
*/ staticchar *try_open(constchar *dirname, constchar *fname, FILE **fp)
{ char *fullname;
/** * Open a file for read access * * If it is a relative filename, we search the full search path for it. * * @param fname Filename to open * @param fp Returns pointer to opened FILE, or NULL on failure * @return pointer to allocated filename, which caller must free
*/ staticchar *fopen_any_on_path(constchar *fname, FILE **fp)
{ constchar *cur_dir = NULL; struct search_path *node; char *fullname;
/* Try current directory first */
assert(fp); if (current_srcfile)
cur_dir = current_srcfile->dir;
fullname = try_open(cur_dir, fname, fp);
/* Failing that, try each search path in turn */ for (node = search_path_head; !*fp && node; node = node->next)
fullname = try_open(node->dirname, fname, fp);
if (fclose(srcfile->f))
die("Error closing \"%s\": %s\n", srcfile->name,
strerror(errno));
/* FIXME: We allow the srcfile_state structure to leak, * because it could still be referenced from a location * variable being carried through the parser somewhere. To * fix this we could either allocate all the files from a
* table, or use a pool allocator. */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.