aboutsummaryrefslogtreecommitdiffstats
path: root/library.hpp
blob: 31bb766b14e21c76728a46d67f34c2a0ecd19fa3 (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
/**
 * @file library.hpp
 * Provides some std library functions so we don't have to include them all.
 */

#ifndef LIBRARY_HPP_
#define LIBRARY_HPP_

/**
 * Copies 'n' bytes of a string to a given location.
 * This function will stop copying once either 'cnt' bytes have been
 * copied, or if 'src' hits a '\0'.
 * @param dst the destination to copy to
 * @param src the source of the data
 * @param cnt the maximum # of chars to copy
 */
void strncpy(char *dst, const char *src, int cnt);

/**
 * Copies from one location to another.
 * The copy will stop once one of the strings hit a '\0'.
 * @param dst the destination to copy to
 * @param src the source of the data
 * @return total number of bytes copied
 */
int strcpy(char *dst, const char *src);

/**
 * Copies 'n' bytes of data to a given location.
 * Basically strncpy, but no types for 'dst' and 'src'.
 * @param dst the destination to copy to
 * @param src the source of the data
 * @param cnt the maximum # of chars to copy
 * @see strncpy
 */
inline void memncpy(void *dst, const void *src, int cnt)
{ strncpy(reinterpret_cast<char *>(dst), reinterpret_cast<const char *>(src), cnt); }

/**
 * Converts an integer to a string.
 * Sign is not handled, and base can go up to 16.
 * THERE'S NO ERROR HANDLING!
 * @param n number to convert
 * @param base the base to convert with (default decimal)
 * @return the string
 */
char *itoa(int n, int base = 10);

#endif // LIBRARY_HPP_