From f7ea3708c38bd38851baafa83e98d95602e53cbc Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 6 Mar 2008 12:16:55 +1100 Subject: 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 --- srcpos.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'srcpos.c') diff --git a/srcpos.c b/srcpos.c index c8eaa1e..9641b76 100644 --- a/srcpos.c +++ b/srcpos.c @@ -82,9 +82,8 @@ struct dtc_file *dtc_open_file(const char *fname, if (fname[0] == '/') { file->file = fopen(fname, "r"); - if (!file->file) - goto out; + goto fail; file->name = strdup(fname); return file; @@ -98,15 +97,13 @@ struct dtc_file *dtc_open_file(const char *fname, return file; if (errno != ENOENT) - goto out; + goto fail; search = search->next; } -out: - free(file->dir); - free(file); - return NULL; +fail: + die("Couldn't open \"%s\": %s\n", fname, strerror(errno)); } void dtc_close_file(struct dtc_file *file) -- cgit v1.1