Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
util.h
Go to the documentation of this file.
1 #ifndef _UTIL_H
2 #define _UTIL_H
3 
4 #include <stdarg.h>
5 
6 /*
7  * Copyright 2011 The Chromium Authors, All Rights Reserved.
8  * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of the
13  * License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */
25 
26 static inline void __attribute__((noreturn)) die(char * str, ...)
27 {
28  va_list ap;
29 
30  va_start(ap, str);
31  fprintf(stderr, "FATAL ERROR: ");
32  vfprintf(stderr, str, ap);
33  exit(1);
34 }
35 
36 static inline void *xmalloc(size_t len)
37 {
38  void *new = malloc(len);
39 
40  if (!new)
41  die("malloc() failed\n");
42 
43  return new;
44 }
45 
46 static inline void *xrealloc(void *p, size_t len)
47 {
48  void *new = realloc(p, len);
49 
50  if (!new)
51  die("realloc() failed (len=%d)\n", len);
52 
53  return new;
54 }
55 
56 extern char *xstrdup(const char *s);
57 extern char *join_path(const char *path, const char *name);
58 
66 int util_is_printable_string(const void *data, int len);
67 
68 /*
69  * Parse an escaped character starting at index i in string s. The resulting
70  * character will be returned and the index i will be updated to point at the
71  * character directly after the end of the encoding, this may be the '\0'
72  * terminator of the string.
73  */
74 char get_escape_char(const char *s, int *i);
75 
83 char *utilfdt_read(const char *filename);
84 
94 int utilfdt_read_err(const char *filename, char **buffp);
95 
96 
105 int utilfdt_write(const char *filename, const void *blob);
106 
116 int utilfdt_write_err(const char *filename, const void *blob);
117 
141 int utilfdt_decode_type(const char *fmt, int *type, int *size);
142 
143 /*
144  * This is a usage message fragment for the -t option. It is the format
145  * supported by utilfdt_decode_type.
146  */
147 
148 #define USAGE_TYPE_MSG \
149  "<type>\ts=string, i=int, u=unsigned, x=hex\n" \
150  "\tOptional modifier prefix:\n" \
151  "\t\thh or b=byte, h=2 byte, l=4 byte (default)\n";
152 
153 #endif /* _UTIL_H */