-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhelper.h
58 lines (44 loc) · 1.54 KB
/
helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* copyfs - copy on write filesystem http://n0x.org/copyfs/
* Copyright (C) 2004 Nicolas Vigier <[email protected]>
* Thomas Joubert <[email protected]>
* This program can be distributed under the terms of the GNU GPL.
* See the file COPYING.
*/
#ifndef HELPER_H
# define HELPER_H
# include <stdio.h>
# include <sys/types.h>
# define LINE_BUFFER_STEP 1024
/*
* Safe memory allocation
*/
void *helper_malloc(size_t size, char *file, int line,
const char *fn);
void *helper_realloc(void *ptr, size_t size, char *file, int line,
const char *fn);
char *helper_strdup(const char *str, char *file, int line,
const char *fn);
# define safe_malloc(s) \
helper_malloc(s, __FILE__, __LINE__, __func__)
# define safe_realloc(p, s) \
helper_realloc(p, s, __FILE__, __LINE__, __func__)
# define safe_strdup(s) \
helper_strdup(s, __FILE__, __LINE__, __func__)
/*
* String arrays
*/
char **helper_split_to_array(const char *string, char separator);
void helper_free_array(char **array);
int helper_array_has_prefix(char **longest, char **shortest);
char *helper_build_composite(char *format, char *separator, ...);
/*
* Miscellaneous things
*/
unsigned char helper_hash_string(const char *string);
char *helper_read_line(FILE *fh);
char *helper_get_file_name(char *base, char *prefix);
char *helper_extract_filename(const char *path);
char *helper_extract_dirname(const char *path);
char *helper_create_meta_name(const char *vpath, char *prefix);
#endif /* !HELPER_H */