diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-15 15:07:35 (GMT) |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-15 15:07:35 (GMT) |
commit | 5f2434a66dfa4701b81b79a78eaf9c32da0f8839 (patch) | |
tree | 8c38f1fb0d0fbcd15e496df89be00ad8c4918a43 /arch/powerpc/boot/dtc-src/srcpos.c | |
parent | 278429cff8809958d25415ba0ed32b59866ab1a8 (diff) | |
parent | 6dc6472581f693b5fc95aebedf67b4960fb85cf0 (diff) | |
download | linux-fsl-qoriq-5f2434a66dfa4701b81b79a78eaf9c32da0f8839.tar.xz |
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc: (158 commits)
powerpc: Fix CHRP PCI config access for indirect_pci
powerpc/chrp: Fix detection of Python PCI host bridge on IBM CHRPs
powerpc: Fix 32-bit SMP boot on CHRP
powerpc: Fix link errors on 32-bit machines using legacy DMA
powerpc/pci: Improve detection of unassigned bridge resources
hvc_console: Fix free_irq in spinlocked section
powerpc: Get USE_STRICT_MM_TYPECHECKS working again
powerpc: Reflect the used arguments in machine_init() prototype
powerpc: Fix DMA offset for non-coherent DMA
powerpc: fix fsl_upm nand driver modular build
powerpc/83xx: add NAND support for the MPC8360E-RDK boards
powerpc: FPGA support for GE Fanuc SBC610
i2c: MPC8349E-mITX Power Management and GPIO expander driver
powerpc: reserve two DMA channels for audio in MPC8610 HPCD device tree
powerpc: document the "fsl,ssi-dma-channel" compatible property
powerpc: disable CHRP and PMAC support in various defconfigs
OF: add fsl,mcu-mpc8349emitx to the exception list
powerpc/83xx: add DS1374 RTC support for the MPC837xE-MDS boards
powerpc: remove support for bootmem-allocated memory for the DIU driver
powerpc: remove non-dependent load fsl_booke PTE_64BIT
...
Diffstat (limited to 'arch/powerpc/boot/dtc-src/srcpos.c')
-rw-r--r-- | arch/powerpc/boot/dtc-src/srcpos.c | 121 |
1 files changed, 66 insertions, 55 deletions
diff --git a/arch/powerpc/boot/dtc-src/srcpos.c b/arch/powerpc/boot/dtc-src/srcpos.c index 352b0fe..9641b76 100644 --- a/arch/powerpc/boot/dtc-src/srcpos.c +++ b/arch/powerpc/boot/dtc-src/srcpos.c @@ -20,86 +20,97 @@ #include "dtc.h" #include "srcpos.h" - -/* - * Record the complete unique set of opened file names. - * Primarily used to cache source position file names. - */ -#define MAX_N_FILE_NAMES (100) - -const char *file_names[MAX_N_FILE_NAMES]; -static int n_file_names = 0; - /* * Like yylineno, this is the current open file pos. */ -int srcpos_filenum = -1; - +struct dtc_file *srcpos_file; - -FILE *dtc_open_file(const char *fname) +static int dtc_open_one(struct dtc_file *file, + const char *search, + const char *fname) { - FILE *f; + char *fullname; - if (lookup_file_name(fname, 1) < 0) - die("Too many files opened\n"); + if (search) { + fullname = xmalloc(strlen(search) + strlen(fname) + 2); - if (streq(fname, "-")) - f = stdin; - else - f = fopen(fname, "r"); + strcpy(fullname, search); + strcat(fullname, "/"); + strcat(fullname, fname); + } else { + fullname = strdup(fname); + } - if (! f) - die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); + file->file = fopen(fullname, "r"); + if (!file->file) { + free(fullname); + return 0; + } - return f; + file->name = fullname; + return 1; } +struct dtc_file *dtc_open_file(const char *fname, + const struct search_path *search) +{ + static const struct search_path default_search = { NULL, NULL, NULL }; -/* - * Locate and optionally add filename fname in the file_names[] array. - * - * If the filename is currently not in the array and the boolean - * add_it is non-zero, an attempt to add the filename will be made. - * - * Returns; - * Index [0..MAX_N_FILE_NAMES) where the filename is kept - * -1 if the name can not be recorded - */ + struct dtc_file *file; + const char *slash; -int lookup_file_name(const char *fname, int add_it) -{ - int i; + file = xmalloc(sizeof(struct dtc_file)); - for (i = 0; i < n_file_names; i++) { - if (strcmp(file_names[i], fname) == 0) - return i; + slash = strrchr(fname, '/'); + if (slash) { + char *dir = xmalloc(slash - fname + 1); + + memcpy(dir, fname, slash - fname); + dir[slash - fname] = 0; + file->dir = dir; + } else { + file->dir = NULL; } - if (add_it) { - if (n_file_names < MAX_N_FILE_NAMES) { - file_names[n_file_names] = strdup(fname); - return n_file_names++; - } + if (streq(fname, "-")) { + file->name = "stdin"; + file->file = stdin; + return file; } - return -1; -} + if (fname[0] == '/') { + file->file = fopen(fname, "r"); + if (!file->file) + goto fail; + + file->name = strdup(fname); + return file; + } + if (!search) + search = &default_search; -const char *srcpos_filename_for_num(int filenum) -{ - if (0 <= filenum && filenum < n_file_names) { - return file_names[filenum]; + while (search) { + if (dtc_open_one(file, search->dir, fname)) + return file; + + if (errno != ENOENT) + goto fail; + + search = search->next; } - return 0; +fail: + die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); } - -const char *srcpos_get_filename(void) +void dtc_close_file(struct dtc_file *file) { - return srcpos_filename_for_num(srcpos_filenum); + if (fclose(file->file)) + die("Error closing \"%s\": %s\n", file->name, strerror(errno)); + + free(file->dir); + free(file); } |