20#include <freeciv_config.h>
31#define MAX_LEN_ADDR 256
32#define MAX_LEN_PATH 4095
36#define FC_INFINITY (1000 * 1000 * 1000)
38#ifndef FREECIV_TESTMATIC
41#define BAD_HEURISTIC_INIT(_ini_val_) = _ini_val_
43#define BAD_HEURISTIC_INIT(_ini_val_)
47#define BOOL_TO_TRISTATE(tri) ((tri) ? TRI_YES : TRI_NO)
54#define MAX(x,y) (((x)>(y))?(x):(y))
55#define MIN(x,y) (((x)<(y))?(x):(y))
57#define CLIP(lower,current,upper) \
58 ((current)<(lower)?(lower):(current)>(upper)?(upper):(current))
61#define ABS(x) (((x) >= 0) ? (x) : -(x))
65#define FC_WRAP(value, range) \
67 ? ((value) % (range) != 0 ? (value) % (range) + (range) : 0) \
68 : ((value) >= (range) ? (value) % (range) : (value)))
70#define BOOL_VAL(x) ((x) != 0)
71#define XOR(p, q) (BOOL_VAL(p) != BOOL_VAL(q))
72#define EQ(p, q) (BOOL_VAL(p) == BOOL_VAL(q))
79 ( (n) / (d) - (( (n) < 0 && (n) % (d) < 0 ) ? 1 : 0) )
81#define MAX_UINT32 0xFFFFFFFF
82#define MAX_UINT16 0xFFFF
85#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
86#define ADD_TO_POINTER(p, n) ((void *)((char *)(p)+(n)))
88#define FC_MEMBER(type, member) (((type *) nullptr)->member)
89#define FC_MEMBER_OFFSETOF(type, member) ((size_t) &FC_MEMBER(type, member))
90#define FC_MEMBER_SIZEOF(type, member) sizeof(FC_MEMBER(type, member))
91#define FC_MEMBER_ARRAY_SIZE(type, member) \
92 ARRAY_SIZE(FC_MEMBER(type, member))
94#define FC_INT_TO_PTR(i) ((void *) (intptr_t) (i))
95#define FC_PTR_TO_INT(p) ((int) (intptr_t) (p))
101#define INITIALIZE_ARRAY(array, size, value) \
105 for (_ini_index = 0; _ini_index < (size); _ini_index++) { \
106 (array)[_ini_index] = (value); \
110#ifndef PATH_SEPARATOR
111#if defined(FREECIV_MSWINDOWS) || defined(_WIN32) || defined(__WIN32__) || defined(__EMX__) || defined(__DJGPP__)
113# define PATH_SEPARATOR ";"
116# define PATH_SEPARATOR ":"
120#if defined(FREECIV_MSWINDOWS) || defined(_WIN32) || defined(__WIN32__) || defined(__EMX__) || defined(__DJGPP__)
122# define DIR_SEPARATOR "\\"
123# define DIR_SEPARATOR_CHAR '\\'
126# define DIR_SEPARATOR_IS_DEFAULT
127# define DIR_SEPARATOR "/"
128# define DIR_SEPARATOR_CHAR '/'
131#define PARENT_DIR_OPERATOR ".."
144 const char *
const *
second);
158#define sz_loud_strlcpy(buffer, str, errmsg) \
159 loud_strlcpy(buffer, str, sizeof(buffer), errmsg)
179#define SPECLIST_TAG fileinfo
180#define SPECLIST_TYPE struct fileinfo
182#define fileinfo_list_iterate(list, pnode) \
183 TYPED_LIST_ITERATE(struct fileinfo, list, pnode)
184#define fileinfo_list_iterate_end LIST_ITERATE_END
226typedef const char *(*m_pre_accessor_fn_t)(
int);
258#define DIRMODE_DEFAULT (-1)
371 out->int_value = value;
int compare_strings(const void *first, const void *second)
void format_time_duration(time_t t, char *buf, int maxlen)
int(* m_pre_strncmp_fn_t)(const char *, const char *, size_t n)
int compare_strings_ptrs(const void *first, const void *second)
void remove_leading_spaces(char *s) fc__attribute((nonnull(1)))
char * user_username(char *buf, size_t bufsz)
int int fc_vsnprintcf(char *buf, size_t buf_len, const char *format, const struct cf_sequence *sequences, size_t sequences_num) fc__attribute((nonnull(1
int int static struct cf_sequence cf_bool_seq(char letter, bool value)
enum fc_tristate fc_tristate_and(enum fc_tristate one, enum fc_tristate two)
size_t() m_strlen_fn_t(const char *str)
static struct cf_sequence cf_char_seq(char letter, char value)
void dont_run_as_root(const char *argv0, const char *fallback)
bool make_dir(const char *pathname, int mode) fc__attribute((nonnull(1)))
bool wildcard_fit_string(const char *pattern, const char *test)
bool check_strlen(const char *str, size_t len, const char *errmsg)
const char * fileinfoname(const struct strvec *dirs, const char *filename)
void remove_trailing_spaces(char *s) fc__attribute((nonnull(1)))
char * user_home_dir(void)
void free_user_home_dir(void)
static struct cf_sequence cf_end(void)
static struct cf_sequence cf_ptr_seq(char letter, const void *value)
const char * m_pre_description(enum m_pre_result result)
static void cf_int_seq(char letter, int value, struct cf_sequence *out)
static struct cf_sequence cf_float_seq(char letter, float value)
static struct cf_sequence cf_str_seq(char letter, const char *value)
static struct cf_sequence cf_trans_bool_seq(char letter, bool value)
char * skip_leading_spaces(char *s) fc__attribute((nonnull(1)))
struct strvec * fileinfolist(const struct strvec *dirs, const char *suffix)
void free_data_dir_names(void)
enum m_pre_result match_prefix_full(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result, int *matches, int max_matches, int *pnum_matches)
const struct strvec * get_scenario_dirs(void)
bool str_to_uint(const char *str, unsigned int *pint) fc__attribute((nonnull(1)))
size_t loud_strlcpy(char *buffer, const char *str, size_t len, const char *errmsg)
char * interpret_tilde_alloc(const char *filename)
static struct cf_sequence cf_hexa_seq(char letter, int value)
void interpret_tilde(char *buf, size_t buf_size, const char *filename)
int compare_strings_strvec(const char *const *first, const char *const *second)
bool is_base64url(const char *s)
void free_multicast_group(void)
void free_fileinfo_data(void)
char * end_of_strn(char *str, int *nleft)
bool path_is_absolute(const char *filename)
bool make_dir_for_file(char *filename) fc__attribute((nonnull(1)))
bool str_to_int(const char *str, int *pint) fc__attribute((nonnull(1)))
bool formats_match(const char *format1, const char *format2)
const char * int_to_text(unsigned int number)
char scanin(const char **buf, char *delimiters, char *dest, int size)
const struct strvec * get_save_dirs(void)
char * skip_to_basename(char *filepath)
bool str_to_float(const char *str, float *pfloat) fc__attribute((nonnull(1)))
void array_shuffle(int *array, int n)
enum m_pre_result match_prefix(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result)
bool is_ascii_name(const char *name)
enum fc_tristate fc_tristate_or(enum fc_tristate one, enum fc_tristate two)
int fc_snprintcf(char *buf, size_t buf_len, const char *format,...) fc__attribute((nonnull(1
const char * setup_langname(void)
void randomize_base64url_string(char *s, size_t n)
char * get_multicast_group(bool ipv6_preferred)
void free_freeciv_storage_dir(void)
const char *(* m_pre_accessor_fn_t)(int)
bool is_safe_filename(const char *name)
void remove_leading_trailing_spaces(char *s)
const char * big_int_to_text(unsigned int mantissa, unsigned int exponent)
const struct strvec * get_data_dirs(void)
char * freeciv_storage_dir(void)
void switch_lang(const char *lang)
struct fileinfo_list * fileinfolist_infix(const struct strvec *dirs, const char *infix, bool nodups)