summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2015-04-22 14:18:53 +0200
committerMarc Kleine-Budde <mkl@pengutronix.de>2015-04-28 14:20:04 +0200
commit5c8d221da14421f9d2f5ae6c48510f017de2eef4 (patch)
tree17d4acd5332a99c48682329ff4bfcf18a1185814
parent39fd620b83b45e6b9f85c5a988e4a63e916000dc (diff)
downloaddt-utils-5c8d221da14421f9d2f5ae6c48510f017de2eef4.tar.gz
dt-utils-5c8d221da14421f9d2f5ae6c48510f017de2eef4.tar.xz
libdt: move read_file() to common.h
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--src/dt/common.h41
-rw-r--r--src/fdtdump.c43
2 files changed, 43 insertions, 41 deletions
diff --git a/src/dt/common.h b/src/dt/common.h
index 6127bea..c5acd27 100644
--- a/src/dt/common.h
+++ b/src/dt/common.h
@@ -1,9 +1,14 @@
#ifndef __DT_COMMON_H
#define __DT_COMMON_H
+#include <fcntl.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <stdint.h>
+#include <unistd.h>
+
+#include <sys/stat.h>
+
/**
* container_of - cast a member of a structure out to the containing structure
@@ -109,6 +114,40 @@ static inline size_t strlcpy(char *dest, const char *src, size_t size)
return ret;
}
+static inline void *read_file(const char *filename, size_t *size)
+{
+ int fd;
+ struct stat s;
+ void *buf = NULL;
+ int ret;
+
+ if (stat(filename, &s))
+ return NULL;
+
+ buf = xzalloc(s.st_size + 1);
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ goto err_out;
+
+ if (read(fd, buf, s.st_size) < s.st_size)
+ goto err_out1;
+
+ close(fd);
+
+ if (size)
+ *size = s.st_size;
+
+ return buf;
+
+err_out1:
+ close(fd);
+err_out:
+ free(buf);
+
+ return NULL;
+}
+
#define cpu_to_be32 __cpu_to_be32
#define be32_to_cpu __be32_to_cpu
diff --git a/src/fdtdump.c b/src/fdtdump.c
index d438a84..54bc77d 100644
--- a/src/fdtdump.c
+++ b/src/fdtdump.c
@@ -1,46 +1,9 @@
-#include <linux/types.h>
-
+#include <errno.h>
#include <stdio.h>
-#include <dt/dt.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include <unistd.h>
-#include <errno.h>
-
-void *read_file(const char *filename, size_t *size)
-{
- int fd;
- struct stat s;
- void *buf = NULL;
- int ret;
-
- if (stat(filename, &s))
- return NULL;
-
- buf = xzalloc(s.st_size + 1);
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- goto err_out;
-
- if (read(fd, buf, s.st_size) < s.st_size)
- goto err_out1;
-
- close(fd);
-
- if (size)
- *size = s.st_size;
-
- return buf;
-
-err_out1:
- close(fd);
-err_out:
- free(buf);
-
- return NULL;
-}
+#include <common.h>
+#include <dt/dt.h>
int main(int argc, char *argv[])
{