-
Notifications
You must be signed in to change notification settings - Fork 0
/
glibwrap.h
82 lines (62 loc) · 1.69 KB
/
glibwrap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* glibwrap.h
*
* Created on: 14/07/2015
* Author: thborges
*/
#ifndef GLIBWRAP_H
#define GLIBWRAP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
* Types
*/
#define gpointer void*
typedef unsigned short ushort;
#define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
/*
* Allocation functions
*/
#define g_new(ptype, count) (ptype*)malloc(sizeof(ptype) * (count))
#define g_new0(ptype, count) (ptype*)calloc(count, sizeof(ptype))
/*
#define g_new(ptype, count) \
(ptype*)malloc(sizeof(ptype) * (count)); \
printf("#%s %ld\n", #ptype, sizeof(ptype) * (count))
#define g_new0(ptype, count) \
(ptype*)calloc(sizeof(ptype) * (count)); \
printf("#%s %ld\n", #ptype, sizeof(ptype) * (count))
*/
#define g_renew(ptype, pointer, count) (ptype*)realloc(pointer, sizeof(ptype) * (count))
void g_free(void *pointer);
void *g_memdup(const void *mem, unsigned int byte_size);
/*
* Double Linked List
*/
struct GList {
struct GList *next;
struct GList *priour;
void *data;
};
typedef struct GList GList;
#define g_list_first(lst) (lst)
#define g_list_previous(lst) (lst->priour)
#define g_list_next(lst) (lst->next)
GList *g_list_append(GList *lst, void *data);
GList *g_list_prepend(GList *lst, void *data);
GList *g_list_remove_link(GList *list, GList *link);
GList *g_list_delete_link(GList *list, GList *link);
GList *g_list_find(GList *lst, void *data);
GList *g_list_remove(GList *lst, void *data);
GList *g_list_concat(GList *lst, GList *lst2);
unsigned g_list_length(GList *lst);
void g_list_free(GList *lst);
void g_list_free_full(GList *lst, void (*destroy)(void *data));
#ifdef __cplusplus
}
#endif
#endif