20 |
#ifndef UTIL_H_ |
#ifndef UTIL_H_ |
21 |
#define UTIL_H_ |
#define UTIL_H_ |
22 |
|
|
|
#include <config.h> |
|
|
|
|
23 |
#ifndef HAVE_VASPRINTF |
#ifndef HAVE_VASPRINTF |
24 |
#include <stdarg.h> |
#include <stdarg.h> |
25 |
#endif |
#endif |
26 |
|
#include <stdbool.h> |
27 |
#include <stdio.h> |
#include <stdio.h> |
28 |
#include <stdlib.h> |
#include <stdlib.h> |
29 |
|
|
35 |
__attribute__((__noreturn__)) |
__attribute__((__noreturn__)) |
36 |
__attribute__((__format__(printf, 1, 2))); |
__attribute__((__format__(printf, 1, 2))); |
37 |
|
|
38 |
|
void fatal_command_line(const char * format, ...) |
39 |
|
__attribute__((__noreturn__)) |
40 |
|
__attribute__((__format__(printf, 1, 2))); |
41 |
|
|
42 |
|
void version(void) |
43 |
|
__attribute__((__noreturn__)); |
44 |
|
|
45 |
|
size_t addst(size_t x, size_t y); |
46 |
|
|
47 |
|
size_t mulst(size_t x, size_t y); |
48 |
|
|
49 |
void * xmalloc(size_t size); |
void * xmalloc(size_t size); |
50 |
|
|
51 |
|
#define xnew(type, count) ((type *) xmalloc(mulst((count), sizeof(type)))) |
52 |
|
|
53 |
void * xrealloc(void * p, size_t size); |
void * xrealloc(void * p, size_t size); |
54 |
|
|
55 |
char * xstrdup(const char * s); |
char * xstrdup(const char * s); |
56 |
|
|
57 |
|
char * xstrndup(const char * s, size_t size); |
58 |
|
|
59 |
|
int xasprintf(char ** s, const char * template, ...) __attribute__((__format__(printf, 2, 3))); |
60 |
|
|
61 |
char * xgetcwd(void); |
char * xgetcwd(void); |
62 |
|
|
63 |
FILE * xfopen(const char * file, const char * mode); |
FILE * xfopen(const char * file, const char * mode); |
72 |
|
|
73 |
void mkdirs(const char * path); |
void mkdirs(const char * path); |
74 |
|
|
75 |
|
bool str_starts_with(const char * string, const char * prefix); |
76 |
|
|
77 |
|
bool str_ends_with(const char * string, const char * suffix); |
78 |
|
|
79 |
char * make_path(const char * parent, const char * relative_path); |
char * make_path(const char * parent, const char * relative_path); |
80 |
|
|
81 |
char * make_canonical_path(const char * relative_path); |
char * make_canonical_path(const char * relative_path); |
92 |
|
|
93 |
void copy_file(const char * source_file, const char * destination_file); |
void copy_file(const char * source_file, const char * destination_file); |
94 |
|
|
95 |
int directory_is_empty(const char * directory); |
bool directory_is_empty(const char * directory); |
96 |
|
|
97 |
struct DirListEntry { |
struct DirListEntry { |
98 |
char * name; |
char * name; |
103 |
|
|
104 |
void free_dir_list(struct DirListEntry * list); |
void free_dir_list(struct DirListEntry * list); |
105 |
|
|
106 |
|
#ifndef HAVE_STRNDUP |
107 |
|
char * strndup(const char * s, size_t size); |
108 |
|
#endif |
109 |
|
|
110 |
#ifndef HAVE_VASPRINTF |
#ifndef HAVE_VASPRINTF |
111 |
int vasprintf(char ** s, const char * template, va_list a); |
int vasprintf(char ** s, const char * template, va_list a); |
112 |
#endif |
#endif |
113 |
|
|
114 |
#ifndef HAVE_ASPRINTF |
#ifndef HAVE_ASPRINTF |
115 |
int asprintf(char ** s, const char * template, ...) |
int asprintf(char ** s, const char * template, ...) __attribute__((__format__(printf, 2, 3))); |
|
__attribute__((__format__(printf, 2, 3))); |
|
116 |
#endif |
#endif |
117 |
|
|
118 |
#endif |
#endif |