blob: c6500b806e2491debb06bcee95959da01c25cc11 (
plain)
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
|
/*
* Created by yuuta on 7/19/22.
*/
#ifndef LIBAC_HELPERS_H
#define LIBAC_HELPERS_H
#include <stdbool.h>
#define SALLOC(s, out) alloc(NULL, 1, sizeof(s), true, (void **) out)
/**
* Allocate or reallocate a range of memory on heap.
* @param existing The existing range to extend. NULL-able.
* @param count The number of bytes. Final size = count * bytes.
* @param bytes The size. Final size = count * bytes.
* @param zero_out Whether to zero out the newly-allocated memory. Ignored when existing != NULL.
* @param out Output memory range. Not NULL if the return value is AC_E_OK.
* @return AC_E_OK or an error code. When failed, *out is untouched.
* MT-Safe
*/
int alloc(void *existing,
unsigned int count,
unsigned int bytes,
bool zero_out,
void **out);
/**
* Duplicate a string.
* @param str String to duplicate.
* @param out Output string. Not NULL if the return value is AC_E_OK.
* @return AC_E_OK or an error code. When failed, *out is untouched.
* MT-Safe
*/
int strdup2(const char *str, char **out);
/**
* Cross-platform thread-safe wrapper of strerror(3).
* @param errnum errno
* @return Always non-NULL error message.
* MT-Safe
*/
char *strerror2(int errnum);
/**
* Cleanup any necessary memory during exit of the current thread.
*/
void helpers_cleanup(void);
#endif /* LIBAC_HELPERS_H */
|