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
41 struct _o_datum {
42 size_t size;
43 unsigned char * data;
44};
45
66char * str_replace(const char * source, const char * str_old, const char * str_new);
67
75char * o_strdup(const char * source);
76
85char * o_strndup(const char * source, size_t len);
86
94int o_strcmp(const char * p1, const char * p2);
95
104int o_strncmp(const char * p1, const char * p2, size_t n);
105
113char * o_strcpy(char * p1, const char * p2);
114
123char * o_strncpy(char * p1, const char * p2, size_t n);
124
132int o_strcasecmp(const char * p1, const char * p2);
133
142int o_strncasecmp(const char * p1, const char * p2, size_t n);
143
151char * o_strstr(const char * haystack, const char * needle);
152
161char * o_strnstr(const char * haystack, const char * needle, size_t len);
162
170char * o_strcasestr(const char * haystack, const char * needle);
171
179char * o_strchr(const char * haystack, int c);
180
189const char * o_strnchr(const char * haystack, size_t len, char c);
190
198char * o_strrchr(const char * haystack, int c);
199
208const char * o_strrnchr(const char * haystack, size_t len, char c);
209
214int o_strnullempty(const char * s);
215
222size_t o_strlen(const char * s);
223
230const char * trimwhitespace(char * str);
231
238char * trimcharacter(char * str, char to_remove);
239
252char * msprintf(const char * message, ...);
253
264char * mstrcatf(char * source, const char * message, ...);
265
288size_t split_string(const char * string, const char * separator, char *** return_array);
289
295void free_string_array(char ** array);
296
302size_t string_array_size(char ** array);
303
310int string_array_has_value(const char ** array, const char * needle);
311
318int string_array_has_value_case(const char ** array, const char * needle);
319
326int string_array_has_value_n(const char ** array, const char * needle, size_t len);
327
334int string_array_has_value_ncase(const char ** array, const char * needle, size_t len);
335
342int string_array_has_trimmed_value(const char ** array, const char * needle);
343
350char * string_array_join(const char ** array, const char * separator);
351
360 struct _pointer_list {
361 size_t size; /* size of the list */
362 void ** list; /* list of pointers */
363};
364
370void pointer_list_init(struct _pointer_list * pointer_list);
371
377void pointer_list_clean(struct _pointer_list * pointer_list);
378
386void pointer_list_clean_free(struct _pointer_list * pointer_list, void (* free_function)(void * elt));
387
393size_t pointer_list_size(struct _pointer_list * pointer_list);
394
402int pointer_list_append(struct _pointer_list * pointer_list, void * element);
403
410void * pointer_list_get_at(struct _pointer_list * pointer_list, size_t index);
411
419int pointer_list_remove_at(struct _pointer_list * pointer_list, size_t index);
420
430int pointer_list_remove_at_free(struct _pointer_list * pointer_list, size_t index, void (* free_function)(void * elt));
431
440int pointer_list_insert_at(struct _pointer_list * pointer_list, void * element, size_t index);
441
449int pointer_list_remove_pointer(struct _pointer_list * pointer_list, void * element);
450
460int pointer_list_remove_pointer_free(struct _pointer_list * pointer_list, void * element, void (* free_function)(void * elt));
461
471/* C89 allows these to be macros */
472#undef malloc
473#undef realloc
474#undef free
475
479 typedef void *(*o_malloc_t)(size_t);
480 typedef void *(*o_realloc_t)(void *, size_t);
481 typedef void (*o_free_t)(void *);
482
488void * o_malloc(size_t size);
489
496void * o_realloc(void * ptr, size_t size);
497
501void o_free(void * ptr);
502
509void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn);
510
517void o_get_alloc_funcs(o_malloc_t * malloc_fn, o_realloc_t * realloc_fn, o_free_t * free_fn);
518
538int o_base64_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
539
550int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
551
562int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
563
574int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
575
587int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
588
600int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
601
612int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
613
624int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
625
636int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
637
648int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
649
660int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
661
672int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
673
678#ifdef __cplusplus
679}
680#endif
681
682#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:212
o_base64url_decode
int o_base64url_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:226
o_base64_encode
int o_base64_encode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:184
o_base64_encode_alloc
int o_base64_encode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:312
o_base64url_2_base64_alloc
int o_base64url_2_base64_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:420
o_base64_decode
int o_base64_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition: base64.c:198
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:241
o_base64url_encode_alloc
int o_base64url_encode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:366
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:279
o_base64_2_base64url_alloc
int o_base64_2_base64url_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:448
o_base64url_decode_alloc
int o_base64url_decode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:393
o_base64_decode_alloc
int o_base64_decode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition: base64.c:339
o_malloc_t
void *(* o_malloc_t)(size_t)
Definition: orcania.h:479
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:480
o_free_t
void(* o_free_t)(void *)
Definition: orcania.h:481
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:760
pointer_list_remove_pointer
int pointer_list_remove_pointer(struct _pointer_list *pointer_list, void *element)
Definition: orcania.c:823
pointer_list_get_at
void * pointer_list_get_at(struct _pointer_list *pointer_list, size_t index)
Definition: orcania.c:747
pointer_list_append
int pointer_list_append(struct _pointer_list *pointer_list, void *element)
Definition: orcania.c:726
pointer_list_clean_free
void pointer_list_clean_free(struct _pointer_list *pointer_list, void(*free_function)(void *elt))
Definition: orcania.c:699
pointer_list_size
size_t pointer_list_size(struct _pointer_list *pointer_list)
Definition: orcania.c:713
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:785
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:843
pointer_list_insert_at
int pointer_list_insert_at(struct _pointer_list *pointer_list, void *element, size_t index)
Definition: orcania.c:799
pointer_list_init
void pointer_list_init(struct _pointer_list *pointer_list)
Definition: orcania.c:674
pointer_list_clean
void pointer_list_clean(struct _pointer_list *pointer_list)
Definition: orcania.c:685
string_array_has_value
int string_array_has_value(const char **array, const char *needle)
Definition: orcania.c:576
string_array_has_value_case
int string_array_has_value_case(const char **array, const char *needle)
Definition: orcania.c:593
string_array_size
size_t string_array_size(char **array)
Definition: orcania.c:496
string_array_join
char * string_array_join(const char **array, const char *separator)
Definition: orcania.c:507
split_string
size_t split_string(const char *string, const char *separator, char ***return_array)
Definition: orcania.c:445
free_string_array
void free_string_array(char **array)
Definition: orcania.c:482
string_array_has_value_n
int string_array_has_value_n(const char **array, const char *needle, size_t len)
Definition: orcania.c:610
string_array_has_value_ncase
int string_array_has_value_ncase(const char **array, const char *needle, size_t len)
Definition: orcania.c:627
string_array_has_trimmed_value
int string_array_has_trimmed_value(const char **array, const char *needle)
Definition: orcania.c:644
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:552
o_strcasecmp
int o_strcasecmp(const char *p1, const char *p2)
Definition: orcania.c:262
trimwhitespace
const char * trimwhitespace(char *str)
Definition: orcania.c:528
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_strnullempty
int o_strnullempty(const char *s)
Definition: orcania.c:433
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
_o_datum
Definition: orcania.h:41
_o_datum::data
unsigned char * data
Definition: orcania.h:43
_o_datum::size
size_t size
Definition: orcania.h:42
_pointer_list
Definition: orcania.h:360
_pointer_list::size
size_t size
Definition: orcania.h:361
_pointer_list::list
void ** list
Definition: orcania.h:362