libcake 0.0.1
Librairie en C
def.h
Aller à la documentation de ce fichier.
1
7#ifndef __CAKE_DEF_H__
8#define __CAKE_DEF_H__
9
11#include <string.h>
13
14/*
15 Certains typedef qui commencent par _ sont des wrappers des structures / fonctions
16 des différents OS, par exemple, cake_char sous Windows correspond à wchar_t tandis que sous
17 Linux à char.
18 Ça permet d'avoir un code beaucoup plus portable.
19
20 cake_bool est un typedef de char peu importe l'OS, ça permet d'avoir une cohésion
21 lors d'appels de fonctions de la pi.
22*/
23
24#if defined(__x86_64)
25#define CAKE_X86_64 1
26#endif
27
28#ifdef __cplusplus
29#define CAKE_C extern "c"
30#else
31#define CAKE_C
32#endif
33
34
35
36#define CAKE_CONCAT(a,b) a##b
37
38#if defined(_WIN32)
39#define CAKE_WINDOWS 1
40
41#ifdef LIBCAKE_EXPORTS
42#define CAKE_API __declspec(dllexport)
43#else
44#define CAKE_API __declspec(dllimport)
45#endif
46
48#include <stddef.h>
49#include <WinSock2.h>
50#include <windows.h>
52
53#define cake_sleep(__millis) Sleep(__millis)
54
55// Sous Windows un cake_char est équivalent à un wchar_t.
56typedef wchar_t cake_char;
57
58typedef DWORD cake_exit_code;
59typedef DWORD cake_size;
60
61typedef HANDLE cake_fd;
62typedef DWORD cake_mask;
63
64/*
65 Permet d'ajouter le L automatiquement devant la chaîne de caractères, ne le fait pas sous Linux,
66 permet un code plus portable.
67*/
68#define CAKE_CHAR(value) CAKE_CONCAT(L, value)
69#define CAKE_CHAR_LENGTH(s) wcslen(s)
70#define CAKE_CHAR_CMP(s1, s2) wcscmp(s1,s2)
71
72#define FILE_SEPARATOR L'\\'
73#define FILE_SEPARATOR_REVERSE L'/'
74#define FILE_SEPARATOR_STR L"\\"
75#define FILE_SEPARATOR_REVERSE_STR L"/"
76
77#define FILE_SEPARATOR_CHAR '\\'
78#define FILE_SEPARATOR_REVERSE_CHAR '/'
79#define FILE_SEPARATOR_CHAR_STR "\\"
80#define FILE_SEPARATOR_REVERSE_CHAR_STR "/"
81
82#define STR_NULL_END L'\0'
83#define ASTERISK L'*'
84
85#define char_length(s) wcslen(s)
86#define char_cmp(s1, s2) wcscmp(s1, s2)
87
88#elif defined(unix) || defined(__unix__) || defined(__unix)
89#define CAKE_UNIX 1
90#include <sys/types.h>
91
92// Sous Unix un cake_char est équivalent à un char.
93typedef char cake_char;
94
95typedef int cake_exit_code;
96
97typedef ssize_t cake_size;
98
99/*
100 Permet d'ajouter le L automatiquement devant la chaîne de caractères, ne le fait pas sous Linux,
101 permet un code plus portable.
102*/
103#define CAKE_CHAR(value) value
104
105#define FILE_SEPARATOR '/'
106#define FILE_SEPARATOR_REVERSE '\\'
107#define FILE_SEPARATOR_STR "/"
108#define FILE_SEPARATOR_REVERSE_STR "\\"
109
110#define FILE_SEPARATOR_CHAR '/'
111#define FILE_SEPARATOR_REVERSE_CHAR '\\'
112#define FILE_SEPARATOR_CHAR_STR "/"
113#define FILE_SEPARATOR_REVERSE_CHAR_STR "\\"
114
115#define STR_NULL_END '\0'
116#define ASTERISK '*'
117
118#define CAKE_CHAR_LENGTH(s) strlen(s)
119#define CAKE_CHAR_CMP(s1, s2) strcmp(s1, s2)
120
121#endif
122
123
124/* ===== Types ===== */
125
126typedef char cake_bool;
127typedef unsigned char uchar;
128typedef unsigned short ushort;
129typedef unsigned int uint;
130typedef unsigned long ulong;
131typedef unsigned long long ulonglong;
132
133typedef long long longlong;
134
135typedef uchar cake_byte; //< Type sur 8 bits.
136typedef uchar cake_undefined_type;
137
138typedef const char *cchar_ptr;
139typedef const short *cshort_ptr;
140typedef const int *cint_ptr;
141typedef const long *clong_ptr;
142typedef const long long *clonglong_ptr;
143
144typedef const unsigned char *cuchar_ptr;
145typedef const unsigned short *cushort_ptr;
146typedef const unsigned int *cuint_ptr;
147typedef const unsigned long *culong_ptr;
148typedef const unsigned long long *culonglong_ptr;
149
150
151/* ===== Defines ===== */
152
153#define cake_true 1
154#define cake_false 0
155
156#define CAKE_BUFF_SIZE 2048
157#define CAKE_PTR(value) &value
158
159#define CAKE_ERROR -1
160#define CAKE_NO_ERROR 0
161
162
163/* ===== Structures ===== */
164typedef struct cake_bytesbuffer {
165 cake_byte *buffer;
166 ulonglong size;
168
169typedef struct cake_ulonglongarray {
170 ulonglong *array;
171 ulonglong length;
173
174#endif
char cake_bool
Type sur 8 bits, utilisé principalement comme valeur de retour des fonctions pour indiquer si une err...
Definition: def.h:126
Definition: def.h:164
Definition: def.h:169