author | Medo <smaxein@googlemail.com> |
Tue, 12 Jun 2012 11:25:05 +0200 | |
changeset 7224 | 5143861c83bd |
parent 7179 | f84805e6df03 |
child 7227 | 1c859f572d72 |
permissions | -rw-r--r-- |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
1 |
#ifndef FLIB_UTIL_H_ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
#define FLIB_UTIL_H_ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
3 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
#include <stddef.h> |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
#include <stdarg.h> |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
/** |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
* Prints a format string to a newly allocated buffer of the required size. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
* Parameters are like those for printf. Returns NULL on error. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
* |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
* Returned buffer must be free()d |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
*/ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
char *flib_asprintf(const char *fmt, ...); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
/** |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
16 |
* Exactly as flib_asprintf, but accepts a va_list. |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
17 |
*/ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
char *flib_vasprintf(const char *fmt, va_list args); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
/** |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
* Return a duplicate of the provided string, or NULL if an error |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
* occurs or if str is already NULL. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
* |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
* Returned buffer must be free()d |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
*/ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
char *flib_strdupnull(const char *str); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
/** |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
* Return a duplicate of the provided buffer, or NULL if an error |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
* occurs or if buf is already NULL or if size is 0. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
* |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
* Returned buffer must be free()d |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
*/ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
void *flib_bufdupnull(const void *buf, size_t size); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
36 |
/** |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
37 |
* Simple malloc wrapper that automatically logs an error if no memory |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
38 |
* is available. Otherwise behaves exactly like malloc. |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
39 |
*/ |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
40 |
void *flib_malloc(size_t size); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
41 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
42 |
/** |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
43 |
* Simple calloc wrapper that automatically logs an error if no memory |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
44 |
* is available. Otherwise behaves exactly like calloc. |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
45 |
*/ |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
46 |
void *flib_calloc(size_t count, size_t elementsize); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
47 |
|
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
#endif |