string.h (4431B)
1/** @file string.h 2 Generic string functions. 3 */ 4#ifndef STRING_INCLUDE 5#define STRING_INCLUDE 6 7#include <types.h> 8 9/** Copies the string pointed to by __src__ (including the terminating 10 `\0' character) to the array pointed to by __dest__. 11 12 The strings may not overlap, and the destination string dest must 13 be large enough to receive the copy. 14 15 @param dest Array to copy into 16 @param src Array to copy from 17 18 @return A pointer to dest 19*/ 20char *strcpy(char *dest, const char *src) OLDCALL PRESERVES_REGS(b, c); 21 22/** Compares strings 23 24 @param s1 First string to compare 25 @param s2 Second string to compare 26 27 Returns: 28 \li > 0 if __s1__ > __s2__ 29 \li 0 if __s1__ == __s2__ 30 \li < 0 if __s1__ < __s2__ 31*/ 32int strcmp(const char *s1, const char *s2) OLDCALL PRESERVES_REGS(b, c); 33 34/** Copies n bytes from memory area src to memory area dest. 35 36 The memory areas may not overlap. 37 38 @param dest Buffer to copy into 39 @param src Buffer to copy from 40 @param len Number of Bytes to copy 41*/ 42void *memcpy(void *dest, const void *src, size_t len); 43 44/** Copies n bytes from memory area src to memory area dest, areas may overlap 45 */ 46void *memmove (void *dest, const void *src, size_t n); 47 48/** Fills the memory region __s__ with __n__ bytes using value __c__ 49 50 @param s Buffer to fill 51 @param c char value to fill with (truncated from int) 52 @param n Number of bytes to fill 53*/ 54void *memset (void *s, int c, size_t n) OLDCALL PRESERVES_REGS(b, c); 55 56/** Reverses the characters in a string 57 58 @param s Pointer to string to reverse. 59 60 For example 'abcdefg' will become 'gfedcba'. 61 62 Banked as the string must be modifiable. 63 64 Returns: Pointer to __s__ 65*/ 66char *reverse(char *s) OLDCALL PRESERVES_REGS(b, c); 67 68/** Concatenate Strings. Appends string __s2__ to the end of string __s1__ 69 70 @param s1 String to append onto 71 @param s2 String to copy from 72 73 For example 'abc' and 'def' will become 'abcdef'. 74 75 String __s1__ must be large enough to store both __s1__ and __s2__. 76 77 Returns: Pointer to __s1__ 78*/ 79char *strcat(char *s1, const char *s2); 80 81/** Calculates the length of a string 82 83 @param s String to calculate length of 84 85 Returns: Length of string not including the terminating `\0' character. 86*/ 87int strlen(const char *s) OLDCALL PRESERVES_REGS(b, c); 88 89/**Concatenate at most __n__ characters from string __s2__ onto the end of __s1__. 90 91 @param s1 String to append onto 92 @param s2 String to copy from 93 @param n Max number of characters to copy from __s2__ 94 95 String __s1__ must be large enough to store both __s1__ and __n__ characters of __s2__ 96 97 Returns: Pointer to __s1__ 98*/ 99char *strncat(char *s1, const char *s2, int n); 100 101/** Compare strings (at most __n__ characters): 102 103 @param s1 First string to compare 104 @param s2 Second string to compare 105 @param n Max number of characters to compare 106 107 Returns zero if the strings are identical, or non-zero 108 if they are not (see below). 109 110 Returns: 111 \li > 0 if __s1__ > __s2__ (at first non-matching byte) 112 \li 0 if __s1__ == __s2__ 113 \li < 0 if __s1__ < __s2__ (at first non-matching byte) 114*/ 115int strncmp(const char *s1, const char *s2, int n); 116 117/** Copy __n__ characters from string __s2__ to __s1__ 118 119 120 @param s1 String to copy into 121 @param s2 String to copy from 122 @param n Max number of characters to copy from __s2__ 123 124 If __s2__ is shorter than __n__, the remaining 125 bytes in __s1__ are filled with \0. 126 127 Warning: If there is no \0 in the first __n__ bytes of __s2__ then __s1__ 128 will not be null terminated. 129 130 Returns: Pointer to __s1__ 131*/ 132char *strncpy(char *s1, const char *s2, int n); 133 134/** Compare up to __count__ bytes in buffers __buf1__ and __buf2__ 135 136 @param buf1 Pointer to First buffer to compare 137 @param buf2 Pointer to Second buffer to compare 138 @param count Max number of bytes to compare 139 140 Returns zero if the buffers are identical, or non-zero 141 if they are not (see below). 142 143 Returns: 144 \li > 0 if __buf1__ > __buf2__ (at first non-matching byte) 145 \li 0 if __buf1__ == __buf2__ 146 \li < 0 if __buf1__ < __buf2__ (at first non-matching byte) 147*/ 148int memcmp(const void *buf1, const void *buf2, size_t count) OLDCALL; 149 150#endif