From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Jon Loeliger <jdl-CYoMK+44s/E@public.gmane.org>
Cc: devicetree-discuss-mnsaURCQ41sdnm+yROfE0A@public.gmane.org
Subject: [1/5] dtc: Move some functions to util.[ch]
Date: Sat, 4 Oct 2008 22:27:06 +1000 (EST) [thread overview]
Message-ID: <20081004122706.4ADF6DDE0A@ozlabs.org> (raw)
In-Reply-To: <20081004122157.GT30184-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
Now that we have a util.[ch] file shared between dtc and
convert-dtsv0, move some functions which are currently duplicated in
the two to util files. Specifically we move the die(), xmalloc() and
xrealloc() functions.
While we're at it, add standard double-include protection to util.h
Signed-off-by: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
---
convert-dtsv0-lexer.l | 20 --------------------
dtc.h | 30 ------------------------------
util.h | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 50 deletions(-)
Index: dtc/convert-dtsv0-lexer.l
===================================================================
--- dtc.orig/convert-dtsv0-lexer.l 2008-10-04 15:20:44.000000000 +1000
+++ dtc/convert-dtsv0-lexer.l 2008-10-04 22:22:23.000000000 +1000
@@ -52,26 +52,6 @@ static char *last_name; /* = NULL */
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-static inline void __attribute__((noreturn)) die(char * str, ...)
-{
- va_list ap;
-
- va_start(ap, str);
- fprintf(stderr, "FATAL ERROR: ");
- vfprintf(stderr, str, ap);
- exit(1);
-}
-
-static inline void *xmalloc(size_t len)
-{
- void *new = malloc(len);
-
- if (! new)
- die("malloc() failed\n");
-
- return new;
-}
-
const struct {
const char *pattern;
int obase, width;
Index: dtc/dtc.h
===================================================================
--- dtc.orig/dtc.h 2008-10-04 15:19:46.000000000 +1000
+++ dtc/dtc.h 2008-10-04 22:22:23.000000000 +1000
@@ -53,36 +53,6 @@ extern int reservenum; /* Number of mem
extern int minsize; /* Minimum blob size */
extern int padsize; /* Additional padding to blob */
-static inline void __attribute__((noreturn)) die(char * str, ...)
-{
- va_list ap;
-
- va_start(ap, str);
- fprintf(stderr, "FATAL ERROR: ");
- vfprintf(stderr, str, ap);
- exit(1);
-}
-
-static inline void *xmalloc(size_t len)
-{
- void *new = malloc(len);
-
- if (! new)
- die("malloc() failed\n");
-
- return new;
-}
-
-static inline void *xrealloc(void *p, size_t len)
-{
- void *new = realloc(p, len);
-
- if (! new)
- die("realloc() failed (len=%d)\n", len);
-
- return new;
-}
-
typedef uint32_t cell_t;
Index: dtc/util.h
===================================================================
--- dtc.orig/util.h 2008-10-04 15:20:03.000000000 +1000
+++ dtc/util.h 2008-10-04 22:22:23.000000000 +1000
@@ -1,3 +1,6 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
/*
* Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
*
@@ -17,4 +20,36 @@
* USA
*/
+static inline void __attribute__((noreturn)) die(char * str, ...)
+{
+ va_list ap;
+
+ va_start(ap, str);
+ fprintf(stderr, "FATAL ERROR: ");
+ vfprintf(stderr, str, ap);
+ exit(1);
+}
+
+static inline void *xmalloc(size_t len)
+{
+ void *new = malloc(len);
+
+ if (!new)
+ die("malloc() failed\n");
+
+ return new;
+}
+
+static inline void *xrealloc(void *p, size_t len)
+{
+ void *new = realloc(p, len);
+
+ if (!new)
+ die("realloc() failed (len=%d)\n", len);
+
+ return new;
+}
+
extern char *xstrdup(const char *s);
+
+#endif /* _UTIL_H */
next prev parent reply other threads:[~2008-10-04 12:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-04 12:21 [0/5] Input file and srcpos rework (v2) David Gibson
[not found] ` <20081004122157.GT30184-787xzQ0H9iRg7VrjXcPTGA@public.gmane.org>
2008-10-04 12:27 ` [3/5] dtc: Cleanup line number tracking, add column number tracking David Gibson
2008-10-04 12:27 ` [4/5] dtc: Cleanup srcpos_string() David Gibson
2008-10-04 12:27 ` [5/5] dtc: Cleanup YYLTYPE and YYLLOC_DEFAULT declarations David Gibson
2008-10-04 12:27 ` [2/5] dtc: Simpler interface to source file management David Gibson
2008-10-04 12:27 ` David Gibson [this message]
2008-10-08 19:52 ` [0/5] Input file and srcpos rework (v2) Jon Loeliger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081004122706.4ADF6DDE0A@ozlabs.org \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-discuss-mnsaURCQ41sdnm+yROfE0A@public.gmane.org \
--cc=jdl-CYoMK+44s/E@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.