[Crosstoolchain-logs] [device-tree-compiler] 261/357: dtc: Make dtc_open_file() die() if unable to open requested file

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:20 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit f7ea3708c38bd38851baafa83e98d95602e53cbc
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Thu Mar 6 12:16:55 2008 +1100

    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 at gibson.dropbear.id.au>
---
 dtc-lexer.l |  3 ---
 dtc.c       |  4 ----
 fstree.c    |  4 ++--
 srcpos.c    | 11 ++++-------
 4 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index 0cd3f69..a643ab3 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -259,9 +259,6 @@ void push_input_file(const char *filename)
 	}
 
 	newfile = dtc_open_file(filename, searchptr);
-	if (!newfile)
-		die("Couldn't open \"%s\": %s", filename, strerror(errno));
-
 
 	incl_file = xmalloc(sizeof(struct incl_file));
 
diff --git a/dtc.c b/dtc.c
index 90e1cce..75517f9 100644
--- a/dtc.c
+++ b/dtc.c
@@ -193,10 +193,6 @@ int main(int argc, char *argv[])
 		bi = dt_from_fs(arg);
 	} else if(streq(inform, "dtb")) {
 		inf = dtc_open_file(arg, NULL);
-		if (!inf)
-			die("Couldn't open \"%s\": %s\n", arg,
-			    strerror(errno));
-
 		bi = dt_from_blob(inf->file);
 	} else {
 		die("Unknown input format \"%s\"\n", inform);
diff --git a/fstree.c b/fstree.c
index 2fc5773..0c0bdf0 100644
--- a/fstree.c
+++ b/fstree.c
@@ -31,8 +31,8 @@ static struct node *read_fstree(const char *dirname)
 	struct node *tree;
 
 	d = opendir(dirname);
-	if (! d)
-		die("opendir(): %s\n", strerror(errno));
+	if (!d)
+		die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
 
 	tree = build_node(NULL, NULL);
 
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)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list