aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc/util.h')
-rw-r--r--scripts/dtc/util.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/scripts/dtc/util.h b/scripts/dtc/util.h
index f5c4f1b50d30..ad5f41199edb 100644
--- a/scripts/dtc/util.h
+++ b/scripts/dtc/util.h
@@ -25,9 +25,17 @@
25 * USA 25 * USA
26 */ 26 */
27 27
28#ifdef __GNUC__
29#define PRINTF(i, j) __attribute__((format (printf, i, j)))
30#define NORETURN __attribute__((noreturn))
31#else
32#define PRINTF(i, j)
33#define NORETURN
34#endif
35
28#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 36#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29 37
30static inline void __attribute__((noreturn)) die(const char *str, ...) 38static inline void NORETURN PRINTF(1, 2) die(const char *str, ...)
31{ 39{
32 va_list ap; 40 va_list ap;
33 41
@@ -53,13 +61,14 @@ static inline void *xrealloc(void *p, size_t len)
53 void *new = realloc(p, len); 61 void *new = realloc(p, len);
54 62
55 if (!new) 63 if (!new)
56 die("realloc() failed (len=%d)\n", len); 64 die("realloc() failed (len=%zd)\n", len);
57 65
58 return new; 66 return new;
59} 67}
60 68
61extern char *xstrdup(const char *s); 69extern char *xstrdup(const char *s);
62extern int xasprintf(char **strp, const char *fmt, ...); 70
71extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...);
63extern char *join_path(const char *path, const char *name); 72extern char *join_path(const char *path, const char *name);
64 73
65/** 74/**
@@ -188,7 +197,7 @@ void utilfdt_print_data(const char *data, int len);
188/** 197/**
189 * Show source version and exit 198 * Show source version and exit
190 */ 199 */
191void util_version(void) __attribute__((noreturn)); 200void NORETURN util_version(void);
192 201
193/** 202/**
194 * Show usage and exit 203 * Show usage and exit
@@ -202,9 +211,10 @@ void util_version(void) __attribute__((noreturn));
202 * @param long_opts The structure of long options 211 * @param long_opts The structure of long options
203 * @param opts_help An array of help strings (should align with long_opts) 212 * @param opts_help An array of help strings (should align with long_opts)
204 */ 213 */
205void util_usage(const char *errmsg, const char *synopsis, 214void NORETURN util_usage(const char *errmsg, const char *synopsis,
206 const char *short_opts, struct option const long_opts[], 215 const char *short_opts,
207 const char * const opts_help[]) __attribute__((noreturn)); 216 struct option const long_opts[],
217 const char * const opts_help[]);
208 218
209/** 219/**
210 * Show usage and exit 220 * Show usage and exit