Orcania: include/orcania.h Source File

Orcania Potluck with different functions for different purposes that can be shared among C programs

orcania.h
Go to the documentation of this file.
1
28#ifndef __ORCANIA_H__
29#define __ORCANIA_H__
30
31#ifdef __cplusplus
32extern "C"
33{
34#endif
35
36#include "orcania-cfg.h"
37
38#include <stdio.h>
39#include <stdlib.h>
40
61char * str_replace(const char * source, const char * str_old, const char * str_new);
62
70char * o_strdup(const char * source);
71
80char * o_strndup(const char * source, size_t len);
81
89int o_strcmp(const char * p1, const char * p2);
90
99int o_strncmp(const char * p1, const char * p2, size_t n);
100
108char * o_strcpy(char * p1, const char * p2);
109
118char * o_strncpy(char * p1, const char * p2, size_t n);
119
127int o_strcasecmp(const char * p1, const char * p2);
128
137int o_strncasecmp(const char * p1, const char * p2, size_t n);
138
146char * o_strstr(const char * haystack, const char * needle);
147
156char * o_strnstr(const char * haystack, const char * needle, size_t len);
157
165char * o_strcasestr(const char * haystack, const char * needle);
166
174char * o_strchr(const char * haystack, int c);
175
184const char * o_strnchr(const char * haystack, size_t len, char c);
185
193char * o_strrchr(const char * haystack, int c);
194
203const char * o_strrnchr(const char * haystack, size_t len, char c);
204
211size_t o_strlen(const char * s);
212
219char * trimwhitespace(char * str);
220
227char * trimcharacter(char * str, char to_remove);
228
241char * msprintf(const char * message, ...);
242
253char * mstrcatf(char * source, const char * message, ...);
254
277size_t split_string(const char * string, const char * separator, char *** return_array);
278
284void free_string_array(char ** array);
285
291size_t string_array_size(char ** array);
292
299int string_array_has_value(const char ** array, const char * needle);
300
307int string_array_has_value_case(const char ** array, const char * needle);
308
315int string_array_has_value_n(const char ** array, const char * needle, size_t len);
316
323int string_array_has_value_ncase(const char ** array, const char * needle, size_t len);
324
331int string_array_has_trimmed_value(const char ** array, const char * needle);
332
339char * string_array_join(const char ** array, const char * separator);
340
349 struct _pointer_list {
350 size_t size; /* size of the list */
351 void ** list; /* list of pointers */
352};
353
359void pointer_list_init(struct _pointer_list * pointer_list);
360
366void pointer_list_clean(struct _pointer_list * pointer_list);
367
375void pointer_list_clean_free(struct _pointer_list * pointer_list, void (* free_function)(void * elt));
376
382size_t pointer_list_size(struct _pointer_list * pointer_list);
383
391int pointer_list_append(struct _pointer_list * pointer_list, void * element);
392
399void * pointer_list_get_at(struct _pointer_list * pointer_list, size_t index);
400
408int pointer_list_remove_at(struct _pointer_list * pointer_list, size_t index);
409
419int pointer_list_remove_at_free(struct _pointer_list * pointer_list, size_t index, void (* free_function)(void * elt));
420
429int pointer_list_insert_at(struct _pointer_list * pointer_list, void * element, size_t index);
430
438int pointer_list_remove_pointer(struct _pointer_list * pointer_list, void * element);
439
449int pointer_list_remove_pointer_free(struct _pointer_list * pointer_list, void * element, void (* free_function)(void * elt));
450
460/* C89 allows these to be macros */
461#undef malloc
462#undef realloc
463#undef free
464
468 typedef void *(*o_malloc_t)(size_t);
469 typedef void *(*o_realloc_t)(void *, size_t);
470 typedef void (*o_free_t)(void *);
471
477void * o_malloc(size_t size);
478
485void * o_realloc(void * ptr, size_t size);
486
490void o_free(void * ptr);
491
498void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn);
499
506void o_get_alloc_funcs(o_malloc_t * malloc_fn, o_realloc_t * realloc_fn, o_free_t * free_fn);
507
527int o_base64_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
528
539int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
540
551int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
552
563int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
564
576int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
577
589int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
590
595#ifdef __cplusplus
596}
597#endif
598
599#endif // __ORCANIA_H__
o_base64url_encode
int o_base64url_encode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:183
o_base64url_decode
int o_base64url_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:227
o_base64_encode
int o_base64_encode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:26
o_base64_decode
int o_base64_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:99
o_base64url_2_base64
int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:259
o_base64_2_base64url
int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:297
o_malloc_t
void *(* o_malloc_t)(size_t)
Definition: orcania.h:468
o_set_alloc_funcs
void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn)
Definition: memory.c:43
o_realloc
void * o_realloc(void *ptr, size_t size)
Definition: memory.c:27
o_malloc
void * o_malloc(size_t size)
Definition: memory.c:19
o_free
void o_free(void *ptr)
Definition: memory.c:35
o_realloc_t
void *(* o_realloc_t)(void *, size_t)
Definition: orcania.h:469
o_free_t
void(* o_free_t)(void *)
Definition: orcania.h:470
o_get_alloc_funcs
void o_get_alloc_funcs(o_malloc_t *malloc_fn, o_realloc_t *realloc_fn, o_free_t *free_fn)
Definition: memory.c:49
pointer_list_remove_at
int pointer_list_remove_at(struct _pointer_list *pointer_list, size_t index)
Definition: orcania.c:751
pointer_list_remove_pointer
int pointer_list_remove_pointer(struct _pointer_list *pointer_list, void *element)
Definition: orcania.c:814
pointer_list_get_at
void * pointer_list_get_at(struct _pointer_list *pointer_list, size_t index)
Definition: orcania.c:738
pointer_list_append
int pointer_list_append(struct _pointer_list *pointer_list, void *element)
Definition: orcania.c:717
pointer_list_clean_free
void pointer_list_clean_free(struct _pointer_list *pointer_list, void(*free_function)(void *elt))
Definition: orcania.c:690
pointer_list_size
size_t pointer_list_size(struct _pointer_list *pointer_list)
Definition: orcania.c:704
pointer_list_remove_at_free
int pointer_list_remove_at_free(struct _pointer_list *pointer_list, size_t index, void(*free_function)(void *elt))
Definition: orcania.c:776
pointer_list_remove_pointer_free
int pointer_list_remove_pointer_free(struct _pointer_list *pointer_list, void *element, void(*free_function)(void *elt))
Definition: orcania.c:834
pointer_list_insert_at
int pointer_list_insert_at(struct _pointer_list *pointer_list, void *element, size_t index)
Definition: orcania.c:790
pointer_list_init
void pointer_list_init(struct _pointer_list *pointer_list)
Definition: orcania.c:665
pointer_list_clean
void pointer_list_clean(struct _pointer_list *pointer_list)
Definition: orcania.c:676
string_array_has_value
int string_array_has_value(const char **array, const char *needle)
Definition: orcania.c:568
string_array_has_value_case
int string_array_has_value_case(const char **array, const char *needle)
Definition: orcania.c:585
string_array_size
size_t string_array_size(char **array)
Definition: orcania.c:488
string_array_join
char * string_array_join(const char **array, const char *separator)
Definition: orcania.c:499
split_string
size_t split_string(const char *string, const char *separator, char ***return_array)
Definition: orcania.c:437
free_string_array
void free_string_array(char **array)
Definition: orcania.c:474
string_array_has_value_n
int string_array_has_value_n(const char **array, const char *needle, size_t len)
Definition: orcania.c:602
string_array_has_value_ncase
int string_array_has_value_ncase(const char **array, const char *needle, size_t len)
Definition: orcania.c:619
string_array_has_trimmed_value
int string_array_has_trimmed_value(const char **array, const char *needle)
Definition: orcania.c:636
o_strncpy
char * o_strncpy(char *p1, const char *p2, size_t n)
Definition: orcania.c:250
o_strrchr
char * o_strrchr(const char *haystack, int c)
Definition: orcania.c:334
o_strndup
char * o_strndup(const char *source, size_t len)
Definition: orcania.c:185
o_strcmp
int o_strcmp(const char *p1, const char *p2)
Definition: orcania.c:206
o_strcasestr
char * o_strcasestr(const char *haystack, const char *needle)
Definition: orcania.c:409
msprintf
char * msprintf(const char *message,...)
Definition: orcania.c:107
o_strcpy
char * o_strcpy(char *p1, const char *p2)
Definition: orcania.c:238
o_strstr
char * o_strstr(const char *haystack, const char *needle)
Definition: orcania.c:294
o_strlen
size_t o_strlen(const char *s)
Definition: orcania.c:421
o_strrnchr
const char * o_strrnchr(const char *haystack, size_t len, char c)
Definition: orcania.c:346
mstrcatf
char * mstrcatf(char *source, const char *message,...)
Definition: orcania.c:135
trimcharacter
char * trimcharacter(char *str, char to_remove)
Definition: orcania.c:544
o_strcasecmp
int o_strcasecmp(const char *p1, const char *p2)
Definition: orcania.c:262
trimwhitespace
char * trimwhitespace(char *str)
Definition: orcania.c:520
o_strdup
char * o_strdup(const char *source)
Definition: orcania.c:176
o_strchr
char * o_strchr(const char *haystack, int c)
Definition: orcania.c:306
o_strncasecmp
int o_strncasecmp(const char *p1, const char *p2, size_t n)
Definition: orcania.c:278
str_replace
char * str_replace(const char *source, const char *str_old, const char *str_new)
Definition: orcania.c:57
o_strnchr
const char * o_strnchr(const char *haystack, size_t len, char c)
Definition: orcania.c:318
o_strncmp
int o_strncmp(const char *p1, const char *p2, size_t n)
Definition: orcania.c:222
o_strnstr
char * o_strnstr(const char *haystack, const char *needle, size_t len)
Definition: orcania.c:397
_pointer_list
Definition: orcania.h:349
_pointer_list::size
size_t size
Definition: orcania.h:350
_pointer_list::list
void ** list
Definition: orcania.h:351