summaryrefslogtreecommitdiff
path: root/user/include/string.h
blob: 4d32f57713320a58ccc12f883a307986e29be59b (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
/**
 * @file string.h
 *
 * @author Freya Murphy <freya@freyacat.org>
 *
 * String libaray functions
 */

#ifndef _STRING_H
#define _STRING_H

#include <stddef.h>

/**
 * Compare the first n bytes (interpreted as unsigned char) of the memory areas s1 and s2
 * @param s1 - the first memory area
 * @param s2 - the second memory area
 * @param n - the byte count
 * @returns an interger less than, equal to, or greater than 0 if the first n bytes
 * of s1 are less than, equal to, or greater than s2.
 */
extern int memcmp(const void *restrict s1, const void *restrict s2, size_t n);

/**
 * Copy the first n bytes from memory area src to memory area dest. The memory
 * areas must not overlap.
 * @param dest - the destination
 * @param src - the source
 * @param n - the byte count
 * @returns a pointer to dest
 */
extern void *memcpy(void *restrict dest, const void *restrict src, size_t n);

/**
 * Copy the first n bytes from memory area src to memory area dest. The memory
 * areas may overlap; memmove behaves as though the bytes are first copied to a
 * temporary array.
 * @param dest - the destination
 * @param src - the source
 * @param n - the byte count
 * @returns a pointer to dest
 */
extern void *memmove(void *restrict dest, const void *restrict src, size_t n);

/**
 * Fill the first n bytes of the memory region dest with the constant byte c.
 * @param dest - the destination
 * @param c - the byte to write
 * @param n - the byte count
 * @returns a pointer to dest
 */
extern void *memset(void *restrict dest, int c, size_t 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
 */
extern size_t strlen(const char *str);

/**
 * Compare null terminated string s1 and s2. The comparison is done using
 * unsigned characters.
 * @param s1 - a pointer to the first string
 * @param s2 - a pointer to the second string
 * @returns an interger less than, equal to, or greater than 0 if s1 compares less
 * than, equal to, or greater than s2
 */
extern int strcmp(const char *restrict s1, const char *restrict s2, size_t n);

/**
 * Compare at most the first n bytes of the strings s1 and s2. The comparison is
 * done using unsigned characters.
 * @param s1 - a pointer to the first string
 * @param s2 - a pointer to the second string
 * @param n - the maximum number of bytes
 * @returns an interger less than, equal to, or greater than 0 if s1 compares less
 * than, equal to, or greater than s2
 */
extern int strncmp(const char *restrict s1, const char *restrict s2, size_t n);

/**
 * Copies the string pointed to by src into the buffer pointer to by dest.
 * The dest buffer must be long enough to hold src.
 * @param dest - the destination
 * @param src - the source
 * @returns a pointer to dest
 */
extern char *strcpy(char *restrict dest, const char *restrict src);

/**
 * Copies the string pointed to by src into the buffer pointer to by dest.
 * The dest buffer must be long enough to hold src or size n.
 * @param dest - the destination
 * @param src - the source
 * @param n - the maximum number of bytes
 * @returns a pointer to dest
 */
extern char *strncpy(char *restrict dest, const char *restrict src, size_t n);

/**
 * Copies the string pointed to by src into the buffer pointed to by dest.
 * The dest buffer must be long enough to hold src.
 * @param dest - the destination
 * @param src - the source
 * @param n - the maximum number of bytes
 * @returns a pointer to the terminating null byte
 */
extern char *stpcpy(char *restrict dest, const char *restrict src);

/**
 * Copies the string pointed to by src into the buffer pointed to by dest.
 * The dest buffer must be long enough to hold src or size n.
 * @param dest - the destination
 * @param src - the source
 * @param n - the maximum number of bytes
 * @returns a pointer to the byte after the last character copied
 */
extern char *stpncpy(char *restrict dest, const char *restrict src, size_t n);

#endif /* string.h */