49 lines
1.0 KiB
C
Raw Normal View History

2021-06-17 17:32:24 -04:00
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2022-07-20 02:58:14 -04:00
#include <iconv.h>
#include <stdint.h>
2021-06-17 17:32:24 -04:00
#include "util.h"
// Set obj To NULL On asprintf() Failure
#define safe_asprintf(obj, ...) \
{ \
if (asprintf(obj, __VA_ARGS__) == -1) { \
*obj = NULL; \
} \
ALLOC_CHECK(*obj); \
}
// Dynamic String Append Macro
#define string_append(str, format, ...) \
{ \
char *old = *str; \
2022-04-22 19:38:15 -04:00
safe_asprintf(str, "%s" format, *str == NULL ? "" : *str, ##__VA_ARGS__); \
2021-06-17 17:32:24 -04:00
ALLOC_CHECK(*str); \
if (old != NULL && old != *str) { \
free(old); \
} \
}
2022-03-14 19:09:25 -04:00
#ifdef __cplusplus
extern "C" {
#endif
2021-06-17 17:32:24 -04:00
// Sanitize String
2022-03-14 19:09:25 -04:00
void sanitize_string(char **str, int max_length, unsigned int allow_newlines);
2022-07-20 02:58:14 -04:00
// CP437
void safe_iconv(iconv_t cd, char *input, size_t input_size, char *output, size_t output_size);
char *to_cp437(const char *input);
char *from_cp437(const char *input);
2022-03-24 22:47:34 -04:00
// Starts With
int starts_with(const char *str, const char *prefix);
2022-03-14 19:09:25 -04:00
#ifdef __cplusplus
2021-06-17 17:32:24 -04:00
}
2022-03-14 19:09:25 -04:00
#endif