1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for string escapes in dtc
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdint.h>
11 #include <errno.h>
12
13 #include <libfdt.h>
14
15 #include "tests.h"
16 #include "testdata.h"
17
18 #define CHUNKSIZE 1024
19
load_file(const char * name,int * len)20 static char *load_file(const char *name, int *len)
21 {
22 FILE *f;
23 char *buf = NULL;
24 int bufsize = 0, n;
25
26 *len = 0;
27
28 f = fopen(name, "r");
29 if (!f)
30 FAIL("Couldn't open \"%s\": %s", name, strerror(errno));
31
32 while (!feof(f)) {
33 if (bufsize < (*len + CHUNKSIZE)) {
34 buf = xrealloc(buf, *len + CHUNKSIZE);
35 bufsize = *len + CHUNKSIZE;
36 }
37
38 n = fread(buf + *len, 1, CHUNKSIZE, f);
39 if (ferror(f))
40 FAIL("Error reading \"%s\": %s", name, strerror(errno));
41 *len += n;
42 }
43
44 return buf;
45 }
46
main(int argc,char * argv[])47 int main(int argc, char *argv[])
48 {
49 void *fdt;
50 char *incbin;
51 int len;
52
53 test_init(argc, argv);
54
55 if (argc != 3)
56 CONFIG("Usage: %s <incbin file> <dtb file>", argv[0]);
57
58 incbin = load_file(argv[1], &len);
59 fdt = load_blob(argv[2]);
60
61 check_getprop(fdt, 0, "incbin", len, incbin);
62 check_getprop(fdt, 0, "incbin-partial", 17, incbin + 13);
63
64 PASS();
65 }
66