summaryrefslogtreecommitdiff
path: root/include/lib.h
blob: 7c74fa2a6db112b5c0856ac6e1e7027f9be15358 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#pragma once

#include <stdarg.h>
#include <stddef.h>

/**
 * The  memcmp() function compares the first n bytes (each interpreted as unsigned char) of the memory
 * areas s1 and s2.
 */
int memcmp(const void *restrict s1, const void *restrict s2, unsigned long n);

/**
 * the  memcpy()  function  copies n bytes from memory area src to memory area dest.
 * the memory areas must not overlap.
 */
void *memcpy(void *restrict dest, const void *restrict src, unsigned long n);

/**
 * the  memcpy()  function  copies n bytes from memory area src to memory area dest.
 * the memory areas must not overlap.
 */
volatile void *memcpyv(volatile void *dest, const volatile void *src, unsigned long n);

/**
 * The  memmove()  function copies n bytes from memory area src to memory area dest.  The memory areas
 * may overlap: copying takes place as though the bytes in src are first copied into a temporary array
 * that does not overlap src or dest, and the bytes are then copied from the temporary array to dest.
 */
void *memmove(void *dest, const void *src, unsigned long n);

/**
 * The  memset() function fills the first n bytes of the memory area pointed to by s with the constant
 * byte c.
 */
void *memset(void *restrict dest, int c, unsigned long n);

/**
 * The  memset() function fills the first n bytes of the memory area pointed to by s with the constant
 * byte c.
 */
volatile void *memsetv(volatile void *dest, int c, unsigned long n);

/**
 * The  strcmp()  function  compares  the two strings s1 and s2.  The locale is not taken into account
 * (for a locale-aware comparison, see strcoll(3)).  The comparison is done using unsigned characters.
 */
int strncmp(const char *restrict s1, const char *restrict s2, unsigned long n);

/**
 * Copys the string pointed to by src , into a string at the buffer pointer to by dest.
 * The dest buffer must be long enough to hold src.
 */
char *strcpy(char *restrict dest, const char *restrict src);

/**
 * Copys the string pointed to by src , into a string at the buffer pointer to by dest.
 * The dest buffer must be long enough to hold src or size n.
 */
char *strncpy(char *restrict dest, const char *restrict src, unsigned long n);

/**
 * Calculates the length of the string pointed to by str, excluding
 * the terminating null byte
 * @param str - the string pointer
 * @returns the length of the string in bytes
 */
size_t strlen(const char *str);

/**
 * Concatenate the string pointed to by src after the string pointed
 * to by dst.
 * @param dst - the pointer to the destination string
 * @param src - the pointer to the source string
 * @returns dst
 */
char *strcat(char *restrict dst, const char *restrict src);

/**
 * @returns 1 if c is a space
 */
int isspace(int c);

/**
 * @returns 1 if c is a digit (0 - 9)
 */
int isdigit(int c);

/**
 * converts single digit int to base 36
 * @param i - int
 * @returns c - base 36 char
 */
char itoc(int i);

/**
 * converts single base 36 chat into int
 * @param c - base 36 char
 * @returns i - int
 */
int ctoi(char c);

/**
 * Converts the initial portiion of the string pointed to by s to int.
 * @param s - the string to convert
 * @returns the number inside s or 0 on error
 */
int atoi(const char *s);

/**
 * Converts the initial portiion of the string pointed to by s to long.
 * @param s - the string to convert
 * @returns the number inside s or 0 on error
 */
long int atol(const char *s);

/**
 * Converts the initial portiion of the string pointed to by s to long long.
 * @param s - the string to convert
 * @returns the number inside s or 0 on error
 */
long long int atoll(const char *s);

/**
 * Converts a integer to asci inside a string with a given radix (base).
 * @param n - the number to convert
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *itoa(int n, char *buffer, int radix);

/**
 * Converts a long to asci inside a string with a given radix (base).
 * @param n - the number to convert
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *ltoa(long int n, char *buffer, int radix);

/**
 * Converts a long long to asci inside a string with a given radix (base).
 * @param n - the number to conver
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *lltoa(long long int n, char *buffer, int radix);

/**
 * Converts a unsigned integer to asci inside a string with a given radix (base).
 * @param n - the number to convert
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *utoa(unsigned int n, char *buffer, int radix);

/**
 * Converts a unsigned long to asci inside a string with a given radix (base).
 * @param n - the number to convert
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *ultoa(unsigned long int n, char *buffer, int radix);

/**
 * Converts a unsigned long long to asci inside a string with a given radix (base).
 * @param n - the number to conver
 * @param buffer - the string buffer
 * @param radix - the base to convert
 */
char *ulltoa(unsigned long long int n, char *buffer, int radix);

/**
 * Converts a byte count to a human readable file size
 * @param bytes - the bytes to convert
 * @param buf - the buffer to store it in
 * @preturns - bus
 */
char *btoa(size_t bytes, char *buf);

/**
 * Converts the string in str to an int value based on the given base.
 * The endptr is updated to where the string was no longer valid.
 * @param str - the string buffer
 * @param endptr - the endptr
 * @param base - the base to convert to
 * @returns 0 on error or success, error if endptr is still equal to str
 */
int strtoi(const char *str, char **endptr, int base);

/**
 * Converts the string in str to an long value based on the given base.
 * The endptr is updated to where the string was no longer valid.
 * @param str - the string buffer
 * @param endptr - the endptr
 * @param base - the base to convert to
 * @returns 0 on error or success, error if endptr is still equal to str
 */
long int strtol(const char *str, char **endptr, int base);

/**
 * Converts the string in str to an long long value based on the given base.
 * The endptr is updated to where the string was no longer valid.
 * @param str - the string buffer
 * @param endptr - the endptr
 * @param base - the base to convert to
 * @returns 0 on error or success, error if endptr is still equal to str
 */
long long int strtoll(const char *str, char **endptr, int base);

/**
 * Prints out a char
 * @param c - the char
 */
void kputc(char c);

/**
 * Prints out a null terminated string
 * @param s - the string
 */
void kputs(const char *s);

/**
 * Prints out a formatted string
 * @param format - the format string
 * @param ... - variable args for the format
 */
void kvprintf(const char *format, va_list args);

/**
 * Prints out a formatted string
 * @param format - the format string
 * @param ... - variable args for the format
 */
__attribute__((format(printf, 1, 2)))
void kprintf(const char *format, ...);