2015-12-04 14:47:52 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2015-12-04 14:47:52 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2016-09-06 16:44:05 +00:00
|
|
|
#ifndef _SHARED_H
|
|
|
|
#define _SHARED_H
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
#include <stdarg.h>
|
2016-09-08 12:11:35 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-09-05 19:47:26 +00:00
|
|
|
#include <unistd.h>
|
2016-09-28 21:53:46 +00:00
|
|
|
#include <time.h>
|
2016-09-28 22:25:36 +00:00
|
|
|
#include <fcntl.h>
|
2017-03-19 14:11:41 +00:00
|
|
|
#include <ctype.h>
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2017-02-23 09:39:17 +00:00
|
|
|
bool overflow_check_u32_add (const u32 a, const u32 b);
|
|
|
|
bool overflow_check_u32_mul (const u32 a, const u32 b);
|
|
|
|
bool overflow_check_u64_add (const u64 a, const u64 b);
|
|
|
|
bool overflow_check_u64_mul (const u64 a, const u64 b);
|
2017-02-22 15:33:23 +00:00
|
|
|
|
2016-09-20 15:04:31 +00:00
|
|
|
bool is_power_of_2 (const u32 v);
|
|
|
|
|
2016-09-08 08:01:49 +00:00
|
|
|
u32 get_random_num (const u32 min, const u32 max);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-09-08 08:01:49 +00:00
|
|
|
u32 mydivc32 (const u32 dividend, const u32 divisor);
|
|
|
|
u64 mydivc64 (const u64 dividend, const u64 divisor);
|
|
|
|
|
2016-09-24 19:44:43 +00:00
|
|
|
char *filename_from_filepath (char *filepath);
|
|
|
|
|
2016-09-30 15:41:40 +00:00
|
|
|
void naive_replace (char *s, const char key_char, const char replace_char);
|
|
|
|
void naive_escape (char *s, size_t s_max, const char key_char, const char escape_char);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
void hc_asprintf (char **strp, const char *fmt, ...);
|
|
|
|
|
2016-10-30 17:55:27 +00:00
|
|
|
void setup_environment_variables (void);
|
|
|
|
void setup_umask (void);
|
2016-09-28 21:53:46 +00:00
|
|
|
void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed);
|
|
|
|
|
2016-10-31 10:28:06 +00:00
|
|
|
int hc_stat (const char *pathname, hc_stat_t *buf);
|
|
|
|
int hc_fstat (int fd, hc_stat_t *buf);
|
|
|
|
|
2016-11-16 09:22:57 +00:00
|
|
|
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
|
|
|
|
void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
bool hc_path_is_file (const char *path);
|
|
|
|
bool hc_path_is_directory (const char *path);
|
|
|
|
bool hc_path_is_empty (const char *path);
|
|
|
|
bool hc_path_exist (const char *path);
|
|
|
|
bool hc_path_read (const char *path);
|
|
|
|
bool hc_path_write (const char *path);
|
2017-01-27 23:08:12 +00:00
|
|
|
bool hc_path_create (const char *path);
|
2017-01-27 10:46:45 +00:00
|
|
|
|
2017-03-19 14:11:41 +00:00
|
|
|
bool hc_string_is_digit (const char *s);
|
|
|
|
|
2017-06-02 08:08:19 +00:00
|
|
|
void hc_string_trim_trailing (char *s);
|
|
|
|
void hc_string_trim_leading (char *s);
|
|
|
|
|
2017-07-06 08:35:25 +00:00
|
|
|
size_t hc_fread (void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
|
|
void hc_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream);
|
|
|
|
|
2017-08-16 17:43:41 +00:00
|
|
|
hc_time_t hc_time (hc_time_t *t);
|
|
|
|
struct tm *hc_gmtime (const hc_time_t *t, MAYBE_UNUSED struct tm *result);
|
|
|
|
char *hc_ctime (const hc_time_t *t, char *buf, MAYBE_UNUSED const size_t buf_size);
|
2017-08-16 15:51:35 +00:00
|
|
|
|
2016-09-06 16:44:05 +00:00
|
|
|
#endif // _SHARED_H
|