1/*
2Copyright (c) 2016 Raspberry Pi (Trading) Ltd.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef UTILS_H
29#define UTILS_H
30
31typedef struct string_struct
32{
33 struct string_struct *prev;
34 struct string_struct *next;
35 char data[0];
36} STRING_T;
37
38typedef struct string_vec_struct
39{
40 int num_strings;
41 int max_strings;
42 char **strings;
43} STRING_VEC_T;
44
45typedef struct overlay_help_state_struct OVERLAY_HELP_STATE_T;
46
47extern int opt_verbose;
48extern int opt_dry_run;
49
50OVERLAY_HELP_STATE_T *overlay_help_open(const char *helpfile);
51void overlay_help_close(OVERLAY_HELP_STATE_T *state);
52int overlay_help_find(OVERLAY_HELP_STATE_T *state, const char *name);
53int overlay_help_find_field(OVERLAY_HELP_STATE_T *state, const char *field);
54const char *overlay_help_field_data(OVERLAY_HELP_STATE_T *state);
55void overlay_help_print_field(OVERLAY_HELP_STATE_T *state,
56 const char *field, const char *label,
57 int indent, int strip_blanks);
58
59int run_cmd(const char *fmt, ...);
60void free_string(const char *string); /* Not thread safe */
61void free_strings(void); /* Not thread safe */
62char *sprintf_dup(const char *fmt, ...); /* Not thread safe */
63char *vsprintf_dup(const char *fmt, va_list ap); /* Not thread safe */
64int dir_exists(const char *dirname);
65int file_exists(const char *dirname);
66void string_vec_init(STRING_VEC_T *vec);
67char *string_vec_add(STRING_VEC_T *vec, const char *str, int len);
68int string_vec_find(STRING_VEC_T *vec, const char *str, int len);
69void string_vec_sort(STRING_VEC_T *vec);
70void string_vec_uninit(STRING_VEC_T *vec);
71int error(const char *fmt, ...);
72void fatal_error(const char *fmt, ...);
73
74#endif
75