| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | #ifndef UTIL_H |
|---|
| 2 | 3 | #define UTIL_H |
|---|
| 3 | 4 | |
|---|
| 5 | +#include <stdlib.h> |
|---|
| 4 | 6 | #include <stdarg.h> |
|---|
| 5 | 7 | #include <stdbool.h> |
|---|
| 6 | 8 | #include <getopt.h> |
|---|
| .. | .. |
|---|
| 8 | 10 | /* |
|---|
| 9 | 11 | * Copyright 2011 The Chromium Authors, All Rights Reserved. |
|---|
| 10 | 12 | * Copyright 2008 Jon Loeliger, Freescale Semiconductor, Inc. |
|---|
| 11 | | - * |
|---|
| 12 | | - * This program is free software; you can redistribute it and/or |
|---|
| 13 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 14 | | - * published by the Free Software Foundation; either version 2 of the |
|---|
| 15 | | - * License, or (at your option) any later version. |
|---|
| 16 | | - * |
|---|
| 17 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 18 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 19 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 20 | | - * General Public License for more details. |
|---|
| 21 | | - * |
|---|
| 22 | | - * You should have received a copy of the GNU General Public License |
|---|
| 23 | | - * along with this program; if not, write to the Free Software |
|---|
| 24 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 25 | | - * USA |
|---|
| 26 | 13 | */ |
|---|
| 27 | 14 | |
|---|
| 28 | 15 | #ifdef __GNUC__ |
|---|
| 16 | +#ifdef __clang__ |
|---|
| 29 | 17 | #define PRINTF(i, j) __attribute__((format (printf, i, j))) |
|---|
| 18 | +#else |
|---|
| 19 | +#define PRINTF(i, j) __attribute__((format (gnu_printf, i, j))) |
|---|
| 20 | +#endif |
|---|
| 30 | 21 | #define NORETURN __attribute__((noreturn)) |
|---|
| 31 | 22 | #else |
|---|
| 32 | 23 | #define PRINTF(i, j) |
|---|
| .. | .. |
|---|
| 72 | 63 | extern char *xstrdup(const char *s); |
|---|
| 73 | 64 | |
|---|
| 74 | 65 | extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...); |
|---|
| 66 | +extern int PRINTF(2, 3) xasprintf_append(char **strp, const char *fmt, ...); |
|---|
| 67 | +extern int xavsprintf_append(char **strp, const char *fmt, va_list ap); |
|---|
| 75 | 68 | extern char *join_path(const char *path, const char *name); |
|---|
| 76 | 69 | |
|---|
| 77 | 70 | /** |
|---|
| .. | .. |
|---|
| 98 | 91 | * stderr. |
|---|
| 99 | 92 | * |
|---|
| 100 | 93 | * @param filename The filename to read, or - for stdin |
|---|
| 94 | + * @param len If non-NULL, the amount of data we managed to read |
|---|
| 101 | 95 | * @return Pointer to allocated buffer containing fdt, or NULL on error |
|---|
| 102 | 96 | */ |
|---|
| 103 | | -char *utilfdt_read(const char *filename); |
|---|
| 104 | | - |
|---|
| 105 | | -/** |
|---|
| 106 | | - * Like utilfdt_read(), but also passes back the size of the file read. |
|---|
| 107 | | - * |
|---|
| 108 | | - * @param len If non-NULL, the amount of data we managed to read |
|---|
| 109 | | - */ |
|---|
| 110 | | -char *utilfdt_read_len(const char *filename, off_t *len); |
|---|
| 97 | +char *utilfdt_read(const char *filename, size_t *len); |
|---|
| 111 | 98 | |
|---|
| 112 | 99 | /** |
|---|
| 113 | 100 | * Read a device tree file into a buffer. Does not report errors, but only |
|---|
| .. | .. |
|---|
| 116 | 103 | * |
|---|
| 117 | 104 | * @param filename The filename to read, or - for stdin |
|---|
| 118 | 105 | * @param buffp Returns pointer to buffer containing fdt |
|---|
| 106 | + * @param len If non-NULL, the amount of data we managed to read |
|---|
| 119 | 107 | * @return 0 if ok, else an errno value representing the error |
|---|
| 120 | 108 | */ |
|---|
| 121 | | -int utilfdt_read_err(const char *filename, char **buffp); |
|---|
| 122 | | - |
|---|
| 123 | | -/** |
|---|
| 124 | | - * Like utilfdt_read_err(), but also passes back the size of the file read. |
|---|
| 125 | | - * |
|---|
| 126 | | - * @param len If non-NULL, the amount of data we managed to read |
|---|
| 127 | | - */ |
|---|
| 128 | | -int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len); |
|---|
| 109 | +int utilfdt_read_err(const char *filename, char **buffp, size_t *len); |
|---|
| 129 | 110 | |
|---|
| 130 | 111 | /** |
|---|
| 131 | 112 | * Write a device tree buffer to a file. This will report any errors on |
|---|
| 132 | 113 | * stderr. |
|---|
| 133 | 114 | * |
|---|
| 134 | 115 | * @param filename The filename to write, or - for stdout |
|---|
| 135 | | - * @param blob Poiner to buffer containing fdt |
|---|
| 116 | + * @param blob Pointer to buffer containing fdt |
|---|
| 136 | 117 | * @return 0 if ok, -1 on error |
|---|
| 137 | 118 | */ |
|---|
| 138 | 119 | int utilfdt_write(const char *filename, const void *blob); |
|---|
| .. | .. |
|---|
| 143 | 124 | * an error message for the user. |
|---|
| 144 | 125 | * |
|---|
| 145 | 126 | * @param filename The filename to write, or - for stdout |
|---|
| 146 | | - * @param blob Poiner to buffer containing fdt |
|---|
| 127 | + * @param blob Pointer to buffer containing fdt |
|---|
| 147 | 128 | * @return 0 if ok, else an errno value representing the error |
|---|
| 148 | 129 | */ |
|---|
| 149 | 130 | int utilfdt_write_err(const char *filename, const void *blob); |
|---|