tools/mkimage: fix compilation on FreeBSD
[15.05/openwrt.git] / tools / mkimage / patches / 100-portability.patch
1 --- a/tools/kwbimage.c
2 +++ b/tools/kwbimage.c
3 @@ -206,6 +206,30 @@ INVL_DATA:
4         exit (EXIT_FAILURE);
5  }
6  
7 +#ifndef __GLIBC__
8 +#ifndef __FreeBSD__
9 +static ssize_t
10 +getline(char **line, size_t *len, FILE *fd)
11 +{
12 +       char *tmp;
13 +       int tmplen;
14 +
15 +       tmp = fgetln(fd, &tmplen);
16 +       if (!tmp)
17 +               return -1;
18 +
19 +       if (!*line || tmplen > *len) {
20 +               *len = tmplen + 1;
21 +               *line = realloc(*line, *len);
22 +       }
23 +
24 +       strncpy(*line, tmp, tmplen);
25 +       line[tmplen] = 0;
26 +       return tmplen;
27 +}
28 +#endif
29 +#endif
30 +
31  /*
32   * this function sets the kwbimage header by-
33   *     1. Abstracting input command line arguments data
34 --- a/include/image.h
35 +++ b/include/image.h
36 @@ -50,6 +50,10 @@
37  
38  #endif /* USE_HOSTCC */
39  
40 +#ifndef ulong
41 +#define ulong unsigned long
42 +#endif
43 +
44  #if defined(CONFIG_FIT)
45  #include <fdt.h>
46  #include <libfdt.h>