Deleted Added
full compact
p_string.c (161195) p_string.c (163533)
1/******************************************************************************
2 *
3 * Filename: p_string.c
4 *
5 * Instantiation of basic string operations to prevent inclusion of full
6 * string library. These are simple implementations not necessarily optimized
7 * for speed, but rather to show intent.
8 *

--- 6 unchanged lines hidden (view full) ---

15 * No warranty, expressed or implied, is included with this software. It is
16 * provided "AS IS" and no warranty of any kind including statutory or aspects
17 * relating to merchantability or fitness for any purpose is provided. All
18 * intellectual property rights of others is maintained with the respective
19 * owners. This software is not copyrighted and is intended for reference
20 * only.
21 * END_BLOCK
22 *
1/******************************************************************************
2 *
3 * Filename: p_string.c
4 *
5 * Instantiation of basic string operations to prevent inclusion of full
6 * string library. These are simple implementations not necessarily optimized
7 * for speed, but rather to show intent.
8 *

--- 6 unchanged lines hidden (view full) ---

15 * No warranty, expressed or implied, is included with this software. It is
16 * provided "AS IS" and no warranty of any kind including statutory or aspects
17 * relating to merchantability or fitness for any purpose is provided. All
18 * intellectual property rights of others is maintained with the respective
19 * owners. This software is not copyrighted and is intended for reference
20 * only.
21 * END_BLOCK
22 *
23 * $FreeBSD: head/sys/boot/arm/at91/libat91/p_string.c 161195 2006-08-10 18:07:49Z imp $
23 * $FreeBSD: head/sys/boot/arm/at91/libat91/p_string.c 163533 2006-10-20 09:12:05Z imp $
24 *****************************************************************************/
25
26#include "lib.h"
27
28/*
29 * .KB_C_FN_DEFINITION_START
24 *****************************************************************************/
25
26#include "lib.h"
27
28/*
29 * .KB_C_FN_DEFINITION_START
30 * int p_IsWhiteSpace(char)
31 * This global function returns true if the character is not considered
32 * a non-space character.
33 * .KB_C_FN_DEFINITION_END
34 */
35int
36p_IsWhiteSpace(char cValue)
37{
38 return ((cValue == ' ') ||
39 (cValue == '\t') ||
40 (cValue == 0) ||
41 (cValue == '\r') ||
42 (cValue == '\n'));
43}
44
45
46/*
47 * .KB_C_FN_DEFINITION_START
48 * unsigned p_HexCharValue(char)
49 * This global function returns the decimal value of the validated hex char.
50 * .KB_C_FN_DEFINITION_END
51 */
52unsigned
53p_HexCharValue(char cValue)
54{
55 if (cValue < ('9' + 1))
56 return (cValue - '0');
57 if (cValue < ('F' + 1))
58 return (cValue - 'A' + 10);
59 return (cValue - 'a' + 10);
60}
61
62
63/*
64 * .KB_C_FN_DEFINITION_START
65 * void p_memset(char *buffer, char value, int size)
66 * This global function sets memory at the pointer for the specified
67 * number of bytes to value.
68 * .KB_C_FN_DEFINITION_END
69 */
70void
71p_memset(char *buffer, char value, int size)
72{
73 while (size--)
74 *buffer++ = value;
75}
76
30 * void p_memset(char *buffer, char value, int size)
31 * This global function sets memory at the pointer for the specified
32 * number of bytes to value.
33 * .KB_C_FN_DEFINITION_END
34 */
35void
36p_memset(char *buffer, char value, int size)
37{
38 while (size--)
39 *buffer++ = value;
40}
41
77
78/*
79 * .KB_C_FN_DEFINITION_START
42/*
43 * .KB_C_FN_DEFINITION_START
80 * int p_strlen(char *)
81 * This global function returns the number of bytes starting at the pointer
82 * before (not including) the string termination character ('/0').
83 * .KB_C_FN_DEFINITION_END
84 */
85int
86p_strlen(const char *buffer)
87{
88 int len = 0;
89 if (buffer)
90 while (buffer[len])
91 len++;
92 return (len);
93}
94
95
96/*
97 * .KB_C_FN_DEFINITION_START
98 * char *p_strcpy(char *to, char *from)
99 * This global function returns a pointer to the end of the destination string
100 * after the copy operation (after the '/0').
101 * .KB_C_FN_DEFINITION_END
102 */
103char *
104p_strcpy(char *to, const char *from)
105{
106 while (*from)
107 *to++ = *from++;
108 *to++ = '\0';
109 return (to);
110}
111
112
113/*
114 * .KB_C_FN_DEFINITION_START
115 * unsigned p_ASCIIToHex(char *)
116 * This global function set the unsigned value equal to the converted
117 * hex number passed as a string. No error checking is performed; the
118 * string must be valid hex value, point at the start of string, and be
119 * NULL-terminated.
120 * .KB_C_FN_DEFINITION_END
121 */
122unsigned
123p_ASCIIToHex(const char *buf)
124{
125 unsigned lValue = 0;
126
127 if ((*buf == '0') && ((buf[1] == 'x') || (buf[1] == 'X')))
128 buf += 2;
129
130 while (*buf) {
131 lValue <<= 4;
132 lValue += p_HexCharValue(*buf++);
133 }
134 return (lValue);
135}
136
137
138/*
139 * .KB_C_FN_DEFINITION_START
140 * unsigned p_ASCIIToDec(char *)
141 * This global function set the unsigned value equal to the converted
142 * decimal number passed as a string. No error checking is performed; the
143 * string must be valid decimal value, point at the start of string, and be
144 * NULL-terminated.
145 * .KB_C_FN_DEFINITION_END
146 */
147unsigned
148p_ASCIIToDec(const char *buf)
149{
150 unsigned v = 0;
151
152 while (*buf) {
153 v *= 10;
154 v += (*buf++) - '0';
155 }
156 return (v);
157}
158
159
160/*
161 * .KB_C_FN_DEFINITION_START
162 * void p_memcpy(char *, char *, unsigned)
163 * This global function copies data from the first pointer to the second
164 * pointer for the specified number of bytes.
165 * .KB_C_FN_DEFINITION_END
166 */
167void
168p_memcpy(char *to, const char *from, unsigned size)
169{
170 while (size--)
171 *to++ = *from++;
172}
173
174
175/*
176 * .KB_C_FN_DEFINITION_START
177 * int p_memcmp(char *to, char *from, unsigned size)
178 * This global function compares data at to against data at from for
179 * size bytes. Returns 0 if the locations are equal. size must be
180 * greater than 0.
181 * .KB_C_FN_DEFINITION_END
182 */
183int
184p_memcmp(const char *to, const char *from, unsigned size)
185{
186 while ((--size) && (*to++ == *from++))
187 continue;
188
189 return (*to != *from);
190}
44 * int p_memcmp(char *to, char *from, unsigned size)
45 * This global function compares data at to against data at from for
46 * size bytes. Returns 0 if the locations are equal. size must be
47 * greater than 0.
48 * .KB_C_FN_DEFINITION_END
49 */
50int
51p_memcmp(const char *to, const char *from, unsigned size)
52{
53 while ((--size) && (*to++ == *from++))
54 continue;
55
56 return (*to != *from);
57}
191
192
193/*
194 * .KB_C_FN_DEFINITION_START
195 * int p_strcmp(char *to, char *from)
196 * This global function compares string at to against string at from.
197 * Returns 0 if the locations are equal.
198 * .KB_C_FN_DEFINITION_END
199 */
200int
201p_strcmp(const char *to, const char *from)
202{
203
204 while (*to && *from && (*to == *from)) {
205 ++to;
206 ++from;
207 }
208
209 return (!((!*to) && (*to == *from)));
210}