Rev 3343 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3343 | Rev 3492 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | * @brief String manipulation functions. |
37 | * @brief String manipulation functions. |
| 38 | */ |
38 | */ |
| 39 | 39 | ||
| 40 | /** Return number of characters in a string. |
40 | /** Return number of characters in a string. |
| 41 | * |
41 | * |
| 42 | * @param str NULL terminated string. |
42 | * @param str NULL terminated string. |
| 43 | * |
43 | * |
| 44 | * @return Number of characters in str. |
44 | * @return Number of characters in str. |
| 45 | */ |
45 | */ |
| 46 | size_t strlen(const char *str) |
46 | size_t strlen(const char *str) |
| 47 | { |
47 | { |
| 48 | int i; |
48 | int i; |
| 49 | 49 | ||
| Line 51... | Line 51... | ||
| 51 | ; |
51 | ; |
| 52 | 52 | ||
| 53 | return i; |
53 | return i; |
| 54 | } |
54 | } |
| 55 | 55 | ||
| 56 | /** Compare two NULL terminated strings |
56 | /** Compare two NULL terminated strings. |
| 57 | * |
57 | * |
| 58 | * Do a char-by-char comparison of two NULL terminated strings. |
58 | * Do a char-by-char comparison of two NULL terminated strings. |
| 59 | * The strings are considered equal iff they consist of the same |
59 | * The strings are considered equal iff they consist of the same |
| 60 | * characters on the minimum of their lengths. |
60 | * characters on the minimum of their lengths. |
| 61 | * |
61 | * |
| 62 | * @param src First string to compare. |
62 | * @param src First string to compare. |
| 63 | * @param dst Second string to compare. |
63 | * @param dst Second string to compare. |
| 64 | * |
64 | * |
| 65 | * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
65 | * @return 0 if the strings are equal, -1 if first is smaller, |
| - | 66 | * 1 if second smaller. |
|
| 66 | * |
67 | * |
| 67 | */ |
68 | */ |
| 68 | int strcmp(const char *src, const char *dst) |
69 | int strcmp(const char *src, const char *dst) |
| 69 | { |
70 | { |
| 70 | for (; *src && *dst; src++, dst++) { |
71 | for (; *src && *dst; src++, dst++) { |
| Line 79... | Line 80... | ||
| 79 | return -1; |
80 | return -1; |
| 80 | return 1; |
81 | return 1; |
| 81 | } |
82 | } |
| 82 | 83 | ||
| 83 | 84 | ||
| 84 | /** Compare two NULL terminated strings |
85 | /** Compare two NULL terminated strings. |
| 85 | * |
86 | * |
| 86 | * Do a char-by-char comparison of two NULL terminated strings. |
87 | * Do a char-by-char comparison of two NULL terminated strings. |
| 87 | * The strings are considered equal iff they consist of the same |
88 | * The strings are considered equal iff they consist of the same |
| 88 | * characters on the minimum of their lengths and specified maximal |
89 | * characters on the minimum of their lengths and specified maximal |
| 89 | * length. |
90 | * length. |
| 90 | * |
91 | * |
| 91 | * @param src First string to compare. |
92 | * @param src First string to compare. |
| 92 | * @param dst Second string to compare. |
93 | * @param dst Second string to compare. |
| 93 | * @param len Maximal length for comparison. |
94 | * @param len Maximal length for comparison. |
| 94 | * |
95 | * |
| 95 | * @return 0 if the strings are equal, -1 if first is smaller, 1 if second smaller. |
96 | * @return 0 if the strings are equal, -1 if first is smaller, |
| - | 97 | * 1 if second smaller. |
|
| 96 | * |
98 | * |
| 97 | */ |
99 | */ |
| 98 | int strncmp(const char *src, const char *dst, size_t len) |
100 | int strncmp(const char *src, const char *dst, size_t len) |
| 99 | { |
101 | { |
| 100 | int i; |
102 | int i; |
| Line 116... | Line 118... | ||
| 116 | * |
118 | * |
| 117 | * Copy at most 'len' characters from string 'src' to 'dest'. |
119 | * Copy at most 'len' characters from string 'src' to 'dest'. |
| 118 | * If 'src' is shorter than 'len', '\0' is inserted behind the |
120 | * If 'src' is shorter than 'len', '\0' is inserted behind the |
| 119 | * last copied character. |
121 | * last copied character. |
| 120 | * |
122 | * |
| 121 | * @param src Source string. |
123 | * @param src Source string. |
| 122 | * @param dest Destination buffer. |
124 | * @param dest Destination buffer. |
| 123 | * @param len Size of destination buffer. |
125 | * @param len Size of destination buffer. |
| 124 | */ |
126 | */ |
| 125 | void strncpy(char *dest, const char *src, size_t len) |
127 | void strncpy(char *dest, const char *src, size_t len) |
| 126 | { |
128 | { |
| 127 | int i; |
129 | int i; |
| 128 | for (i = 0; i < len; i++) { |
130 | for (i = 0; i < len; i++) { |
| Line 130... | Line 132... | ||
| 130 | return; |
132 | return; |
| 131 | } |
133 | } |
| 132 | dest[i-1] = '\0'; |
134 | dest[i-1] = '\0'; |
| 133 | } |
135 | } |
| 134 | 136 | ||
| 135 | /** Convert ascii representation to unative_t |
137 | /** Convert ascii representation to unative_t. |
| 136 | * |
138 | * |
| 137 | * Supports 0x for hexa & 0 for octal notation. |
139 | * Supports 0x for hexa & 0 for octal notation. |
| 138 | * Does not check for overflows, does not support negative numbers |
140 | * Does not check for overflows, does not support negative numbers |
| 139 | * |
141 | * |
| 140 | * @param text Textual representation of number |
142 | * @param text Textual representation of number. |
| 141 | * @return Converted number or 0 if no valid number ofund |
143 | * @return Converted number or 0 if no valid number found. |
| 142 | */ |
144 | */ |
| 143 | unative_t atoi(const char *text) |
145 | unative_t atoi(const char *text) |
| 144 | { |
146 | { |
| 145 | int base = 10; |
147 | int base = 10; |
| 146 | unative_t result = 0; |
148 | unative_t result = 0; |
| Line 150... | Line 152... | ||
| 150 | text += 2; |
152 | text += 2; |
| 151 | } else if (text[0] == '0') |
153 | } else if (text[0] == '0') |
| 152 | base = 8; |
154 | base = 8; |
| 153 | 155 | ||
| 154 | while (*text) { |
156 | while (*text) { |
| 155 | if (base != 16 && \ |
157 | if (base != 16 && |
| 156 | ((*text >= 'A' && *text <= 'F' ) |
158 | ((*text >= 'A' && *text <= 'F') || |
| 157 | || (*text >='a' && *text <='f'))) |
159 | (*text >='a' && *text <='f'))) |
| 158 | break; |
160 | break; |
| 159 | if (base == 8 && *text >='8') |
161 | if (base == 8 && *text >='8') |
| 160 | break; |
162 | break; |
| 161 | 163 | ||
| 162 | if (*text >= '0' && *text <= '9') { |
164 | if (*text >= '0' && *text <= '9') { |
| Line 174... | Line 176... | ||
| 174 | } |
176 | } |
| 175 | 177 | ||
| 176 | return result; |
178 | return result; |
| 177 | } |
179 | } |
| 178 | 180 | ||
| - | 181 | /** Move piece of memory to another, possibly overlapping, location. |
|
| - | 182 | * |
|
| - | 183 | * @param dst Destination address. |
|
| - | 184 | * @param src Source address. |
|
| - | 185 | * @param len Number of bytes to move. |
|
| - | 186 | * |
|
| - | 187 | * @return Destination address. |
|
| - | 188 | */ |
|
| - | 189 | void *memmove(void *dst, const void *src, size_t len) |
|
| - | 190 | { |
|
| - | 191 | char *d = dst; |
|
| - | 192 | const char *s = src; |
|
| - | 193 | if (s < d) { |
|
| - | 194 | while (len--) |
|
| - | 195 | *(d + len) = *(s + len); |
|
| - | 196 | } else { |
|
| - | 197 | while (len--) |
|
| - | 198 | *d++ = *s++; |
|
| - | 199 | } |
|
| - | 200 | ||
| - | 201 | return dst; |
|
| - | 202 | } |
|
| - | 203 | ||
| 179 | /** @} |
204 | /** @} |
| 180 | */ |
205 | */ |