Browse Source

dtc: Make dtc_open_file() die() if unable to open requested file

All current callers of dtc_open_file() immediately die() if it returns
an error.  In a non-interative tool like dtc, it's hard to see what
you could sensibly do to recover from a failure to open an input file
in any case.

Therefore, make dtc_open_file() itself die() if there's an error
opening the requested file.  This removes the need for error checking
at the callsites, and ensures a consistent error message in all cases.
While we're at it, change the rror message from fstree.c when we fail
to open the input directory to match dtc_open_file()'s error message.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 17 years ago committed by Jon Loeliger
parent
commit
f7ea3708c3
  1. 3
      dtc-lexer.l
  2. 4
      dtc.c
  3. 4
      fstree.c
  4. 11
      srcpos.c

3
dtc-lexer.l

@ -259,9 +259,6 @@ void push_input_file(const char *filename)
} }


newfile = dtc_open_file(filename, searchptr); newfile = dtc_open_file(filename, searchptr);
if (!newfile)
die("Couldn't open \"%s\": %s", filename, strerror(errno));



incl_file = xmalloc(sizeof(struct incl_file)); incl_file = xmalloc(sizeof(struct incl_file));



4
dtc.c

@ -193,10 +193,6 @@ int main(int argc, char *argv[])
bi = dt_from_fs(arg); bi = dt_from_fs(arg);
} else if(streq(inform, "dtb")) { } else if(streq(inform, "dtb")) {
inf = dtc_open_file(arg, NULL); inf = dtc_open_file(arg, NULL);
if (!inf)
die("Couldn't open \"%s\": %s\n", arg,
strerror(errno));

bi = dt_from_blob(inf->file); bi = dt_from_blob(inf->file);
} else { } else {
die("Unknown input format \"%s\"\n", inform); die("Unknown input format \"%s\"\n", inform);

4
fstree.c

@ -31,8 +31,8 @@ static struct node *read_fstree(const char *dirname)
struct node *tree; struct node *tree;


d = opendir(dirname); d = opendir(dirname);
if (! d) if (!d)
die("opendir(): %s\n", strerror(errno)); die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));


tree = build_node(NULL, NULL); tree = build_node(NULL, NULL);



11
srcpos.c

@ -82,9 +82,8 @@ struct dtc_file *dtc_open_file(const char *fname,


if (fname[0] == '/') { if (fname[0] == '/') {
file->file = fopen(fname, "r"); file->file = fopen(fname, "r");

if (!file->file) if (!file->file)
goto out; goto fail;


file->name = strdup(fname); file->name = strdup(fname);
return file; return file;
@ -98,15 +97,13 @@ struct dtc_file *dtc_open_file(const char *fname,
return file; return file;


if (errno != ENOENT) if (errno != ENOENT)
goto out; goto fail;


search = search->next; search = search->next;
} }


out: fail:
free(file->dir); die("Couldn't open \"%s\": %s\n", fname, strerror(errno));
free(file);
return NULL;
} }


void dtc_close_file(struct dtc_file *file) void dtc_close_file(struct dtc_file *file)

Loading…
Cancel
Save