-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.h
More file actions
77 lines (65 loc) · 2.44 KB
/
Copy pathutility.h
File metadata and controls
77 lines (65 loc) · 2.44 KB
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
/**
* @file utility.h
* @author Pietro Firpo (pietro.firpo@pm.me)
* @brief Common tasks such as comparing variables, allocate memory
*/
#ifndef SEEN_UTILITY
#define SEEN_UTILITY
#include "types.h"
/**
* @brief Compare two values
* @param spec Type specifier of the values to be compared. Refer to ::spec_t for supported types.
* @param a Pointer to the first element to be compared
* @param b Pointer to the second element to be compared
* @return Constant for the corresponding comparation result
* @retval GREATER First element is grater than the second
* @retval EQUAL First element is equal to the second
* @retval SMALLER First element is smaller than the second
*/
int chooseCmp(const spec_t spec, const void *a, const void *b);
/**
* @brief Compare two chars
* @details Equivalent to `chooseCmp("%c", a, b)`. Refer to chooseCmp()
*/
int charCmp(const void *a, const void *b);
/**
* @brief Compare two bytes
* @details Equivalent to `charCmp(a, b)`. Refer to charCmp().
*/
int byteCmp(const void *a, const void *b);
/**
* @brief Compare two ints
* @details Equivalent to `chooseCmp("%i", a, b)`. Refer to chooseCmp()
*/
int intCmp(const void *a, const void *b);
/**
* @brief Compare two floats
* @details Equivalent to `chooseCmp("%f", a, b)`. Refer to chooseCmp()
*/
int floatCmp(const void *a, const void *b);
/**
* @brief Compare two doubles
* @details Equivalent to `chooseCmp("%lf", a, b)`. Refer to chooseCmp()
*/
int doubleCmp(const void *a, const void *b);
/**
* @brief Compare two pointers
* @details Equivalent to `chooseCmp("%p", a, b)`. Refer to chooseCmp()
*/
int ptrCmp(const void *a, const void *b);
/**
* @brief Return a pointer to a space in memory of specified size
* @details Calls `malloc(bytes)` for a maximum of 10 times until it returns a not null pointer. If in 10 calls does not manage to obtain a not null pointer makes the program terminate
* @param bytes Number of bytes to allocate
* @return A pointer to the allocated memory
*/
void *saferMalloc(unsigned int bytes);
/**
* @brief Reallocate a space in memory
* @details Calls `realloc(pointer, bytes)` for a maximum of 10 times until it returns a not null pointer. If in 10 calls does not manage to obtain a not null pointer makes the program terminate
* @param pointer Pointer to the memory to be reallocated
* @param bytes Number of bytes to allocate
* @return A pointer to the allocated memory
*/
void *saferRealloc(void *pointer, unsigned int bytes);
#endif