]>
Dogcows Code - chaz/rasterize/blob - common.h
4b0f7e04005a24978edf2579f9f8d99073c83019
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
19 * Define a type for scalar values, either float or double.
22 typedef double scal_t
;
37 * Define a keyword for use while defining small and fast functions.
39 #define __fast__ static inline
43 * Define some macros for packing and unpacking bytes to and from larger ints.
45 #define PACK(W,N,B) (((B) << (8 * (N))) | ((W) & ~(0xff << (8 * (N)))))
46 #define UNPACK(W,N) ((uint8_t)((W) >> (8 * (N))) & 0xff)
49 typedef void (*dtor_t
)(void*);
50 #define DTOR(A) (dtor_t)(A)
54 * Allocate a block of memory of a certain size. This follows the semantics
55 * of malloc(3), except it will never return NULL and will abort(3) if the
56 * memory could not be allocated.
58 void* mem_alloc(size_t size
);
61 * Change the size of a block of memory. This follows the semantics of
62 * realloc(3), except it will never return NULL and will abort(3) if the
63 * memory could not be allocated.
65 void* mem_realloc(void* mem
, size_t size
);
68 * Deallocate a block of memory previously allocated by mem_alloc or malloc(3)
69 * and friends. This is essentially just a call to free(3).
71 void mem_free(void* mem
);
74 * Set a function to call if either mem_alloc or mem_realloc fails, or NULL if
75 * no callback should be called. The callback takes the same arguments as
76 * realloc(3) and may try to fulfill the request. The return value of the
77 * callback function will be returned from the allocation function and must be
78 * a valid pointer to an allocated block of memory. The callback function
79 * should not call mem_alloc or mem_realloc and must not return if a block of
80 * memory could not be allocated.
82 void mem_set_fn(void* (*fn
)(void*, size_t));
85 * Get the number of blocks currently allocated with either mem_alloc or
86 * mem_realloc. This number should be zero at the end of a process running
93 * Trim white space off of the right side of a string.
95 void rtrim(char *str
);
98 * Trim white space off of the left side of a string.
100 void ltrim(char *str
);
103 * Trim white space off of both sides of a string.
113 #endif // __COMMON_H__
This page took 0.031667 seconds and 4 git commands to generate.