2009-04-30 08:25:52 -04:00
|
|
|
|
|
|
|
#ifndef __MISC_H__
|
|
|
|
#define __MISC_H__
|
|
|
|
|
2017-01-06 03:44:18 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-30 08:51:36 -04:00
|
|
|
#include <stdint.h>
|
2014-09-27 16:59:19 -04:00
|
|
|
#include <time.h>
|
2017-01-13 17:32:59 -05:00
|
|
|
#include <pthread.h>
|
2010-09-18 11:15:41 -04:00
|
|
|
|
|
|
|
struct onekeyval {
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
struct onekeyval *next;
|
2014-08-15 16:56:39 -04:00
|
|
|
struct onekeyval *sort;
|
2010-09-18 11:15:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct keyval {
|
|
|
|
struct onekeyval *head;
|
|
|
|
struct onekeyval *tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-30 08:25:52 -04:00
|
|
|
int
|
2010-02-02 15:02:24 -05:00
|
|
|
safe_atoi32(const char *str, int32_t *val);
|
2009-04-30 08:25:52 -04:00
|
|
|
|
2010-02-08 08:58:14 -05:00
|
|
|
int
|
|
|
|
safe_atou32(const char *str, uint32_t *val);
|
|
|
|
|
2010-05-05 13:03:53 -04:00
|
|
|
int
|
|
|
|
safe_hextou32(const char *str, uint32_t *val);
|
|
|
|
|
2009-04-30 08:25:52 -04:00
|
|
|
int
|
2010-02-02 15:02:24 -05:00
|
|
|
safe_atoi64(const char *str, int64_t *val);
|
2010-01-10 06:09:29 -05:00
|
|
|
|
2010-02-08 08:58:14 -05:00
|
|
|
int
|
|
|
|
safe_atou64(const char *str, uint64_t *val);
|
|
|
|
|
2010-04-04 12:07:32 -04:00
|
|
|
int
|
|
|
|
safe_hextou64(const char *str, uint64_t *val);
|
|
|
|
|
2010-09-18 11:15:41 -04:00
|
|
|
|
|
|
|
/* Key/value functions */
|
2014-08-15 16:56:39 -04:00
|
|
|
struct keyval *
|
|
|
|
keyval_alloc(void);
|
|
|
|
|
2010-09-18 11:15:41 -04:00
|
|
|
int
|
|
|
|
keyval_add(struct keyval *kv, const char *name, const char *value);
|
|
|
|
|
|
|
|
int
|
|
|
|
keyval_add_size(struct keyval *kv, const char *name, const char *value, size_t size);
|
|
|
|
|
|
|
|
void
|
|
|
|
keyval_remove(struct keyval *kv, const char *name);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
keyval_get(struct keyval *kv, const char *name);
|
|
|
|
|
|
|
|
void
|
|
|
|
keyval_clear(struct keyval *kv);
|
|
|
|
|
2014-08-15 16:56:39 -04:00
|
|
|
void
|
|
|
|
keyval_sort(struct keyval *kv);
|
|
|
|
|
2010-09-18 11:15:41 -04:00
|
|
|
|
2010-01-09 07:43:29 -05:00
|
|
|
char *
|
|
|
|
m_realpath(const char *pathname);
|
|
|
|
|
2010-06-21 11:50:09 -04:00
|
|
|
char *
|
2015-05-31 09:05:31 -04:00
|
|
|
unicode_fixup_string(char *str, const char *fromcode);
|
2010-06-21 11:50:09 -04:00
|
|
|
|
2014-08-15 16:56:39 -04:00
|
|
|
char *
|
|
|
|
trimwhitespace(const char *str);
|
|
|
|
|
2009-04-30 08:51:36 -04:00
|
|
|
uint32_t
|
2016-01-17 14:59:16 -05:00
|
|
|
djb_hash(const void *data, size_t len);
|
2009-04-30 08:51:36 -04:00
|
|
|
|
2009-05-01 14:56:22 -04:00
|
|
|
char *
|
|
|
|
b64_decode(const char *b64);
|
|
|
|
|
2010-04-12 12:22:38 -04:00
|
|
|
char *
|
2016-07-29 13:53:56 -04:00
|
|
|
b64_encode(const uint8_t *in, size_t len);
|
2010-04-12 12:22:38 -04:00
|
|
|
|
2010-01-04 11:58:28 -05:00
|
|
|
uint64_t
|
|
|
|
murmur_hash64(const void *key, int len, uint32_t seed);
|
|
|
|
|
2014-09-27 16:59:19 -04:00
|
|
|
/* Timer function for platforms without hi-res timers */
|
2011-02-17 10:21:35 -05:00
|
|
|
int
|
|
|
|
clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res);
|
|
|
|
|
|
|
|
struct timespec
|
|
|
|
timespec_add(struct timespec time1, struct timespec time2);
|
|
|
|
|
|
|
|
int
|
|
|
|
timespec_cmp(struct timespec time1, struct timespec time2);
|
|
|
|
|
2017-01-13 17:32:59 -05:00
|
|
|
/* mutex wrappers with checks */
|
|
|
|
void
|
|
|
|
fork_mutex_init(pthread_mutex_t *mutex);
|
|
|
|
void
|
|
|
|
fork_mutex_lock(pthread_mutex_t *mutex);
|
|
|
|
void
|
|
|
|
fork_mutex_unlock(pthread_mutex_t *mutex);
|
|
|
|
void
|
|
|
|
fork_mutex_destroy(pthread_mutex_t *mutex);
|
|
|
|
|
|
|
|
/* condition wrappers with checks */
|
|
|
|
void
|
|
|
|
fork_cond_init(pthread_cond_t *cond);
|
|
|
|
void
|
|
|
|
fork_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
|
|
|
int
|
|
|
|
fork_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
|
|
|
const struct timespec *ts);
|
|
|
|
void
|
|
|
|
fork_cond_signal(pthread_cond_t *cond);
|
|
|
|
void
|
|
|
|
fork_cond_destroy(pthread_cond_t *cond);
|
|
|
|
|
2009-04-30 08:25:52 -04:00
|
|
|
#endif /* !__MISC_H__ */
|