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

Loading...
Searching...
No Matches
orcania.h
Go to the documentation of this file.
1
27
28#ifndef __ORCANIA_H__
29#define __ORCANIA_H__
30
31#ifdef __cplusplus
32 extern "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
54
66 char * str_replace(const char * source, const char * str_old, const char * str_new);
67
75 char * o_strdup(const char * source);
76
85 char * o_strndup(const char * source, size_t len);
86
94 int o_strcmp(const char * p1, const char * p2);
95
104 int o_strncmp(const char * p1, const char * p2, size_t n);
105
113 char * o_strcpy(char * p1, const char * p2);
114
123 char * o_strncpy(char * p1, const char * p2, size_t n);
124
132 int o_strcasecmp(const char * p1, const char * p2);
133
142 int o_strncasecmp(const char * p1, const char * p2, size_t n);
143
151 char * o_strstr(const char * haystack, const char * needle);
152
161 char * o_strnstr(const char * haystack, const char * needle, size_t len);
162
170 char * o_strcasestr(const char * haystack, const char * needle);
171
179 char * o_strchr(const char * haystack, int c);
180
189 const char * o_strnchr(const char * haystack, size_t len, char c);
190
198 char * o_strrchr(const char * haystack, int c);
199
208 const char * o_strrnchr(const char * haystack, size_t len, char c);
209
214 int o_strnullempty(const char * s);
215
222 size_t o_strlen(const char * s);
223
230 const char * trimwhitespace(char * str);
231
239 char * trimcharacter(char * str, char to_remove);
240
253 char * msprintf(const char * message, ...);
254
265 char * mstrcatf(char * source, const char * message, ...);
266
270
275
289 size_t split_string(const char * string, const char * separator, char *** return_array);
290
296 void free_string_array(char ** array);
297
303 size_t string_array_size(char ** array);
304
311 int string_array_has_value(const char ** array, const char * needle);
312
319 int string_array_has_value_case(const char ** array, const char * needle);
320
328 int string_array_has_value_n(const char ** array, const char * needle, size_t len);
329
337 int string_array_has_value_ncase(const char ** array, const char * needle, size_t len);
338
345 int string_array_has_trimmed_value(const char ** array, const char * needle);
346
353 char * string_array_join(const char ** array, const char * separator);
354
358
363 struct _pointer_list {
364 size_t size; /* size of the list */
365 void ** list; /* list of pointers */
366};
367
373 void pointer_list_init(struct _pointer_list * pointer_list);
374
380 void pointer_list_clean(struct _pointer_list * pointer_list);
381
389 void pointer_list_clean_free(struct _pointer_list * pointer_list, void (* free_function)(void * elt));
390
396 size_t pointer_list_size(struct _pointer_list * pointer_list);
397
405 int pointer_list_append(struct _pointer_list * pointer_list, void * element);
406
413 void * pointer_list_get_at(struct _pointer_list * pointer_list, size_t index);
414
422 int pointer_list_remove_at(struct _pointer_list * pointer_list, size_t index);
423
433 int pointer_list_remove_at_free(struct _pointer_list * pointer_list, size_t index, void (* free_function)(void * elt));
434
443 int pointer_list_insert_at(struct _pointer_list * pointer_list, void * element, size_t index);
444
452 int pointer_list_remove_pointer(struct _pointer_list * pointer_list, void * element);
453
463 int pointer_list_remove_pointer_free(struct _pointer_list * pointer_list, void * element, void (* free_function)(void * elt));
464
468
473
474/* C89 allows these to be macros */
475#undef malloc
476#undef realloc
477#undef free
478
482 typedef void *(*o_malloc_t)(size_t);
483 typedef void *(*o_realloc_t)(void *, size_t);
484 typedef void (*o_free_t)(void *);
485
491 void * o_malloc(size_t size);
492
499 void * o_realloc(void * ptr, size_t size);
500
504 void o_free(void * ptr);
505
512 void o_set_alloc_funcs(o_malloc_t malloc_fn, o_realloc_t realloc_fn, o_free_t free_fn);
513
520 void o_get_alloc_funcs(o_malloc_t * malloc_fn, o_realloc_t * realloc_fn, o_free_t * free_fn);
521
525
530
541 int o_base64_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
542
553 int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
554
565 int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * out, size_t * out_len);
566
577 int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
578
590 int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
591
603 int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len);
604
615 int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
616
627 int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
628
639 int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
640
651 int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
652
663 int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
664
675 int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat);
676
680
681#ifdef __cplusplus
682}
683#endif
684
685#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:181
o_base64url_decode
int o_base64url_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition base64.c:185
o_base64_encode
int o_base64_encode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition base64.c:173
o_base64_encode_alloc
int o_base64_encode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition base64.c:239
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:307
o_base64_decode
int o_base64_decode(const unsigned char *src, size_t len, unsigned char *out, size_t *out_len)
Definition base64.c:177
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:189
o_base64url_encode_alloc
int o_base64url_encode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition base64.c:273
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:216
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:325
o_base64url_decode_alloc
int o_base64url_decode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition base64.c:290
o_base64_decode_alloc
int o_base64_decode_alloc(const unsigned char *src, size_t len, struct _o_datum *dat)
Definition base64.c:256
o_malloc_t
void *(* o_malloc_t)(size_t)
Definition orcania.h:482
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:483
o_free_t
void(* o_free_t)(void *)
Definition orcania.h:484
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:605
pointer_list_remove_pointer
int pointer_list_remove_pointer(struct _pointer_list *pointer_list, void *element)
Definition orcania.c:652
pointer_list_get_at
void * pointer_list_get_at(struct _pointer_list *pointer_list, size_t index)
Definition orcania.c:597
pointer_list_append
int pointer_list_append(struct _pointer_list *pointer_list, void *element)
Definition orcania.c:580
pointer_list_clean_free
void pointer_list_clean_free(struct _pointer_list *pointer_list, void(*free_function)(void *elt))
Definition orcania.c:562
pointer_list_size
size_t pointer_list_size(struct _pointer_list *pointer_list)
Definition orcania.c:572
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:624
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:666
pointer_list_insert_at
int pointer_list_insert_at(struct _pointer_list *pointer_list, void *element, size_t index)
Definition orcania.c:633
pointer_list_init
void pointer_list_init(struct _pointer_list *pointer_list)
Definition orcania.c:546
pointer_list_clean
void pointer_list_clean(struct _pointer_list *pointer_list)
Definition orcania.c:553
string_array_has_value
int string_array_has_value(const char **array, const char *needle)
Definition orcania.c:464
string_array_has_value_case
int string_array_has_value_case(const char **array, const char *needle)
Definition orcania.c:478
string_array_size
size_t string_array_size(char **array)
Definition orcania.c:396
string_array_join
char * string_array_join(const char **array, const char *separator)
Definition orcania.c:404
split_string
size_t split_string(const char *string, const char *separator, char ***return_array)
Definition orcania.c:351
free_string_array
void free_string_array(char **array)
Definition orcania.c:385
string_array_has_value_n
int string_array_has_value_n(const char **array, const char *needle, size_t len)
Definition orcania.c:492
string_array_has_value_ncase
int string_array_has_value_ncase(const char **array, const char *needle, size_t len)
Definition orcania.c:506
string_array_has_trimmed_value
int string_array_has_trimmed_value(const char **array, const char *needle)
Definition orcania.c:520
o_strncpy
char * o_strncpy(char *p1, const char *p2, size_t n)
Definition orcania.c:204
o_strrchr
char * o_strrchr(const char *haystack, int c)
Definition orcania.c:268
o_strndup
char * o_strndup(const char *source, size_t len)
Definition orcania.c:155
o_strcmp
int o_strcmp(const char *p1, const char *p2)
Definition orcania.c:172
o_strcasestr
char * o_strcasestr(const char *haystack, const char *needle)
Definition orcania.c:331
msprintf
char * msprintf(const char *message,...)
Definition orcania.c:99
o_strcpy
char * o_strcpy(char *p1, const char *p2)
Definition orcania.c:196
o_strstr
char * o_strstr(const char *haystack, const char *needle)
Definition orcania.c:236
o_strlen
size_t o_strlen(const char *s)
Definition orcania.c:339
o_strrnchr
const char * o_strrnchr(const char *haystack, size_t len, char c)
Definition orcania.c:276
mstrcatf
char * mstrcatf(char *source, const char *message,...)
Definition orcania.c:120
trimcharacter
char * trimcharacter(char *str, char to_remove)
Definition orcania.c:443
o_strcasecmp
int o_strcasecmp(const char *p1, const char *p2)
Definition orcania.c:212
trimwhitespace
const char * trimwhitespace(char *str)
Definition orcania.c:422
o_strdup
char * o_strdup(const char *source)
Definition orcania.c:151
o_strchr
char * o_strchr(const char *haystack, int c)
Definition orcania.c:244
o_strnullempty
int o_strnullempty(const char *s)
Definition orcania.c:347
o_strncasecmp
int o_strncasecmp(const char *p1, const char *p2, size_t n)
Definition orcania.c:224
str_replace
char * str_replace(const char *source, const char *str_old, const char *str_new)
Definition orcania.c:55
o_strnchr
const char * o_strnchr(const char *haystack, size_t len, char c)
Definition orcania.c:252
o_strncmp
int o_strncmp(const char *p1, const char *p2, size_t n)
Definition orcania.c:184
o_strnstr
char * o_strnstr(const char *haystack, const char *needle, size_t len)
Definition orcania.c:323
_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:363
_pointer_list::size
size_t size
Definition orcania.h:364
_pointer_list::list
void ** list
Definition orcania.h:365