1*418b791dSBob Badour /**
2*418b791dSBob Badour * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3*418b791dSBob Badour *
4*418b791dSBob Badour * Redistribution and use in source and binary forms, with or without
5*418b791dSBob Badour * modification, are permitted provided that the following conditions are
6*418b791dSBob Badour * met:
7*418b791dSBob Badour * * Redistributions of source code must retain the above copyright
8*418b791dSBob Badour * notice, this list of conditions and the following disclaimer.
9*418b791dSBob Badour * * Redistributions in binary form must reproduce the above
10*418b791dSBob Badour * copyright notice, this list of conditions and the following
11*418b791dSBob Badour * disclaimer in the documentation and/or other materials provided
12*418b791dSBob Badour * with the distribution.
13*418b791dSBob Badour * * Neither the name of The Linux Foundation nor the names of its
14*418b791dSBob Badour * contributors may be used to endorse or promote products derived
15*418b791dSBob Badour * from this software without specific prior written permission.
16*418b791dSBob Badour *
17*418b791dSBob Badour * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18*418b791dSBob Badour * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*418b791dSBob Badour * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20*418b791dSBob Badour * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21*418b791dSBob Badour * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*418b791dSBob Badour * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*418b791dSBob Badour * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24*418b791dSBob Badour * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25*418b791dSBob Badour * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26*418b791dSBob Badour * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*418b791dSBob Badour * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*418b791dSBob Badour */
29*418b791dSBob Badour
30*418b791dSBob Badour #ifndef AEESTD_H
31*418b791dSBob Badour #define AEESTD_H
32*418b791dSBob Badour /*====================================================================
33*418b791dSBob Badour
34*418b791dSBob Badour DESCRIPTION: Standard library; general-purpose utility functions.
35*418b791dSBob Badour
36*418b791dSBob Badour ====================================================================*/
37*418b791dSBob Badour #include "AEEVaList.h"
38*418b791dSBob Badour #include "AEEStdDef.h"
39*418b791dSBob Badour #include "string.h"
40*418b791dSBob Badour
41*418b791dSBob Badour #define STD_CONSTRAIN( val, min, max ) (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val))
42*418b791dSBob Badour #define STD_BETWEEN( val, minGE, maxLT ) \
43*418b791dSBob Badour ( (unsigned long)((unsigned long)(val) - (unsigned long)(minGE)) < \
44*418b791dSBob Badour (unsigned long)((unsigned long)(maxLT) - (unsigned long)(minGE)) )
45*418b791dSBob Badour #define STD_ARRAY_SIZE(a) ((int)((sizeof((a))/sizeof((a)[0]))))
46*418b791dSBob Badour #define STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a))))
47*418b791dSBob Badour
48*418b791dSBob Badour #define STD_SIZEOF(x) ((int)sizeof(x))
49*418b791dSBob Badour #define STD_OFFSETOF(type,member) (((char*)(&((type*)1)->member))-((char*)1))
50*418b791dSBob Badour
51*418b791dSBob Badour #define STD_RECOVER_REC(type,member,p) ((void)((p)-&(((type*)1)->member)),\
52*418b791dSBob Badour (type*)(void*)(((char*)(void*)(p))-STD_OFFSETOF(type,member)))
53*418b791dSBob Badour #define STD_MIN(a,b) ((a)<(b)?(a):(b))
54*418b791dSBob Badour #define STD_MAX(a,b) ((a)>(b)?(a):(b))
55*418b791dSBob Badour //lint -emacro(545,STD_ZEROAT)
56*418b791dSBob Badour #define STD_ZEROAT(p) std_memset((p), 0, sizeof(*p))
57*418b791dSBob Badour
58*418b791dSBob Badour #define _STD_BITS_PER(bits) (8*sizeof((bits)[0]))
59*418b791dSBob Badour
60*418b791dSBob Badour #define STD_BIT_SET(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] |= 0x1<<((ix) & (_STD_BITS_PER((bits))-1)))
61*418b791dSBob Badour #define STD_BIT_CLEAR(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] &= ~(0x1<<((ix) & (_STD_BITS_PER((bits))-1))))
62*418b791dSBob Badour #define STD_BIT_TEST(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] & (0x1<<((ix) & (_STD_BITS_PER((bits))-1))))
63*418b791dSBob Badour
64*418b791dSBob Badour //
65*418b791dSBob Badour // Error codes
66*418b791dSBob Badour //
67*418b791dSBob Badour #define STD_NODIGITS 1
68*418b791dSBob Badour #define STD_NEGATIVE 2
69*418b791dSBob Badour #define STD_OVERFLOW 3
70*418b791dSBob Badour #define STD_BADPARAM 4
71*418b791dSBob Badour #define STD_UNDERFLOW 5
72*418b791dSBob Badour
73*418b791dSBob Badour //Compute string length using strlen
74*418b791dSBob Badour #define std_strlen strlen
75*418b791dSBob Badour
76*418b791dSBob Badour #ifdef __cplusplus
77*418b791dSBob Badour extern "C" {
78*418b791dSBob Badour #endif /* #ifdef __cplusplus */
79*418b791dSBob Badour
80*418b791dSBob Badour //Version function
81*418b791dSBob Badour extern int std_getversion(char *pcDst, int nDestSize);
82*418b791dSBob Badour
83*418b791dSBob Badour //String functions
84*418b791dSBob Badour extern int std_strcmp(const char *s1, const char *s2);
85*418b791dSBob Badour extern int std_strncmp(const char *s1, const char *s2, int n);
86*418b791dSBob Badour extern int std_stricmp(const char *s1, const char *s2);
87*418b791dSBob Badour extern int std_strnicmp(const char *s1, const char *s2, int n);
88*418b791dSBob Badour extern int std_strlcpy(char *pcDst, const char *pszSrc, int nDestSize);
89*418b791dSBob Badour extern int std_strlcat(char *pcDst, const char *pszSrc, int nDestSize);
90*418b791dSBob Badour extern char * std_strstr(const char *pszString, const char *pszSearch);
91*418b791dSBob Badour
92*418b791dSBob Badour //Character functions
93*418b791dSBob Badour extern char std_tolower(char c);
94*418b791dSBob Badour extern char std_toupper(char c);
95*418b791dSBob Badour
96*418b791dSBob Badour // Mem functions
97*418b791dSBob Badour extern void * std_memset(void *p, int c, int nLen);
98*418b791dSBob Badour extern void * std_memmove(void *pTo, const void *cpFrom, int nLen);
99*418b791dSBob Badour extern int std_memscpy(void *dst, int dst_size, const void *src, int src_size);
100*418b791dSBob Badour extern int std_memsmove(void *dst, int dst_size, const void *src, int src_size);
101*418b791dSBob Badour extern int std_memcmp(const void *a, const void *b, int length);
102*418b791dSBob Badour extern void * std_memchr(const void* s, int c, int n);
103*418b791dSBob Badour extern void * std_memstr(const char* cpHaystack, const char* cpszNeedle, int nHaystackLen);
104*418b791dSBob Badour extern void * std_memrchr(const void* s, int c, int n);
105*418b791dSBob Badour extern void * std_memrchrbegin(const void* p, int c, int nLen);
106*418b791dSBob Badour extern void * std_memchrend(const void* cpcSrch, int c, int nLen);
107*418b791dSBob Badour extern void * std_memchrsend(const void *cpSrch, const char* cpszChars, int nLen);
108*418b791dSBob Badour
109*418b791dSBob Badour //Other String functions
110*418b791dSBob Badour extern char * std_strchr(const char* s, int c);
111*418b791dSBob Badour extern char * std_strchrs(const char* sSrch, const char *sChars);
112*418b791dSBob Badour extern char * std_strrchr(const char* s, int c);
113*418b791dSBob Badour extern char * std_strchrend(const char *cpszSrch, char c);
114*418b791dSBob Badour extern char * std_strchrsend(const char* s, const char* cpszSrch);
115*418b791dSBob Badour extern char * std_strends(const char* cpsz, const char* cpszSuffix);
116*418b791dSBob Badour extern char * std_striends(const char* cpsz, const char* cpszSuffix);
117*418b791dSBob Badour extern char * std_strbegins(const char* cpsz, const char* cpszPrefix);
118*418b791dSBob Badour extern char * std_stribegins(const char* cpsz, const char* cpszPrefix);
119*418b791dSBob Badour extern int std_strcspn(const char* s, const char* cpszSrch);
120*418b791dSBob Badour extern int std_strspn(const char* s, const char* cpszSrch);
121*418b791dSBob Badour
122*418b791dSBob Badour //Wide char string functions
123*418b791dSBob Badour extern int std_wstrlen(const AECHAR *s);
124*418b791dSBob Badour extern int std_wstrlcpy(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize);
125*418b791dSBob Badour extern int std_wstrlcat(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize);
126*418b791dSBob Badour extern int std_wstrncmp(const AECHAR* s1, const AECHAR* s2, int nLen);
127*418b791dSBob Badour extern int std_wstrcmp(const AECHAR* s1, const AECHAR* s2);
128*418b791dSBob Badour extern AECHAR* std_wstrchr(const AECHAR* cpwszText, AECHAR ch);
129*418b791dSBob Badour extern AECHAR* std_wstrrchr(const AECHAR* cpwszText, AECHAR ch);
130*418b791dSBob Badour
131*418b791dSBob Badour //Path functions
132*418b791dSBob Badour extern int std_makepath(const char *cpszDir,
133*418b791dSBob Badour const char *cpszFile,
134*418b791dSBob Badour char *pszDest, int nDestSize);
135*418b791dSBob Badour extern char * std_splitpath(const char *cpszPath, const char *cpszDir);
136*418b791dSBob Badour extern char * std_cleanpath(char *pszPath);
137*418b791dSBob Badour extern char * std_basename(const char *pszPath);
138*418b791dSBob Badour
139*418b791dSBob Badour //Inet functions, number functions
140*418b791dSBob Badour extern unsigned int std_scanul(const char *pchBuf, int nRadix,
141*418b791dSBob Badour const char **ppchEnd, int *pnError);
142*418b791dSBob Badour extern uint64 std_scanull(const char *pchBuf, int nRadix,
143*418b791dSBob Badour const char **ppchEnd, int *pnError);
144*418b791dSBob Badour extern double std_scand(const char *pchBuf, const char **ppchEnd);
145*418b791dSBob Badour
146*418b791dSBob Badour // Rand functions
147*418b791dSBob Badour extern unsigned std_rand_next(unsigned uRand);
148*418b791dSBob Badour extern uint32 std_rand(uint32 uSeed, byte* pDest, int nSize);
149*418b791dSBob Badour
150*418b791dSBob Badour
151*418b791dSBob Badour // printf functions
152*418b791dSBob Badour extern int std_vstrlprintf(char *pszDest, int nDestSize,
153*418b791dSBob Badour const char *pszFmt, AEEVaList args);
154*418b791dSBob Badour
155*418b791dSBob Badour extern int std_strlprintf(char *pszDest, int nDestSize,
156*418b791dSBob Badour const char *pszFmt, ...);
157*418b791dSBob Badour
158*418b791dSBob Badour extern int std_vsnprintf(char *pszDest, int nDestSize,
159*418b791dSBob Badour const char *cpszFmt, AEEVaList args);
160*418b791dSBob Badour
161*418b791dSBob Badour extern int std_snprintf(char *pszDest, int nDestSize,
162*418b791dSBob Badour const char *pszFmt, ...);
163*418b791dSBob Badour
164*418b791dSBob Badour // endian swapping functions
165*418b791dSBob Badour extern int std_CopyLE(void *pvDest, int nDestSize,
166*418b791dSBob Badour const void *pvSrc, int nSrcSize,
167*418b791dSBob Badour const char *pszFields);
168*418b791dSBob Badour
169*418b791dSBob Badour extern int std_CopyBE(void *pvDest, int nDestSize,
170*418b791dSBob Badour const void *pvSrc, int nSrcSize,
171*418b791dSBob Badour const char *pszFields);
172*418b791dSBob Badour
173*418b791dSBob Badour // sorting utilities
174*418b791dSBob Badour extern void std_qsort(void* pElems, int nNumElems, int nElemWidth,
175*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
176*418b791dSBob Badour void* pCompareCx);
177*418b791dSBob Badour
178*418b791dSBob Badour extern int std_bisect(const void* pElems, int nNumElems, int nElemWidth,
179*418b791dSBob Badour const void* pElem,
180*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
181*418b791dSBob Badour void* pCompareCx);
182*418b791dSBob Badour
183*418b791dSBob Badour extern void std_merge(void* vpDst, int nDst,
184*418b791dSBob Badour const void* vpA, int nA,
185*418b791dSBob Badour const void* vpB, int nB,
186*418b791dSBob Badour int nElemWidth,
187*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
188*418b791dSBob Badour void* pCompareCx);
189*418b791dSBob Badour
190*418b791dSBob Badour extern int std_uniq(void* vpElems, int nNumElems, int nElemWidth,
191*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
192*418b791dSBob Badour void* pCompareCx);
193*418b791dSBob Badour
194*418b791dSBob Badour #ifdef __cplusplus
195*418b791dSBob Badour }
196*418b791dSBob Badour #endif /* #ifdef __cplusplus */
197*418b791dSBob Badour
198*418b791dSBob Badour
199*418b791dSBob Badour #define STD_SWAPS(us) \
200*418b791dSBob Badour ((((us) & 0xff) << 8) + (((us) & 0xff00) >> 8))
201*418b791dSBob Badour
202*418b791dSBob Badour
std_swaps(unsigned short us)203*418b791dSBob Badour static __inline unsigned short std_swaps(unsigned short us)
204*418b791dSBob Badour {
205*418b791dSBob Badour return STD_SWAPS(us);
206*418b791dSBob Badour }
207*418b791dSBob Badour
208*418b791dSBob Badour /* note, STD_SWAPL() requires that ul be an l-value, and destroyable.
209*418b791dSBob Badour this macro is not intended for use outside AEEstd.h */
210*418b791dSBob Badour #define STD_SWAPL(ul) \
211*418b791dSBob Badour (((ul) = (((ul) & 0x00ff00ff) << 8) | (((ul)>>8) & 0x00ff00ff)),(((ul) >> 16) | ((ul) << 16)))
212*418b791dSBob Badour
std_swapl(unsigned long ul)213*418b791dSBob Badour static __inline unsigned long std_swapl(unsigned long ul)
214*418b791dSBob Badour {
215*418b791dSBob Badour return STD_SWAPL(ul);
216*418b791dSBob Badour }
217*418b791dSBob Badour
218*418b791dSBob Badour #ifdef AEE_BIGENDIAN
219*418b791dSBob Badour # define STD_HTONL(u) (u)
220*418b791dSBob Badour # define STD_HTONS(u) (u)
221*418b791dSBob Badour # define STD_HTOLEL(u) (STD_SWAPL(u))
222*418b791dSBob Badour # define STD_HTOLES(u) (STD_SWAPS(u))
223*418b791dSBob Badour #else
224*418b791dSBob Badour # define STD_HTONL(u) (STD_SWAPL(u))
225*418b791dSBob Badour # define STD_HTONS(u) (STD_SWAPS(u))
226*418b791dSBob Badour # define STD_HTOLEL(u) (u)
227*418b791dSBob Badour # define STD_HTOLES(u) (u)
228*418b791dSBob Badour #endif
229*418b791dSBob Badour
std_letohs(unsigned short us)230*418b791dSBob Badour static __inline unsigned short std_letohs(unsigned short us)
231*418b791dSBob Badour {
232*418b791dSBob Badour return STD_HTOLES(us);
233*418b791dSBob Badour }
234*418b791dSBob Badour
std_htoles(unsigned short us)235*418b791dSBob Badour static __inline unsigned short std_htoles(unsigned short us)
236*418b791dSBob Badour {
237*418b791dSBob Badour return STD_HTOLES(us);
238*418b791dSBob Badour }
239*418b791dSBob Badour
std_letohl(unsigned long ul)240*418b791dSBob Badour static __inline unsigned long std_letohl(unsigned long ul)
241*418b791dSBob Badour {
242*418b791dSBob Badour return STD_HTOLEL(ul);
243*418b791dSBob Badour }
244*418b791dSBob Badour
std_htolel(unsigned long ul)245*418b791dSBob Badour static __inline unsigned long std_htolel(unsigned long ul)
246*418b791dSBob Badour {
247*418b791dSBob Badour return STD_HTOLEL(ul);
248*418b791dSBob Badour }
249*418b791dSBob Badour
std_ntohs(unsigned short us)250*418b791dSBob Badour static __inline unsigned short std_ntohs(unsigned short us)
251*418b791dSBob Badour {
252*418b791dSBob Badour return STD_HTONS(us);
253*418b791dSBob Badour }
254*418b791dSBob Badour
std_htons(unsigned short us)255*418b791dSBob Badour static __inline unsigned short std_htons(unsigned short us)
256*418b791dSBob Badour {
257*418b791dSBob Badour return STD_HTONS(us);
258*418b791dSBob Badour }
259*418b791dSBob Badour
std_ntohl(unsigned long ul)260*418b791dSBob Badour static __inline unsigned long std_ntohl(unsigned long ul)
261*418b791dSBob Badour {
262*418b791dSBob Badour return STD_HTONL(ul);
263*418b791dSBob Badour }
264*418b791dSBob Badour
std_htonl(unsigned long ul)265*418b791dSBob Badour static __inline unsigned long std_htonl(unsigned long ul)
266*418b791dSBob Badour {
267*418b791dSBob Badour return STD_HTONL(ul);
268*418b791dSBob Badour }
269*418b791dSBob Badour
270*418b791dSBob Badour
271*418b791dSBob Badour #undef STD_HTONL // private macro; not exported as a supported API
272*418b791dSBob Badour #undef STD_HTONS // private macro; not exported as a supported API
273*418b791dSBob Badour #undef STD_HTOLEL // private macro; not exported as a supported API
274*418b791dSBob Badour #undef STD_HTOLES // private macro; not exported as a supported API
275*418b791dSBob Badour #undef STD_SWAPS // private macro; not exported as a supported API
276*418b791dSBob Badour #undef STD_SWAPL // private macro; not exported as a supported API
277*418b791dSBob Badour
278*418b791dSBob Badour
279*418b791dSBob Badour /*
280*418b791dSBob Badour =======================================================================
281*418b791dSBob Badour MACROS DOCUMENTATION
282*418b791dSBob Badour =======================================================================
283*418b791dSBob Badour
284*418b791dSBob Badour STD_CONTSTRAIN()
285*418b791dSBob Badour
286*418b791dSBob Badour Description:
287*418b791dSBob Badour STD_CONTSTRAIN() constrains a number to be between two other numbers.
288*418b791dSBob Badour
289*418b791dSBob Badour Definition:
290*418b791dSBob Badour STD_CONSTRAIN( val, min, max ) \
291*418b791dSBob Badour (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val))
292*418b791dSBob Badour
293*418b791dSBob Badour Parameters:
294*418b791dSBob Badour val: number to constrain
295*418b791dSBob Badour min: number to stay greater than or equal to
296*418b791dSBob Badour max: number to stay less than or equal to
297*418b791dSBob Badour
298*418b791dSBob Badour Evaluation Value:
299*418b791dSBob Badour the constrained number
300*418b791dSBob Badour
301*418b791dSBob Badour =======================================================================
302*418b791dSBob Badour
303*418b791dSBob Badour STD_BETWEEN()
304*418b791dSBob Badour
305*418b791dSBob Badour Description:
306*418b791dSBob Badour STD_BETWEEN() tests whether a number is between two other numbers.
307*418b791dSBob Badour
308*418b791dSBob Badour Definition:
309*418b791dSBob Badour STD_BETWEEN( val, minGE, maxLT ) \
310*418b791dSBob Badour ((unsigned)((unsigned)(val) - (unsigned)(minGE)) < \
311*418b791dSBob Badour (unsigned)((unsigned)(maxLT) - (unsigned)(minGE)))
312*418b791dSBob Badour
313*418b791dSBob Badour Parameters:
314*418b791dSBob Badour val: value to test
315*418b791dSBob Badour minGE: lower bound
316*418b791dSBob Badour maxLT: upper bound
317*418b791dSBob Badour
318*418b791dSBob Badour Evaluation Value:
319*418b791dSBob Badour 1 if val >= minGE and val < maxLT
320*418b791dSBob Badour
321*418b791dSBob Badour =======================================================================
322*418b791dSBob Badour
323*418b791dSBob Badour STD_ARRAY_SIZE()
324*418b791dSBob Badour
325*418b791dSBob Badour Description:
326*418b791dSBob Badour STD_ARRAY_SIZE() gives the number of elements in a statically allocated array.
327*418b791dSBob Badour
328*418b791dSBob Badour Definition:
329*418b791dSBob Badour STD_ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0]))
330*418b791dSBob Badour
331*418b791dSBob Badour Parameters:
332*418b791dSBob Badour a: array to test
333*418b791dSBob Badour
334*418b791dSBob Badour Evaluation Value:
335*418b791dSBob Badour number of elements in a
336*418b791dSBob Badour
337*418b791dSBob Badour =======================================================================
338*418b791dSBob Badour
339*418b791dSBob Badour STD_ARRAY_MEMBER()
340*418b791dSBob Badour
341*418b791dSBob Badour Description:
342*418b791dSBob Badour STD_ARRAY_MEMBER() tests whether an item is a member of a statically allocated array.
343*418b791dSBob Badour
344*418b791dSBob Badour Definition:
345*418b791dSBob Badour STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a))))
346*418b791dSBob Badour
347*418b791dSBob Badour Parameters:
348*418b791dSBob Badour p: item to test
349*418b791dSBob Badour a: array to check
350*418b791dSBob Badour
351*418b791dSBob Badour Evaluation Value:
352*418b791dSBob Badour 1 if p is in a
353*418b791dSBob Badour
354*418b791dSBob Badour =======================================================================
355*418b791dSBob Badour
356*418b791dSBob Badour STD_OFFSETOF()
357*418b791dSBob Badour
358*418b791dSBob Badour Description:
359*418b791dSBob Badour STD_OFFSETOF() gives the offset of member of a struct.
360*418b791dSBob Badour
361*418b791dSBob Badour Definition:
362*418b791dSBob Badour STD_OFFSETOF(type,member) (((char *)(&((type *)0)->member))-((char *)0))
363*418b791dSBob Badour
364*418b791dSBob Badour Parameters:
365*418b791dSBob Badour type: structured type
366*418b791dSBob Badour member: name of member in the struct
367*418b791dSBob Badour
368*418b791dSBob Badour Evaluation Value:
369*418b791dSBob Badour offset of member (in bytes) in type
370*418b791dSBob Badour
371*418b791dSBob Badour =======================================================================
372*418b791dSBob Badour
373*418b791dSBob Badour STD_RECOVER_REC()
374*418b791dSBob Badour
375*418b791dSBob Badour Description:
376*418b791dSBob Badour STD_RECOVER_REC() provides a safe cast from a pointer to a member
377*418b791dSBob Badour of a struct to a pointer to the containing struct
378*418b791dSBob Badour
379*418b791dSBob Badour Definition:
380*418b791dSBob Badour STD_RECOVER_REC(type,member,p) ((type*)(((char*)(p))-STD_OFFSETOF(type,member)))
381*418b791dSBob Badour
382*418b791dSBob Badour Parameters:
383*418b791dSBob Badour type: structured type
384*418b791dSBob Badour member: name of member in the struct
385*418b791dSBob Badour p: pointer to the member of the struct
386*418b791dSBob Badour
387*418b791dSBob Badour Evaluation Value:
388*418b791dSBob Badour a pointer of type type to the containing struct
389*418b791dSBob Badour
390*418b791dSBob Badour =======================================================================
391*418b791dSBob Badour
392*418b791dSBob Badour STD_MIN()
393*418b791dSBob Badour
394*418b791dSBob Badour Description:
395*418b791dSBob Badour STD_MIN() finds the smaller of two values.
396*418b791dSBob Badour
397*418b791dSBob Badour Definition:
398*418b791dSBob Badour STD_MIN(a,b) ((a)<(b)?(a):(b))
399*418b791dSBob Badour
400*418b791dSBob Badour Parameters:
401*418b791dSBob Badour a, b: values to compare
402*418b791dSBob Badour
403*418b791dSBob Badour Evaluation Value:
404*418b791dSBob Badour smaller of a and b
405*418b791dSBob Badour
406*418b791dSBob Badour =======================================================================
407*418b791dSBob Badour
408*418b791dSBob Badour STD_MAX()
409*418b791dSBob Badour
410*418b791dSBob Badour Description:
411*418b791dSBob Badour STD_MAX() finds the larger of two values.
412*418b791dSBob Badour
413*418b791dSBob Badour Definition:
414*418b791dSBob Badour STD_MAX(a,b) ((a)>(b)?(a):(b))
415*418b791dSBob Badour
416*418b791dSBob Badour Parameters:
417*418b791dSBob Badour a, b: values to compare
418*418b791dSBob Badour
419*418b791dSBob Badour Evaluation Value:
420*418b791dSBob Badour larger of a and b
421*418b791dSBob Badour
422*418b791dSBob Badour =======================================================================
423*418b791dSBob Badour
424*418b791dSBob Badour STD_ZEROAT()
425*418b791dSBob Badour
426*418b791dSBob Badour Description:
427*418b791dSBob Badour STD_ZEROAT() zero-initializes the contents of a typed chunk of memory.
428*418b791dSBob Badour
429*418b791dSBob Badour Definition:
430*418b791dSBob Badour STD_ZEROAT(p) std_memset((p), 0, sizeof(*p))
431*418b791dSBob Badour
432*418b791dSBob Badour Parameters:
433*418b791dSBob Badour p: the chunk to initialize
434*418b791dSBob Badour
435*418b791dSBob Badour Evaluation Value:
436*418b791dSBob Badour p
437*418b791dSBob Badour
438*418b791dSBob Badour =======================================================================
439*418b791dSBob Badour
440*418b791dSBob Badour STD_BIT_SET()
441*418b791dSBob Badour
442*418b791dSBob Badour Description:
443*418b791dSBob Badour STD_BIT_SET(bits, ix) sets the bit in the memory stored in bits at
444*418b791dSBob Badour index ix
445*418b791dSBob Badour
446*418b791dSBob Badour Parameters:
447*418b791dSBob Badour bits: the memory address holding the bits
448*418b791dSBob Badour ix: the index of the bit to set;
449*418b791dSBob Badour
450*418b791dSBob Badour =======================================================================
451*418b791dSBob Badour
452*418b791dSBob Badour STD_BIT_CLEAR()
453*418b791dSBob Badour
454*418b791dSBob Badour Description:
455*418b791dSBob Badour STD_BIT_CLEAR(bits, ix) clears the bit in the memory stored in bits
456*418b791dSBob Badour at index ix
457*418b791dSBob Badour
458*418b791dSBob Badour Parameters:
459*418b791dSBob Badour bits: the memory address holding the bits
460*418b791dSBob Badour ix: the index of the bit to clear
461*418b791dSBob Badour
462*418b791dSBob Badour =======================================================================
463*418b791dSBob Badour
464*418b791dSBob Badour STD_BIT_TEST()
465*418b791dSBob Badour
466*418b791dSBob Badour Description:
467*418b791dSBob Badour STD_BIT_TEST(bits, ix) returns the bit in the memory stored in bits
468*418b791dSBob Badour at index ix
469*418b791dSBob Badour
470*418b791dSBob Badour Parameters:
471*418b791dSBob Badour bits: the memory address holding the bits
472*418b791dSBob Badour ix: the index of the bit to test
473*418b791dSBob Badour
474*418b791dSBob Badour Evaluation Value:
475*418b791dSBob Badour 0x1 if set 0x0 if not set
476*418b791dSBob Badour
477*418b791dSBob Badour =====================================================================
478*418b791dSBob Badour INTERFACES DOCUMENTATION
479*418b791dSBob Badour =======================================================================
480*418b791dSBob Badour
481*418b791dSBob Badour std Interface
482*418b791dSBob Badour
483*418b791dSBob Badour Description:
484*418b791dSBob Badour This library provides a set of general-purpose utility functions.
485*418b791dSBob Badour Functionality may overlap that of a subset of the C standard library, but
486*418b791dSBob Badour this library differs in a few respects:
487*418b791dSBob Badour
488*418b791dSBob Badour - Functions are fully reentrant and avoid use of static variables.
489*418b791dSBob Badour
490*418b791dSBob Badour - The library can be supported consistently across all environments.
491*418b791dSBob Badour Compiler-supplied libraries sometimes behave inconsistently and are
492*418b791dSBob Badour unavailable in some environments.
493*418b791dSBob Badour
494*418b791dSBob Badour - Omits "unsafe" functions. C standard library includes many functions
495*418b791dSBob Badour that are best avoided entirely: strcpy, strcat, strtok, etc.
496*418b791dSBob Badour
497*418b791dSBob Badour
498*418b791dSBob Badour =======================================================================
499*418b791dSBob Badour
500*418b791dSBob Badour std_getversion()
501*418b791dSBob Badour
502*418b791dSBob Badour Description:
503*418b791dSBob Badour
504*418b791dSBob Badour The std_getversion() copies the stdlib version to pcDst. This function
505*418b791dSBob Badour takes the size of the destination buffer as an argument and guarantees
506*418b791dSBob Badour to zero-terminate the result and not to overflow the nDestSize size.
507*418b791dSBob Badour
508*418b791dSBob Badour This function copies up to size-1 characters from the stdlib version
509*418b791dSBob Badour string to pcDest and NUL-terminates the pcDest string.
510*418b791dSBob Badour
511*418b791dSBob Badour Prototype:
512*418b791dSBob Badour int std_getversion(char *pcDst, int nDestSize)
513*418b791dSBob Badour
514*418b791dSBob Badour
515*418b791dSBob Badour Parameters:
516*418b791dSBob Badour pcDst : Destination string
517*418b791dSBob Badour nDestSize: Size of the destination buffer in bytes
518*418b791dSBob Badour
519*418b791dSBob Badour Return Value:
520*418b791dSBob Badour
521*418b791dSBob Badour Returns the length of the version string (in characters).
522*418b791dSBob Badour
523*418b791dSBob Badour =======================================================================
524*418b791dSBob Badour
525*418b791dSBob Badour std_strlen()
526*418b791dSBob Badour
527*418b791dSBob Badour Description:
528*418b791dSBob Badour The std_strlen() computes the length of the given string.
529*418b791dSBob Badour
530*418b791dSBob Badour Prototype:
531*418b791dSBob Badour int std_strlen(const char *cpszStr)
532*418b791dSBob Badour
533*418b791dSBob Badour Parameters:
534*418b791dSBob Badour cpszStr : String whose length will be computed
535*418b791dSBob Badour
536*418b791dSBob Badour Return Value:
537*418b791dSBob Badour Length of the string in characters that precede the terminating NULL character.
538*418b791dSBob Badour
539*418b791dSBob Badour =======================================================================
540*418b791dSBob Badour
541*418b791dSBob Badour std_strcmp()
542*418b791dSBob Badour
543*418b791dSBob Badour Description:
544*418b791dSBob Badour The std_strcmp() compares two NUL-terminated character strings.
545*418b791dSBob Badour Comparison is strictly by byte values with no character set
546*418b791dSBob Badour interpretation.
547*418b791dSBob Badour
548*418b791dSBob Badour Prototype:
549*418b791dSBob Badour
550*418b791dSBob Badour int std_strcmp(const char *s1, const char *s2);
551*418b791dSBob Badour
552*418b791dSBob Badour Parameters:
553*418b791dSBob Badour s1, s2: strings to compare
554*418b791dSBob Badour
555*418b791dSBob Badour Return Value:
556*418b791dSBob Badour 0 if strings are the same ~
557*418b791dSBob Badour < 0 if s1 is less than s2 ~
558*418b791dSBob Badour > 0 if s1 is greater than s2
559*418b791dSBob Badour
560*418b791dSBob Badour See Also:
561*418b791dSBob Badour std_wstrcmp
562*418b791dSBob Badour
563*418b791dSBob Badour =======================================================================
564*418b791dSBob Badour
565*418b791dSBob Badour std_strncmp()
566*418b791dSBob Badour
567*418b791dSBob Badour Description:
568*418b791dSBob Badour The std_strncmp() compares at most n bytes of two NUL-terminated character strings.
569*418b791dSBob Badour
570*418b791dSBob Badour Prototype:
571*418b791dSBob Badour
572*418b791dSBob Badour int std_strncmp(const char *s1, const char *s2, int n);
573*418b791dSBob Badour
574*418b791dSBob Badour Parameters:
575*418b791dSBob Badour s1, s2: strings to compare
576*418b791dSBob Badour n: maximum number of bytes to compare. if either s1 or s2 is
577*418b791dSBob Badour shorter than n, the function terminates there
578*418b791dSBob Badour
579*418b791dSBob Badour Return Value:
580*418b791dSBob Badour 0 if strings are the same ~
581*418b791dSBob Badour < 0 if s1 is less than s2 ~
582*418b791dSBob Badour > 0 if s1 is greater than s2
583*418b791dSBob Badour
584*418b791dSBob Badour See Also:
585*418b791dSBob Badour std_wstrncmp
586*418b791dSBob Badour
587*418b791dSBob Badour =======================================================================
588*418b791dSBob Badour
589*418b791dSBob Badour std_stricmp()
590*418b791dSBob Badour
591*418b791dSBob Badour Description:
592*418b791dSBob Badour The std_stricmp() compares two NUL-terminated character strings, case-folding any
593*418b791dSBob Badour ASCII characters.
594*418b791dSBob Badour
595*418b791dSBob Badour Prototype:
596*418b791dSBob Badour
597*418b791dSBob Badour int std_stricmp(const char *s1, const char *s2);
598*418b791dSBob Badour
599*418b791dSBob Badour Parameters:
600*418b791dSBob Badour s1, s2: strings to compare
601*418b791dSBob Badour
602*418b791dSBob Badour Return Value:
603*418b791dSBob Badour 0 if strings are the same ~
604*418b791dSBob Badour < 0 if s1 is less than s2 ~
605*418b791dSBob Badour > 0 if s1 is greater than s2
606*418b791dSBob Badour
607*418b791dSBob Badour =======================================================================
608*418b791dSBob Badour
609*418b791dSBob Badour std_strnicmp()
610*418b791dSBob Badour
611*418b791dSBob Badour Description:
612*418b791dSBob Badour The std_strnicmp() compares at most n bytes of 2 NUL-terminated character strings,
613*418b791dSBob Badour case-folding any ASCII characters.
614*418b791dSBob Badour
615*418b791dSBob Badour Prototype:
616*418b791dSBob Badour
617*418b791dSBob Badour int std_strnicmp(const char *s1, const char *s2, int n);
618*418b791dSBob Badour
619*418b791dSBob Badour Parameters:
620*418b791dSBob Badour s1, s2: strings to compare
621*418b791dSBob Badour n: maximum number of bytes to compare. if either s1 or s2 is
622*418b791dSBob Badour shorter than n, the function terminates there
623*418b791dSBob Badour
624*418b791dSBob Badour Return Value:
625*418b791dSBob Badour 0 if strings are the same ~
626*418b791dSBob Badour < 0 if s1 is less than s2 ~
627*418b791dSBob Badour > 0 if s1 is greater than s2
628*418b791dSBob Badour
629*418b791dSBob Badour =======================================================================
630*418b791dSBob Badour
631*418b791dSBob Badour std_strlcpy()
632*418b791dSBob Badour
633*418b791dSBob Badour Description:
634*418b791dSBob Badour
635*418b791dSBob Badour The std_strlcpy() copies pszSrc string to the pcDst. It is a safer
636*418b791dSBob Badour alternative to strcpy() or strncpy(). This function takes the size of the
637*418b791dSBob Badour destination buffer as an argument and guarantees to NUL-terminate the
638*418b791dSBob Badour result and not to overflow the nDestSize size.
639*418b791dSBob Badour
640*418b791dSBob Badour This function copies up to nDestSize-1 characters from the pszSrc string
641*418b791dSBob Badour to pcDest and NUL-terminates the pcDest string.
642*418b791dSBob Badour
643*418b791dSBob Badour Prototype:
644*418b791dSBob Badour int std_strlcpy(char *pcDst, const char *pszSrc, int nDestSize)
645*418b791dSBob Badour
646*418b791dSBob Badour Parameters:
647*418b791dSBob Badour pcDst : Destination string
648*418b791dSBob Badour pcSrc : Source string
649*418b791dSBob Badour nDestSize: Size of the destination buffer in bytes
650*418b791dSBob Badour
651*418b791dSBob Badour Return Value:
652*418b791dSBob Badour
653*418b791dSBob Badour Returns the length of the string (in characters) it tried to create,
654*418b791dSBob Badour which is same as length of pszSrc.
655*418b791dSBob Badour
656*418b791dSBob Badour Example:
657*418b791dSBob Badour
658*418b791dSBob Badour {
659*418b791dSBob Badour char buf[64];
660*418b791dSBob Badour if (std_strlcpy(buf, file_name, STD_ARRAY_SIZE(buf) >=
661*418b791dSBob Badour STD_ARRAY_SIZE(buf)) {
662*418b791dSBob Badour //Truncated -- Handle overflow....
663*418b791dSBob Badour }
664*418b791dSBob Badour }
665*418b791dSBob Badour
666*418b791dSBob Badour Comment:
667*418b791dSBob Badour
668*418b791dSBob Badour Unlike strlcpy, std_strlcpy accepts an integer size and does nothing when a
669*418b791dSBob Badour negative value is passed. When passing valid sizes for objects on our
670*418b791dSBob Badour supported platforms, this should not result in any observed difference.
671*418b791dSBob Badour However, calling strlcpy() with UINT_MAX will result in the entire source
672*418b791dSBob Badour string being copied, whereas std_strlcpy() will do nothing. Passing INT_MAX
673*418b791dSBob Badour to str_strlcpy() will achieve the same result (although both these cases are
674*418b791dSBob Badour bad practice since they defeat bounds checking).
675*418b791dSBob Badour
676*418b791dSBob Badour
677*418b791dSBob Badour =======================================================================
678*418b791dSBob Badour
679*418b791dSBob Badour std_strlcat()
680*418b791dSBob Badour
681*418b791dSBob Badour Description:
682*418b791dSBob Badour
683*418b791dSBob Badour The std_strlcat() function concatenates a string to a string already
684*418b791dSBob Badour residing in a buffer. It is a safer alternative to strcat() or strncat().
685*418b791dSBob Badour This function takes the size of the destination buffer as an argument and
686*418b791dSBob Badour guarantees not to create an improperly terminated string and not to
687*418b791dSBob Badour overflow the nDestSize size.
688*418b791dSBob Badour
689*418b791dSBob Badour This function appends pszSrc to pcDst, copying at most nDestSize minus
690*418b791dSBob Badour the length of the string in pcDest minus 1 bytes, always NUL-terminating
691*418b791dSBob Badour the result.
692*418b791dSBob Badour
693*418b791dSBob Badour For compatibility with "strlcat()", std_strlcat() does *not* zero-terminate
694*418b791dSBob Badour the destination buffer in cases where the buffer lacks termination on entry
695*418b791dSBob Badour to the function. Do not rely on std_strlcat() to zero-terminate a buffer
696*418b791dSBob Badour that is not already zero-terminated; instead ensure that the buffer is
697*418b791dSBob Badour properly initialized using std_strlcpy() or some other means.
698*418b791dSBob Badour
699*418b791dSBob Badour Prototype:
700*418b791dSBob Badour
701*418b791dSBob Badour int std_strlcat(char *pcDst, const char *pszSrc, int nDestSize)
702*418b791dSBob Badour
703*418b791dSBob Badour Parameters:
704*418b791dSBob Badour
705*418b791dSBob Badour pcDst : Destination string
706*418b791dSBob Badour pcSrc : Source string
707*418b791dSBob Badour nDestSize: Size of the destination buffer in bytes
708*418b791dSBob Badour
709*418b791dSBob Badour Return Value:
710*418b791dSBob Badour
711*418b791dSBob Badour Returns the length of the string (in characters) it tried to create,
712*418b791dSBob Badour which is same as length of pszSrc plus the length of pszDest.
713*418b791dSBob Badour
714*418b791dSBob Badour Example:
715*418b791dSBob Badour
716*418b791dSBob Badour {
717*418b791dSBob Badour char buf[64];
718*418b791dSBob Badour if (std_strlcat(buf, file_name, STD_ARRAY_SIZE(buf) >=
719*418b791dSBob Badour STD_ARRAY_SIZE(buf)) {
720*418b791dSBob Badour //Truncated -- Handle overflow....
721*418b791dSBob Badour }
722*418b791dSBob Badour }
723*418b791dSBob Badour
724*418b791dSBob Badour
725*418b791dSBob Badour =======================================================================
726*418b791dSBob Badour
727*418b791dSBob Badour std_strstr()
728*418b791dSBob Badour
729*418b791dSBob Badour Description:
730*418b791dSBob Badour The std_strstr() finds the first occurrence of a substring in a string.
731*418b791dSBob Badour
732*418b791dSBob Badour Prototype:
733*418b791dSBob Badour
734*418b791dSBob Badour char * std_strstr(const char *pszString, const char *pszSearch);
735*418b791dSBob Badour
736*418b791dSBob Badour Parameters:
737*418b791dSBob Badour pszString: string to search
738*418b791dSBob Badour pszSearch: sub string to search for
739*418b791dSBob Badour
740*418b791dSBob Badour Return Value:
741*418b791dSBob Badour A pointer to the first character in the first occurrence of the substring if found, NULL otherwise
742*418b791dSBob Badour
743*418b791dSBob Badour =======================================================================
744*418b791dSBob Badour
745*418b791dSBob Badour std_tolower()
746*418b791dSBob Badour
747*418b791dSBob Badour Description:
748*418b791dSBob Badour The std_tolower() converts an uppercase letter to the corresponding
749*418b791dSBob Badour lowercase letter.
750*418b791dSBob Badour
751*418b791dSBob Badour Prototype:
752*418b791dSBob Badour char std_tolower(char c);
753*418b791dSBob Badour
754*418b791dSBob Badour Parameters:
755*418b791dSBob Badour c: A character.
756*418b791dSBob Badour
757*418b791dSBob Badour Return Value:
758*418b791dSBob Badour the corresponding lowercase letter if c is an ASCII character whose
759*418b791dSBob Badour value is representable as an uppercase letter, else the same character
760*418b791dSBob Badour c is returned.
761*418b791dSBob Badour
762*418b791dSBob Badour =======================================================================
763*418b791dSBob Badour
764*418b791dSBob Badour std_toupper()
765*418b791dSBob Badour
766*418b791dSBob Badour Description:
767*418b791dSBob Badour The std_toupper() converts an lowercase letter to the corresponding
768*418b791dSBob Badour uppercase letter.
769*418b791dSBob Badour
770*418b791dSBob Badour Prototype:
771*418b791dSBob Badour char std_toupper(char c);
772*418b791dSBob Badour
773*418b791dSBob Badour Parameters:
774*418b791dSBob Badour c: is a character.
775*418b791dSBob Badour
776*418b791dSBob Badour Return Value:
777*418b791dSBob Badour The corresponding uppercase letter if c is an ASCII character whose
778*418b791dSBob Badour value is representable as an lowercase letter; else the same character
779*418b791dSBob Badour c is returned.
780*418b791dSBob Badour
781*418b791dSBob Badour =======================================================================
782*418b791dSBob Badour
783*418b791dSBob Badour std_memset()
784*418b791dSBob Badour
785*418b791dSBob Badour Description:
786*418b791dSBob Badour The std_memset() sets each byte in a block of memory to a value.
787*418b791dSBob Badour
788*418b791dSBob Badour Prototype:
789*418b791dSBob Badour
790*418b791dSBob Badour void *std_memset(void *p, int c, int nLen);
791*418b791dSBob Badour
792*418b791dSBob Badour Parameters:
793*418b791dSBob Badour p: memory block to set
794*418b791dSBob Badour c: value to set each byte to
795*418b791dSBob Badour nLen: size of p in bytes
796*418b791dSBob Badour
797*418b791dSBob Badour Return Value:
798*418b791dSBob Badour p
799*418b791dSBob Badour
800*418b791dSBob Badour =======================================================================
801*418b791dSBob Badour
802*418b791dSBob Badour std_memmove()
803*418b791dSBob Badour
804*418b791dSBob Badour Description:
805*418b791dSBob Badour The std_memmove() copies a block of memory from one buffer to another.
806*418b791dSBob Badour
807*418b791dSBob Badour Prototype:
808*418b791dSBob Badour
809*418b791dSBob Badour void *std_memmove(void *pTo, const void *cpFrom, int nLen);
810*418b791dSBob Badour
811*418b791dSBob Badour Parameters:
812*418b791dSBob Badour pTo: destination buffer
813*418b791dSBob Badour cpFrom: source buffer
814*418b791dSBob Badour nLen: number of bytes to copy
815*418b791dSBob Badour
816*418b791dSBob Badour Return Value:
817*418b791dSBob Badour pTo
818*418b791dSBob Badour
819*418b791dSBob Badour =======================================================================
820*418b791dSBob Badour
821*418b791dSBob Badour std_memsmove()
822*418b791dSBob Badour
823*418b791dSBob Badour Description:
824*418b791dSBob Badour
825*418b791dSBob Badour Size bounded memory move.
826*418b791dSBob Badour
827*418b791dSBob Badour Moves bytes from the source buffer to the destination buffer.
828*418b791dSBob Badour
829*418b791dSBob Badour This function ensures that there will not be a copy beyond
830*418b791dSBob Badour the size of the destination buffer.
831*418b791dSBob Badour
832*418b791dSBob Badour This function should be used in preference to memscpy() if there
833*418b791dSBob Badour is the possiblity of source and destination buffers overlapping.
834*418b791dSBob Badour The result of the operation is defined to be as if the copy were from
835*418b791dSBob Badour the source to a temporary buffer that overlaps neither source nor
836*418b791dSBob Badour destination, followed by a copy from that temporary buffer to the
837*418b791dSBob Badour destination.
838*418b791dSBob Badour
839*418b791dSBob Badour Prototype:
840*418b791dSBob Badour
841*418b791dSBob Badour int std_memsmove(void *dst, int dst_size, const void *src, int src_size);
842*418b791dSBob Badour
843*418b791dSBob Badour Parameters:
844*418b791dSBob Badour @param[out] dst Destination buffer.
845*418b791dSBob Badour @param[in] dst_size Size of the destination buffer in bytes.
846*418b791dSBob Badour @param[in] src Source buffer.
847*418b791dSBob Badour @param[in] src_size Number of bytes to copy from source buffer.
848*418b791dSBob Badour
849*418b791dSBob Badour Return value:
850*418b791dSBob Badour The number of bytes copied to the destination buffer. It is the
851*418b791dSBob Badour caller's responsibility to check for trunction if it cares about it -
852*418b791dSBob Badour truncation has occurred if the return value is less than src_size.
853*418b791dSBob Badour A negative return value indicates an error
854*418b791dSBob Badour
855*418b791dSBob Badour =======================================================================
856*418b791dSBob Badour
857*418b791dSBob Badour std_memcmp()
858*418b791dSBob Badour
859*418b791dSBob Badour Description:
860*418b791dSBob Badour The std_memcmp() compares two memory buffers, byte-wise.
861*418b791dSBob Badour
862*418b791dSBob Badour Prototype:
863*418b791dSBob Badour
864*418b791dSBob Badour int std_memcmp(const void *a, const void *b, int length);
865*418b791dSBob Badour
866*418b791dSBob Badour Parameters:
867*418b791dSBob Badour a, b: buffers to compare
868*418b791dSBob Badour length: number of bytes to compare
869*418b791dSBob Badour
870*418b791dSBob Badour Return Value:
871*418b791dSBob Badour 0 if buffers are the same for nLength ~
872*418b791dSBob Badour < 0 if a is less than b ~
873*418b791dSBob Badour > 0 if a is greater than b
874*418b791dSBob Badour
875*418b791dSBob Badour =======================================================================
876*418b791dSBob Badour
877*418b791dSBob Badour std_memscpy - Size bounded memory copy.
878*418b791dSBob Badour
879*418b791dSBob Badour Description:
880*418b791dSBob Badour
881*418b791dSBob Badour Copies bytes from the source buffer to the destination buffer.
882*418b791dSBob Badour
883*418b791dSBob Badour This function ensures that there will not be a copy beyond
884*418b791dSBob Badour the size of the destination buffer.
885*418b791dSBob Badour
886*418b791dSBob Badour The result of calling this on overlapping source and destination
887*418b791dSBob Badour buffers is undefined.
888*418b791dSBob Badour
889*418b791dSBob Badour Prototype:
890*418b791dSBob Badour
891*418b791dSBob Badour int std_memscpy(void *dst, int dst_size, const void *src, int src_size);
892*418b791dSBob Badour
893*418b791dSBob Badour Parameters:
894*418b791dSBob Badour
895*418b791dSBob Badour @param[out] dst Destination buffer.
896*418b791dSBob Badour @param[in] dst_size Size of the destination buffer in bytes.
897*418b791dSBob Badour @param[in] src Source buffer.
898*418b791dSBob Badour @param[in] src_size Number of bytes to copy from source buffer.
899*418b791dSBob Badour
900*418b791dSBob Badour Return value:
901*418b791dSBob Badour
902*418b791dSBob Badour The number of bytes copied to the destination buffer. It is the
903*418b791dSBob Badour caller's responsibility to check for trunction if it cares about it -
904*418b791dSBob Badour truncation has occurred if the return value is less than src_size.
905*418b791dSBob Badour Returs a negative value on error.
906*418b791dSBob Badour
907*418b791dSBob Badour =======================================================================
908*418b791dSBob Badour
909*418b791dSBob Badour std_memchr()
910*418b791dSBob Badour
911*418b791dSBob Badour Description:
912*418b791dSBob Badour The std_memchr() finds the first occurrence of a character in a memory
913*418b791dSBob Badour buffer.
914*418b791dSBob Badour
915*418b791dSBob Badour Prototype:
916*418b791dSBob Badour
917*418b791dSBob Badour void *std_memchr(const void* s, int c, int n);
918*418b791dSBob Badour
919*418b791dSBob Badour Parameters:
920*418b791dSBob Badour s: buffer to search
921*418b791dSBob Badour c: value of byte to look for
922*418b791dSBob Badour n: size of s in bytes
923*418b791dSBob Badour
924*418b791dSBob Badour Return Value:
925*418b791dSBob Badour A pointer to the occurrence of c. NULL if not found.
926*418b791dSBob Badour
927*418b791dSBob Badour =======================================================================
928*418b791dSBob Badour
929*418b791dSBob Badour std_memstr()
930*418b791dSBob Badour
931*418b791dSBob Badour Description:
932*418b791dSBob Badour The std_memstr() finds the first occurrence of a substring in a memory
933*418b791dSBob Badour buffer.
934*418b791dSBob Badour
935*418b791dSBob Badour Prototype:
936*418b791dSBob Badour
937*418b791dSBob Badour void *std_memstr(const char* cpHaystack, const char* cpszNeedle,
938*418b791dSBob Badour int nHaystackLen);
939*418b791dSBob Badour
940*418b791dSBob Badour Parameters:
941*418b791dSBob Badour cpHaystack: buffer to search
942*418b791dSBob Badour cpszNeedle: NUL-terminated string to search for
943*418b791dSBob Badour nHaystackLen: size of cpHaystack in bytes
944*418b791dSBob Badour
945*418b791dSBob Badour Return Value:
946*418b791dSBob Badour a pointer to the first occurrence of cpszNeedle if found,
947*418b791dSBob Badour NULL otherwise
948*418b791dSBob Badour
949*418b791dSBob Badour Comments:
950*418b791dSBob Badour None
951*418b791dSBob Badour
952*418b791dSBob Badour Side Effects:
953*418b791dSBob Badour None
954*418b791dSBob Badour
955*418b791dSBob Badour See Also:
956*418b791dSBob Badour None
957*418b791dSBob Badour
958*418b791dSBob Badour =======================================================================
959*418b791dSBob Badour
960*418b791dSBob Badour std_memrchr()
961*418b791dSBob Badour
962*418b791dSBob Badour Description:
963*418b791dSBob Badour
964*418b791dSBob Badour The std_memrchr() finds the last occurrence of a character in a memory
965*418b791dSBob Badour buffer.
966*418b791dSBob Badour
967*418b791dSBob Badour Prototype:
968*418b791dSBob Badour
969*418b791dSBob Badour void *std_memrchr(const void* s, int c, int n);
970*418b791dSBob Badour
971*418b791dSBob Badour Parameters:
972*418b791dSBob Badour s: buffer to search
973*418b791dSBob Badour c: value of byte to look for
974*418b791dSBob Badour n: size of s in bytes
975*418b791dSBob Badour
976*418b791dSBob Badour Return Value:
977*418b791dSBob Badour a pointer to the last occurrence of c, NULL if not found
978*418b791dSBob Badour
979*418b791dSBob Badour =======================================================================
980*418b791dSBob Badour
981*418b791dSBob Badour std_memrchrbegin()
982*418b791dSBob Badour
983*418b791dSBob Badour Description:
984*418b791dSBob Badour The std_memrchrbegin() finds the last occurrence of a character in a
985*418b791dSBob Badour memory buffer.
986*418b791dSBob Badour
987*418b791dSBob Badour Prototype:
988*418b791dSBob Badour
989*418b791dSBob Badour void *std_memrchrbegin(const void* s, int c, int n);
990*418b791dSBob Badour
991*418b791dSBob Badour Parameters:
992*418b791dSBob Badour s: buffer to search
993*418b791dSBob Badour c: value of byte to look for
994*418b791dSBob Badour n: size of s in bytes
995*418b791dSBob Badour
996*418b791dSBob Badour Return Value:
997*418b791dSBob Badour a pointer to the last occurrence of c, or s if not found
998*418b791dSBob Badour
999*418b791dSBob Badour =======================================================================
1000*418b791dSBob Badour
1001*418b791dSBob Badour std_memchrend()
1002*418b791dSBob Badour
1003*418b791dSBob Badour Description:
1004*418b791dSBob Badour The std_memchrend() finds the first occurrence of a character in a
1005*418b791dSBob Badour memory buffer.
1006*418b791dSBob Badour
1007*418b791dSBob Badour Prototype:
1008*418b791dSBob Badour
1009*418b791dSBob Badour void *std_memchrend(const void* s, int c, int n);
1010*418b791dSBob Badour
1011*418b791dSBob Badour Parameters:
1012*418b791dSBob Badour s: buffer to search
1013*418b791dSBob Badour c: value of byte to look for
1014*418b791dSBob Badour n: size of s in bytes
1015*418b791dSBob Badour
1016*418b791dSBob Badour Return Value:
1017*418b791dSBob Badour a pointer to the occurrence of c, s + n if not found
1018*418b791dSBob Badour
1019*418b791dSBob Badour =======================================================================
1020*418b791dSBob Badour std_memchrsend()
1021*418b791dSBob Badour
1022*418b791dSBob Badour Description:
1023*418b791dSBob Badour The std_memchrsend() finds the first occurrence of any character in a
1024*418b791dSBob Badour NUL-terminated list of characters in a memory buffer.
1025*418b791dSBob Badour
1026*418b791dSBob Badour Prototype:
1027*418b791dSBob Badour
1028*418b791dSBob Badour void *std_memchrend(const void* s, const char* cpszChars, int n);
1029*418b791dSBob Badour
1030*418b791dSBob Badour Parameters:
1031*418b791dSBob Badour s: buffer to search
1032*418b791dSBob Badour cpszChars: characters to look for
1033*418b791dSBob Badour n: size of s in bytes
1034*418b791dSBob Badour
1035*418b791dSBob Badour Return Value:
1036*418b791dSBob Badour a pointer to the first occurrence of one of cpszChars, s + n if not found
1037*418b791dSBob Badour
1038*418b791dSBob Badour =======================================================================
1039*418b791dSBob Badour
1040*418b791dSBob Badour std_strchr()
1041*418b791dSBob Badour
1042*418b791dSBob Badour Description:
1043*418b791dSBob Badour The std_strchr() finds the first occurrence of a character in a
1044*418b791dSBob Badour NUL-terminated string.
1045*418b791dSBob Badour
1046*418b791dSBob Badour Prototype:
1047*418b791dSBob Badour
1048*418b791dSBob Badour char *std_strchr(const char* s, int c);
1049*418b791dSBob Badour
1050*418b791dSBob Badour Parameters:
1051*418b791dSBob Badour s: string to search
1052*418b791dSBob Badour c: char to search for
1053*418b791dSBob Badour
1054*418b791dSBob Badour Return Value:
1055*418b791dSBob Badour pointer to first occurrence, NULL if not found
1056*418b791dSBob Badour
1057*418b791dSBob Badour See Also:
1058*418b791dSBob Badour std_wstrchr
1059*418b791dSBob Badour
1060*418b791dSBob Badour =======================================================================
1061*418b791dSBob Badour
1062*418b791dSBob Badour std_strchrs()
1063*418b791dSBob Badour
1064*418b791dSBob Badour Description:
1065*418b791dSBob Badour The std_strchrs() searches s, a NUL-terminated string, for the first
1066*418b791dSBob Badour occurrence of any characters in cpszSrch, a NUL-terminated list of
1067*418b791dSBob Badour characters.
1068*418b791dSBob Badour
1069*418b791dSBob Badour Prototype:
1070*418b791dSBob Badour
1071*418b791dSBob Badour char *std_strchrs(const char* s, const char *cpszSrch);
1072*418b791dSBob Badour
1073*418b791dSBob Badour Parameters:
1074*418b791dSBob Badour s: string to search
1075*418b791dSBob Badour cpszSrch: a list of characters to search for
1076*418b791dSBob Badour
1077*418b791dSBob Badour Return Value:
1078*418b791dSBob Badour first occurrence of any of cpszSrch, NULL if not found
1079*418b791dSBob Badour
1080*418b791dSBob Badour =======================================================================
1081*418b791dSBob Badour
1082*418b791dSBob Badour std_strrchr()
1083*418b791dSBob Badour
1084*418b791dSBob Badour Description:
1085*418b791dSBob Badour The std_strrchr() finds the last occurrence of a character in a
1086*418b791dSBob Badour NUL-terminated string.
1087*418b791dSBob Badour
1088*418b791dSBob Badour Prototype:
1089*418b791dSBob Badour
1090*418b791dSBob Badour char *std_strrchr(const char* s, int c);
1091*418b791dSBob Badour
1092*418b791dSBob Badour Parameters:
1093*418b791dSBob Badour s: string to search
1094*418b791dSBob Badour c: char to search for
1095*418b791dSBob Badour
1096*418b791dSBob Badour Return Value:
1097*418b791dSBob Badour pointer to last occurrence, NULL if not found
1098*418b791dSBob Badour
1099*418b791dSBob Badour See Also:
1100*418b791dSBob Badour std_wstrrchr
1101*418b791dSBob Badour
1102*418b791dSBob Badour =======================================================================
1103*418b791dSBob Badour
1104*418b791dSBob Badour std_strchrend()
1105*418b791dSBob Badour
1106*418b791dSBob Badour Description:
1107*418b791dSBob Badour The std_strchrend() finds the first occurrence of a character in a
1108*418b791dSBob Badour NUL-terminated string.
1109*418b791dSBob Badour
1110*418b791dSBob Badour Prototype:
1111*418b791dSBob Badour
1112*418b791dSBob Badour char *std_strchrend(const char* s, int c);
1113*418b791dSBob Badour
1114*418b791dSBob Badour Parameters:
1115*418b791dSBob Badour s: string to search
1116*418b791dSBob Badour c: char to search for
1117*418b791dSBob Badour
1118*418b791dSBob Badour Return Value:
1119*418b791dSBob Badour pointer to first occurrence, s + std_strlen(s) if not found
1120*418b791dSBob Badour
1121*418b791dSBob Badour =======================================================================
1122*418b791dSBob Badour
1123*418b791dSBob Badour std_strchrsend()
1124*418b791dSBob Badour
1125*418b791dSBob Badour Description:
1126*418b791dSBob Badour The std_strchrsend() searches s, a NUL-terminated string, for the first
1127*418b791dSBob Badour occurrence of any characters in cpszSrch, a NUL-terminated list of
1128*418b791dSBob Badour characters.
1129*418b791dSBob Badour
1130*418b791dSBob Badour Prototype:
1131*418b791dSBob Badour
1132*418b791dSBob Badour char *std_strchrsend(const char* s, const char* cpszSrch);
1133*418b791dSBob Badour
1134*418b791dSBob Badour Parameters:
1135*418b791dSBob Badour s: string to search
1136*418b791dSBob Badour cpszSrch: a list of characters to search for
1137*418b791dSBob Badour
1138*418b791dSBob Badour Return Value:
1139*418b791dSBob Badour first occurrence of any of cpszSrch or s+strlen(s) if not found
1140*418b791dSBob Badour
1141*418b791dSBob Badour =======================================================================
1142*418b791dSBob Badour
1143*418b791dSBob Badour std_strends()
1144*418b791dSBob Badour
1145*418b791dSBob Badour Description:
1146*418b791dSBob Badour The std_strends() tests whether a string ends in a particular suffix.
1147*418b791dSBob Badour
1148*418b791dSBob Badour Prototype:
1149*418b791dSBob Badour
1150*418b791dSBob Badour char *std_strends(const char* cpsz, const char* cpszSuffix);
1151*418b791dSBob Badour
1152*418b791dSBob Badour Parameters:
1153*418b791dSBob Badour cpsz: string to test
1154*418b791dSBob Badour cpszSuffix: suffix to test for
1155*418b791dSBob Badour
1156*418b791dSBob Badour Return Value:
1157*418b791dSBob Badour the first character of cpsz+std_strlen(cpsz)-std_strlen(cpszSuffix)
1158*418b791dSBob Badour if cpsz ends with cpszSuffix. NULL otherwise.
1159*418b791dSBob Badour
1160*418b791dSBob Badour =======================================================================
1161*418b791dSBob Badour
1162*418b791dSBob Badour std_striends()
1163*418b791dSBob Badour
1164*418b791dSBob Badour Description:
1165*418b791dSBob Badour The std_striends() tests whether a string ends in a particular suffix,
1166*418b791dSBob Badour case-folding ASCII characters.
1167*418b791dSBob Badour
1168*418b791dSBob Badour Prototype:
1169*418b791dSBob Badour
1170*418b791dSBob Badour char *std_striends(const char* cpsz, const char* cpszSuffix);
1171*418b791dSBob Badour
1172*418b791dSBob Badour Parameters:
1173*418b791dSBob Badour cpsz: string to test
1174*418b791dSBob Badour cpszSuffix: suffix to test for
1175*418b791dSBob Badour
1176*418b791dSBob Badour Return Value:
1177*418b791dSBob Badour the first character of cpsz+std_strlen(cpsz)-std_strlen(cpszSuffix)
1178*418b791dSBob Badour if cpsz ends with cpszSuffix. NULL otherwise.
1179*418b791dSBob Badour
1180*418b791dSBob Badour =======================================================================
1181*418b791dSBob Badour
1182*418b791dSBob Badour std_strbegins()
1183*418b791dSBob Badour
1184*418b791dSBob Badour Description:
1185*418b791dSBob Badour The std_strbegins() tests whether a string begins with a particular
1186*418b791dSBob Badour prefix string.
1187*418b791dSBob Badour
1188*418b791dSBob Badour Prototype:
1189*418b791dSBob Badour
1190*418b791dSBob Badour char *std_strbegins(const char* cpsz, const char* cpszPrefix);
1191*418b791dSBob Badour
1192*418b791dSBob Badour Parameters:
1193*418b791dSBob Badour cpsz: string to test
1194*418b791dSBob Badour cpszPrefix: prefix to test for
1195*418b791dSBob Badour
1196*418b791dSBob Badour Return Value:
1197*418b791dSBob Badour cpsz + std_strlen(cpszPrefix) if cpsz does begin with cpszPrefix,
1198*418b791dSBob Badour NULL otherwise
1199*418b791dSBob Badour
1200*418b791dSBob Badour =======================================================================
1201*418b791dSBob Badour
1202*418b791dSBob Badour std_stribegins()
1203*418b791dSBob Badour
1204*418b791dSBob Badour Description:
1205*418b791dSBob Badour The std_stribegins() tests whether a string begins with a particular
1206*418b791dSBob Badour prefix string, case-folding ASCII characters.
1207*418b791dSBob Badour
1208*418b791dSBob Badour Prototype:
1209*418b791dSBob Badour
1210*418b791dSBob Badour char *std_stribegins(const char* cpsz, const char* cpszPrefix);
1211*418b791dSBob Badour
1212*418b791dSBob Badour Parameters:
1213*418b791dSBob Badour cpsz: string to test
1214*418b791dSBob Badour cpszPrefix: prefix to test for
1215*418b791dSBob Badour
1216*418b791dSBob Badour Return Value:
1217*418b791dSBob Badour cpsz + std_strlen(cpszPrefix) if cpsz does begin with cpszPrefix,
1218*418b791dSBob Badour NULL otherwise
1219*418b791dSBob Badour
1220*418b791dSBob Badour
1221*418b791dSBob Badour =======================================================================
1222*418b791dSBob Badour
1223*418b791dSBob Badour std_strcspn()
1224*418b791dSBob Badour
1225*418b791dSBob Badour Description:
1226*418b791dSBob Badour The std_strcspn() function searches s, a NUL-terminated string, for
1227*418b791dSBob Badour the first occurrence of any characters in cpszSrch, a NUL-terminated
1228*418b791dSBob Badour list of characters. This function returns the length of the longest
1229*418b791dSBob Badour initial substring of s which consists of characters not present in
1230*418b791dSBob Badour cpszSrch.
1231*418b791dSBob Badour
1232*418b791dSBob Badour Prototype:
1233*418b791dSBob Badour
1234*418b791dSBob Badour int std_strcspn(const char* s, const char* cpszSrch);
1235*418b791dSBob Badour
1236*418b791dSBob Badour Parameters:
1237*418b791dSBob Badour s: string to search
1238*418b791dSBob Badour cpszSrch: a list of characters to search for
1239*418b791dSBob Badour
1240*418b791dSBob Badour Return Value:
1241*418b791dSBob Badour The index into the string s of the first occurrence of any of the
1242*418b791dSBob Badour characters in cpszSrch. If no match is found, then index of the
1243*418b791dSBob Badour terminating NUL character is returned.
1244*418b791dSBob Badour
1245*418b791dSBob Badour See Also:
1246*418b791dSBob Badour std_strspn, std_strchr, std_strchrs
1247*418b791dSBob Badour
1248*418b791dSBob Badour =======================================================================
1249*418b791dSBob Badour
1250*418b791dSBob Badour std_strspn()
1251*418b791dSBob Badour
1252*418b791dSBob Badour Description:
1253*418b791dSBob Badour The std_strspn() functions searches s, a NUL-terminated string, for
1254*418b791dSBob Badour the first occurrence of a character that matches none of the
1255*418b791dSBob Badour characters in cpszSrch, a NUL-terminated list of characters. This
1256*418b791dSBob Badour function returns the length of the longest initial substring of s
1257*418b791dSBob Badour which consists of characters present in cpszSrch.
1258*418b791dSBob Badour
1259*418b791dSBob Badour Prototype:
1260*418b791dSBob Badour
1261*418b791dSBob Badour int std_strspn(const char* s, const char* cpszSrch);
1262*418b791dSBob Badour
1263*418b791dSBob Badour Parameters:
1264*418b791dSBob Badour s: string to search
1265*418b791dSBob Badour cpszSrch: a list of characters to search for
1266*418b791dSBob Badour
1267*418b791dSBob Badour Return Value:
1268*418b791dSBob Badour The index into the string s of the first occurrence of any character
1269*418b791dSBob Badour that matches none of the characters in cpszSrch. If all characters
1270*418b791dSBob Badour in s are present in cpszSrch, the index of the terminating NUL
1271*418b791dSBob Badour character is returned.
1272*418b791dSBob Badour
1273*418b791dSBob Badour See Also:
1274*418b791dSBob Badour std_strcspn, std_strchr, std_strchrs
1275*418b791dSBob Badour
1276*418b791dSBob Badour =======================================================================
1277*418b791dSBob Badour
1278*418b791dSBob Badour std_wstrlcpy()
1279*418b791dSBob Badour
1280*418b791dSBob Badour Description:
1281*418b791dSBob Badour
1282*418b791dSBob Badour The std_wstrlcpy() function copies a string. It is equivalent to
1283*418b791dSBob Badour str_strlcpy() except that it operates on wide (16-bit) character strings.
1284*418b791dSBob Badour See std_strlcpy() for details.
1285*418b791dSBob Badour
1286*418b791dSBob Badour
1287*418b791dSBob Badour Prototype:
1288*418b791dSBob Badour
1289*418b791dSBob Badour int std_wstrlcpy(AECHAR *pcDest, const AECHAR *pszSrc, int nDestSize);
1290*418b791dSBob Badour
1291*418b791dSBob Badour Parameters:
1292*418b791dSBob Badour pcDst: destination string
1293*418b791dSBob Badour pszSrc: source string
1294*418b791dSBob Badour int nDestSize: size of pcDest __in AECHARs__
1295*418b791dSBob Badour
1296*418b791dSBob Badour Return Value:
1297*418b791dSBob Badour Returns the length of the string (in AECHARs) it tried to create,
1298*418b791dSBob Badour which is same as length of pszSrc.
1299*418b791dSBob Badour
1300*418b791dSBob Badour Example:
1301*418b791dSBob Badour
1302*418b791dSBob Badour {
1303*418b791dSBob Badour AECHAR buf[64];
1304*418b791dSBob Badour if (std_wstrlcpy(buf, file_name, STD_ARRAY_SIZE(buf)) >=
1305*418b791dSBob Badour STD_ARRAY_SIZE(buf)) {
1306*418b791dSBob Badour //Truncated -- Handle overflow....
1307*418b791dSBob Badour }
1308*418b791dSBob Badour }
1309*418b791dSBob Badour
1310*418b791dSBob Badour See Also:
1311*418b791dSBob Badour std_wstrlcat
1312*418b791dSBob Badour
1313*418b791dSBob Badour =======================================================================
1314*418b791dSBob Badour
1315*418b791dSBob Badour std_wstrlcat()
1316*418b791dSBob Badour
1317*418b791dSBob Badour Description:
1318*418b791dSBob Badour
1319*418b791dSBob Badour The std_wstrlcat() function concatenates two strings. It is equivalent to
1320*418b791dSBob Badour std_strlcat() except that it operates on wide (16-bit) character strings.
1321*418b791dSBob Badour See std_strlcat() for more information.
1322*418b791dSBob Badour
1323*418b791dSBob Badour Prototype:
1324*418b791dSBob Badour int std_wstrlcat(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize)
1325*418b791dSBob Badour
1326*418b791dSBob Badour Parameters:
1327*418b791dSBob Badour pcDst[out]: Destination string
1328*418b791dSBob Badour pcSrc : Source string
1329*418b791dSBob Badour nDestSize: Size of the destination buffer in AECHARs
1330*418b791dSBob Badour
1331*418b791dSBob Badour Return Value:
1332*418b791dSBob Badour Returns the length of the string (in AECHARs) it tried to create,
1333*418b791dSBob Badour which is same as length of pszSrc + the length of pszDest.
1334*418b791dSBob Badour
1335*418b791dSBob Badour Example:
1336*418b791dSBob Badour
1337*418b791dSBob Badour {
1338*418b791dSBob Badour char buf[64];
1339*418b791dSBob Badour if (std_wstrlcat(buf, file_name, STD_ARRAY_SIZE(buf)) >=
1340*418b791dSBob Badour STD_ARRAY_SIZE(buf)) {
1341*418b791dSBob Badour //Truncated -- Handle overflow....
1342*418b791dSBob Badour }
1343*418b791dSBob Badour }
1344*418b791dSBob Badour
1345*418b791dSBob Badour See Also:
1346*418b791dSBob Badour std_wstrlcpy
1347*418b791dSBob Badour
1348*418b791dSBob Badour =======================================================================
1349*418b791dSBob Badour
1350*418b791dSBob Badour std_wstrncmp()
1351*418b791dSBob Badour
1352*418b791dSBob Badour Description:
1353*418b791dSBob Badour
1354*418b791dSBob Badour The std_wstrncmp() function compares up to a specified number of bytes
1355*418b791dSBob Badour in two NUL-terminated strings. It is equivalent to std_strncmp() except
1356*418b791dSBob Badour that it operates on wide (16-bit) character strings.
1357*418b791dSBob Badour
1358*418b791dSBob Badour Prototype:
1359*418b791dSBob Badour int std_wstrncmp(const AECHAR* s1, const AECHAR* s2, int nLen);
1360*418b791dSBob Badour
1361*418b791dSBob Badour Parameters:
1362*418b791dSBob Badour s1, s2: strings to compare
1363*418b791dSBob Badour n: maximum number of AECHARs to compare. if either s1 or s2 is
1364*418b791dSBob Badour shorter than n, the function terminates there.
1365*418b791dSBob Badour
1366*418b791dSBob Badour Return Value:
1367*418b791dSBob Badour 0 if strings are the same ~
1368*418b791dSBob Badour < 0 if s1 is less than s2 ~
1369*418b791dSBob Badour > 0 if s1 is greater than s2
1370*418b791dSBob Badour
1371*418b791dSBob Badour See Also:
1372*418b791dSBob Badour std_strncmp
1373*418b791dSBob Badour
1374*418b791dSBob Badour =======================================================================
1375*418b791dSBob Badour
1376*418b791dSBob Badour std_wstrcmp()
1377*418b791dSBob Badour
1378*418b791dSBob Badour Description:
1379*418b791dSBob Badour The std_wstrcmp() compares two NUL-terminated strings. It is equivalent
1380*418b791dSBob Badour to std_strncmp() except that it operates on wide (16-bit) character
1381*418b791dSBob Badour strings. Comparison is strictly by byte values with no character set
1382*418b791dSBob Badour interpretation.
1383*418b791dSBob Badour
1384*418b791dSBob Badour Prototype:
1385*418b791dSBob Badour
1386*418b791dSBob Badour int std_wstrcmp(const AECHAR* s1, const AECHAR* s2);
1387*418b791dSBob Badour
1388*418b791dSBob Badour Parameters:
1389*418b791dSBob Badour s1, s2: strings to compare
1390*418b791dSBob Badour
1391*418b791dSBob Badour Return Value:
1392*418b791dSBob Badour 0 if strings are the same ~
1393*418b791dSBob Badour < 0 if s1 is less than s2 ~
1394*418b791dSBob Badour > 0 if s1 is greater than s2
1395*418b791dSBob Badour
1396*418b791dSBob Badour See Also:
1397*418b791dSBob Badour std_strcmp
1398*418b791dSBob Badour
1399*418b791dSBob Badour =======================================================================
1400*418b791dSBob Badour
1401*418b791dSBob Badour std_wstrchr()
1402*418b791dSBob Badour
1403*418b791dSBob Badour Description:
1404*418b791dSBob Badour This function is the wide string counterpart of std_strchr().
1405*418b791dSBob Badour The std_wstrchr() finds the first occurrence of a character in a
1406*418b791dSBob Badour NUL-terminated wide (16-bit) character string.
1407*418b791dSBob Badour
1408*418b791dSBob Badour Prototype:
1409*418b791dSBob Badour
1410*418b791dSBob Badour AECHAR* std_wstrchr(const AECHAR* s, AECHAR ch);
1411*418b791dSBob Badour
1412*418b791dSBob Badour Parameters:
1413*418b791dSBob Badour s: string to search
1414*418b791dSBob Badour ch: char to search for
1415*418b791dSBob Badour
1416*418b791dSBob Badour Return Value:
1417*418b791dSBob Badour pointer to first occurrence, NULL if not found
1418*418b791dSBob Badour
1419*418b791dSBob Badour See Also:
1420*418b791dSBob Badour std_strchr
1421*418b791dSBob Badour
1422*418b791dSBob Badour =======================================================================
1423*418b791dSBob Badour
1424*418b791dSBob Badour std_wstrrchr()
1425*418b791dSBob Badour
1426*418b791dSBob Badour Description:
1427*418b791dSBob Badour This function is the wide string counterpart of std_strrchr().
1428*418b791dSBob Badour The std_wstrrchr() finds the last occurrence of a character in a
1429*418b791dSBob Badour NUL-terminated wide (16-bit) character string.
1430*418b791dSBob Badour
1431*418b791dSBob Badour Prototype:
1432*418b791dSBob Badour
1433*418b791dSBob Badour AECHAR* std_wstrrchr(const AECHAR* s, AECHAR ch);
1434*418b791dSBob Badour
1435*418b791dSBob Badour Parameters:
1436*418b791dSBob Badour s: string to search
1437*418b791dSBob Badour ch: char to search for
1438*418b791dSBob Badour
1439*418b791dSBob Badour Return Value:
1440*418b791dSBob Badour pointer to last occurrence, NULL if not found
1441*418b791dSBob Badour
1442*418b791dSBob Badour See Also:
1443*418b791dSBob Badour std_strrchr
1444*418b791dSBob Badour
1445*418b791dSBob Badour =======================================================================
1446*418b791dSBob Badour
1447*418b791dSBob Badour std_makepath()
1448*418b791dSBob Badour
1449*418b791dSBob Badour Description:
1450*418b791dSBob Badour The std_makepath() constructs a path from a directory portion and a file
1451*418b791dSBob Badour portion, using forward slashes, adding necessary slashes and deleting extra
1452*418b791dSBob Badour slashes. This function guarantees NUL-termination of pszDest
1453*418b791dSBob Badour
1454*418b791dSBob Badour Prototype:
1455*418b791dSBob Badour
1456*418b791dSBob Badour int std_makepath(const char *cpszDir, const char *cpszFile,
1457*418b791dSBob Badour char *pszDest, int nDestSize)
1458*418b791dSBob Badour
1459*418b791dSBob Badour Parameters:
1460*418b791dSBob Badour cpszDir: directory part
1461*418b791dSBob Badour cpszFile: file part
1462*418b791dSBob Badour pszDest: output buffer
1463*418b791dSBob Badour nDestSize: size of output buffer in bytes
1464*418b791dSBob Badour
1465*418b791dSBob Badour Return Value:
1466*418b791dSBob Badour the required length to construct the path, not including
1467*418b791dSBob Badour NUL-termination
1468*418b791dSBob Badour
1469*418b791dSBob Badour Comments:
1470*418b791dSBob Badour The following list of examples shows the strings returned by
1471*418b791dSBob Badour std_makepath() for different paths.
1472*418b791dSBob Badour
1473*418b791dSBob Badour Example:
1474*418b791dSBob Badour
1475*418b791dSBob Badour cpszDir cpszFile std_makepath()
1476*418b791dSBob Badour "" "" ""
1477*418b791dSBob Badour "" "/" ""
1478*418b791dSBob Badour "/" "" "/"
1479*418b791dSBob Badour "/" "/" "/"
1480*418b791dSBob Badour "/" "f" "/f"
1481*418b791dSBob Badour "/" "/f" "/f"
1482*418b791dSBob Badour "d" "f" "d/f"
1483*418b791dSBob Badour "d/" "f" "d/f"
1484*418b791dSBob Badour "d" "/f" "d/f"
1485*418b791dSBob Badour "d/" "/f" "d/f"
1486*418b791dSBob Badour
1487*418b791dSBob Badour See Also:
1488*418b791dSBob Badour std_splitpath
1489*418b791dSBob Badour
1490*418b791dSBob Badour =======================================================================
1491*418b791dSBob Badour
1492*418b791dSBob Badour std_splitpath()
1493*418b791dSBob Badour
1494*418b791dSBob Badour Description:
1495*418b791dSBob Badour The std_splitpath() finds the filename part of a path given an inclusive
1496*418b791dSBob Badour directory, tests for cpszPath being in cpszDir. The forward slashes are
1497*418b791dSBob Badour used as directory delimiters.
1498*418b791dSBob Badour
1499*418b791dSBob Badour Prototype:
1500*418b791dSBob Badour
1501*418b791dSBob Badour char *std_splitpath(const char *cpszPath, const char *cpszDir);
1502*418b791dSBob Badour
1503*418b791dSBob Badour Parameters:
1504*418b791dSBob Badour cpszPath: path to test for inclusion
1505*418b791dSBob Badour cpszDir: directory that cpszPath might be in
1506*418b791dSBob Badour
1507*418b791dSBob Badour Return Value:
1508*418b791dSBob Badour the part of cpszPath that actually falls beneath cpszDir, NULL if
1509*418b791dSBob Badour cpszPath is not under cpszDir
1510*418b791dSBob Badour
1511*418b791dSBob Badour Comments:
1512*418b791dSBob Badour The std_splitpath() is similar to std_strbegins(), but it ignores trailing
1513*418b791dSBob Badour slashes on cpszDir, and it returns a pointer to the first character of
1514*418b791dSBob Badour the subpath.
1515*418b791dSBob Badour
1516*418b791dSBob Badour The return value of std_splitpath() will never begin with a '/'.
1517*418b791dSBob Badour
1518*418b791dSBob Badour The following list of examples shows the strings returned by
1519*418b791dSBob Badour std_splitpath() for different paths.
1520*418b791dSBob Badour
1521*418b791dSBob Badour Example:
1522*418b791dSBob Badour cpszPath cpszDir std_splitpath()
1523*418b791dSBob Badour "" "" ""
1524*418b791dSBob Badour "" "/" ""
1525*418b791dSBob Badour "/" "" ""
1526*418b791dSBob Badour "/" "/" ""
1527*418b791dSBob Badour "/d" "d" null
1528*418b791dSBob Badour "/d" "/" "d"
1529*418b791dSBob Badour "/d/" "/d" ""
1530*418b791dSBob Badour "/d/f" "/" "d/f"
1531*418b791dSBob Badour "/d/f" "/d" "f"
1532*418b791dSBob Badour "/d/f" "/d/" "f"
1533*418b791dSBob Badour
1534*418b791dSBob Badour See Also:
1535*418b791dSBob Badour std_makepath
1536*418b791dSBob Badour
1537*418b791dSBob Badour =======================================================================
1538*418b791dSBob Badour
1539*418b791dSBob Badour std_cleanpath()
1540*418b791dSBob Badour
1541*418b791dSBob Badour Description:
1542*418b791dSBob Badour The std_cleanpath() removes double slashes, ".", and ".." from
1543*418b791dSBob Badour slash-delimited paths,. It operates in-place.
1544*418b791dSBob Badour
1545*418b791dSBob Badour Prototype:
1546*418b791dSBob Badour
1547*418b791dSBob Badour char *std_cleanpath(char *pszPath);
1548*418b791dSBob Badour
1549*418b791dSBob Badour Parameters:
1550*418b791dSBob Badour pszPath[in/out]: path to "clean"
1551*418b791dSBob Badour
1552*418b791dSBob Badour Return Value:
1553*418b791dSBob Badour pszPath
1554*418b791dSBob Badour
1555*418b791dSBob Badour Comments:
1556*418b791dSBob Badour Passing an "fs:/" path to this function may produce undesirable
1557*418b791dSBob Badour results. This function assumes '/' is the root.
1558*418b791dSBob Badour
1559*418b791dSBob Badour Examples:
1560*418b791dSBob Badour pszPath std_cleanpath()
1561*418b791dSBob Badour "", "",
1562*418b791dSBob Badour "/", "/",
1563*418b791dSBob Badour
1564*418b791dSBob Badour // here"s, mostly alone
1565*418b791dSBob Badour "./", "/",
1566*418b791dSBob Badour "/.", "/",
1567*418b791dSBob Badour "/./", "/",
1568*418b791dSBob Badour
1569*418b791dSBob Badour // "up"s, mostly alone
1570*418b791dSBob Badour "..", "",
1571*418b791dSBob Badour "/..", "/",
1572*418b791dSBob Badour "../", "/",
1573*418b791dSBob Badour "/../", "/",
1574*418b791dSBob Badour
1575*418b791dSBob Badour // fun with x
1576*418b791dSBob Badour "x/.", "x",
1577*418b791dSBob Badour "x/./", "x/",
1578*418b791dSBob Badour "x/..", "",
1579*418b791dSBob Badour "/x/..", "/",
1580*418b791dSBob Badour "x/../", "/",
1581*418b791dSBob Badour "/x/../", "/",
1582*418b791dSBob Badour "/x/../..", "/",
1583*418b791dSBob Badour "x/../..", "",
1584*418b791dSBob Badour "x/../../", "/",
1585*418b791dSBob Badour "x/./../", "/",
1586*418b791dSBob Badour "x/././", "x/",
1587*418b791dSBob Badour "x/.././", "/",
1588*418b791dSBob Badour "x/../.", "",
1589*418b791dSBob Badour "x/./..", "",
1590*418b791dSBob Badour "../x", "/x",
1591*418b791dSBob Badour "../../x", "/x",
1592*418b791dSBob Badour "/../x", "/x",
1593*418b791dSBob Badour "./../x", "/x",
1594*418b791dSBob Badour
1595*418b791dSBob Badour // double slashes
1596*418b791dSBob Badour "//", "/",
1597*418b791dSBob Badour "///", "/",
1598*418b791dSBob Badour "////", "/",
1599*418b791dSBob Badour "x//x", "x/x",
1600*418b791dSBob Badour
1601*418b791dSBob Badour
1602*418b791dSBob Badour Side Effects:
1603*418b791dSBob Badour None
1604*418b791dSBob Badour
1605*418b791dSBob Badour See Also:
1606*418b791dSBob Badour None
1607*418b791dSBob Badour
1608*418b791dSBob Badour
1609*418b791dSBob Badour =======================================================================
1610*418b791dSBob Badour
1611*418b791dSBob Badour std_basename()
1612*418b791dSBob Badour
1613*418b791dSBob Badour Description:
1614*418b791dSBob Badour The std_basename() returns the filename part of a string,
1615*418b791dSBob Badour assuming '/' delimited filenames.
1616*418b791dSBob Badour
1617*418b791dSBob Badour Prototype:
1618*418b791dSBob Badour
1619*418b791dSBob Badour char *std_basename(const char *cpszPath);
1620*418b791dSBob Badour
1621*418b791dSBob Badour Parameters:
1622*418b791dSBob Badour cpszPath: path of interest
1623*418b791dSBob Badour
1624*418b791dSBob Badour Return Value:
1625*418b791dSBob Badour pointer into cpszPath that denotes part of the string immediately
1626*418b791dSBob Badour following the last '/'
1627*418b791dSBob Badour
1628*418b791dSBob Badour Examples:
1629*418b791dSBob Badour cpszPath std_basename()
1630*418b791dSBob Badour "" ""
1631*418b791dSBob Badour "/" ""
1632*418b791dSBob Badour "x" "x"
1633*418b791dSBob Badour "/x" "x"
1634*418b791dSBob Badour "y/x" "x"
1635*418b791dSBob Badour "/y/x" "x"
1636*418b791dSBob Badour
1637*418b791dSBob Badour See Also:
1638*418b791dSBob Badour None
1639*418b791dSBob Badour
1640*418b791dSBob Badour =======================================================================
1641*418b791dSBob Badour
1642*418b791dSBob Badour std_rand_next()
1643*418b791dSBob Badour
1644*418b791dSBob Badour Description:
1645*418b791dSBob Badour The std_rand_next() generates pseudo-random bytes.
1646*418b791dSBob Badour
1647*418b791dSBob Badour Prototype:
1648*418b791dSBob Badour
1649*418b791dSBob Badour unsigned std_rand_next(unsigned uRand);
1650*418b791dSBob Badour
1651*418b791dSBob Badour Parameters:
1652*418b791dSBob Badour uRand: a seed for the pseudo-random generator
1653*418b791dSBob Badour
1654*418b791dSBob Badour Return Value:
1655*418b791dSBob Badour the next value in the generator from uRand
1656*418b791dSBob Badour
1657*418b791dSBob Badour Comments:
1658*418b791dSBob Badour for best results, this function should be called with its last
1659*418b791dSBob Badour generated output.
1660*418b791dSBob Badour
1661*418b791dSBob Badour This is an example of code to generate 256 bytes of pseudo-random data.
1662*418b791dSBob Badour
1663*418b791dSBob Badour This is not crypto quality and should not be used for key generation
1664*418b791dSBob Badour and the like.
1665*418b791dSBob Badour
1666*418b791dSBob Badour Example:
1667*418b791dSBob Badour {
1668*418b791dSBob Badour unsigned rand_buf[256/sizeof(unsigned)];
1669*418b791dSBob Badour int i;
1670*418b791dSBob Badour unsigned uLast = std_rand_next(uCurrentTime);
1671*418b791dSBob Badour for (i = 0; i < STD_ARRAY_SIZE(rand_buf); i++) {
1672*418b791dSBob Badour rand_buf[i] = (uLast = std_rand_next(uLast));
1673*418b791dSBob Badour }
1674*418b791dSBob Badour }
1675*418b791dSBob Badour
1676*418b791dSBob Badour See Also:
1677*418b791dSBob Badour std_rand()
1678*418b791dSBob Badour
1679*418b791dSBob Badour =======================================================================
1680*418b791dSBob Badour
1681*418b791dSBob Badour std_rand()
1682*418b791dSBob Badour
1683*418b791dSBob Badour Description:
1684*418b791dSBob Badour The std_rand() functions generates pseudo-random bytes and places it
1685*418b791dSBob Badour in an output buffer of specified size.
1686*418b791dSBob Badour
1687*418b791dSBob Badour Prototype:
1688*418b791dSBob Badour
1689*418b791dSBob Badour uint32 std_rand(uint32 uSeed, byte* pDest, int nSize);
1690*418b791dSBob Badour
1691*418b791dSBob Badour Parameters:
1692*418b791dSBob Badour uSeed: A seed for the pseudo-random generator
1693*418b791dSBob Badour pDest: The output buffer where the random bytes are placed.
1694*418b791dSBob Badour nSize: The size in bytes of pDest.
1695*418b791dSBob Badour
1696*418b791dSBob Badour Return Value:
1697*418b791dSBob Badour The new seed value that can be used in a subsequent call to
1698*418b791dSBob Badour std_rand().
1699*418b791dSBob Badour
1700*418b791dSBob Badour Comments:
1701*418b791dSBob Badour
1702*418b791dSBob Badour std_rand() is a linear congruent psuedo-random number generator that
1703*418b791dSBob Badour is seeded using the input seed. This makes the ouput predictable if
1704*418b791dSBob Badour you can determine (or influence) the seed value used. Furthermore,
1705*418b791dSBob Badour the random sequence of bytes generated by two different calls to this
1706*418b791dSBob Badour function will be identical if both the calls use the same seed value.
1707*418b791dSBob Badour
1708*418b791dSBob Badour This is not crypto quality and should not be used for key generation
1709*418b791dSBob Badour and other cryptographic uses.
1710*418b791dSBob Badour
1711*418b791dSBob Badour See Also:
1712*418b791dSBob Badour std_rand_next()
1713*418b791dSBob Badour
1714*418b791dSBob Badour =======================================================================
1715*418b791dSBob Badour
1716*418b791dSBob Badour std_CopyLE()
1717*418b791dSBob Badour
1718*418b791dSBob Badour Description:
1719*418b791dSBob Badour
1720*418b791dSBob Badour The std_CopyLE() function copies data while translating numeric values
1721*418b791dSBob Badour between host byte ordering and "little endian" byte ordering.
1722*418b791dSBob Badour
1723*418b791dSBob Badour pvDest and pvSrc are NOT required to be 16 or 32-bit word aligned.
1724*418b791dSBob Badour
1725*418b791dSBob Badour Behavior is undefined when the destination and source arrays overlap,
1726*418b791dSBob Badour except in the special case where pvDest and pvSrc are equal. In that case,
1727*418b791dSBob Badour std_CopyLE() modifies the buffer in-place.
1728*418b791dSBob Badour
1729*418b791dSBob Badour When the target byte ordering (little endian) matches the host byte
1730*418b791dSBob Badour ordering, in-place translations reduce to a no-op, and copies are
1731*418b791dSBob Badour delegated directly to std_memmove().
1732*418b791dSBob Badour
1733*418b791dSBob Badour
1734*418b791dSBob Badour Prototype:
1735*418b791dSBob Badour int std_CopyLE(void *pvDest, int nDestSize,
1736*418b791dSBob Badour const void *pvSrc, int nSrcSize,
1737*418b791dSBob Badour const char *pszFields);
1738*418b791dSBob Badour
1739*418b791dSBob Badour Parameters:
1740*418b791dSBob Badour pvDest: Pointer to destination buffer.
1741*418b791dSBob Badour nDestSize: Size of the destination buffer.
1742*418b791dSBob Badour pvSrc: Pointer to buffer containing source data.
1743*418b791dSBob Badour nSrcSize: Size of source data.
1744*418b791dSBob Badour pszFields: Description of the fields that comprise the source data.
1745*418b791dSBob Badour
1746*418b791dSBob Badour Each field size is given by a positive decimal integer or one of
1747*418b791dSBob Badour the following characters: "S", "L", "Q", or "*". The letters
1748*418b791dSBob Badour denote fields that should be converted to the desired byte
1749*418b791dSBob Badour ordering:
1750*418b791dSBob Badour
1751*418b791dSBob Badour ===pre>
1752*418b791dSBob Badour S : a 2 byte (16 bit) value.
1753*418b791dSBob Badour L : a 4 byte (32 bit) value.
1754*418b791dSBob Badour Q : a 8 byte (64 bit) value.
1755*418b791dSBob Badour ===/pre>
1756*418b791dSBob Badour
1757*418b791dSBob Badour An integer gives a number of bytes and "*" represents the
1758*418b791dSBob Badour remainder of the pvSrc[] buffer. No reordering is performed on
1759*418b791dSBob Badour data in these fields.
1760*418b791dSBob Badour
1761*418b791dSBob Badour Comparisons are case-sensitive. Behavior is undefined when
1762*418b791dSBob Badour other characters are supplied in pszFields.
1763*418b791dSBob Badour
1764*418b791dSBob Badour For example: "L12S*" would be appropriate to copy a structure
1765*418b791dSBob Badour containing a uint32 followed by a 12 byte character array,
1766*418b791dSBob Badour followed by a uint16, followed by an arbitrary amount of
1767*418b791dSBob Badour character data.
1768*418b791dSBob Badour
1769*418b791dSBob Badour If nSrcSize is greater than the structure size (total of all the
1770*418b791dSBob Badour sizes in pszFields[]) then pvSrc[] is treated as an array of
1771*418b791dSBob Badour structures, each of which is described by pszFields.
1772*418b791dSBob Badour
1773*418b791dSBob Badour Return Value:
1774*418b791dSBob Badour
1775*418b791dSBob Badour The number of bytes actually copied or translated in-place. This will be
1776*418b791dSBob Badour the smaller of nDestSize and nSrcSize, or zero if one of them are negative.
1777*418b791dSBob Badour
1778*418b791dSBob Badour
1779*418b791dSBob Badour =======================================================================
1780*418b791dSBob Badour
1781*418b791dSBob Badour std_CopyBE()
1782*418b791dSBob Badour
1783*418b791dSBob Badour Description:
1784*418b791dSBob Badour
1785*418b791dSBob Badour The std_CopyBE() function has the same semantics as std_CopyLE() except it
1786*418b791dSBob Badour copies between host byte ordering and big-endian ("network") byte order.
1787*418b791dSBob Badour
1788*418b791dSBob Badour See std_CopyLE() for more details.
1789*418b791dSBob Badour
1790*418b791dSBob Badour
1791*418b791dSBob Badour Prototype:
1792*418b791dSBob Badour void *std_CopyBE(void *pvDest, const void *pvSrc,
1793*418b791dSBob Badour int cbDest, int nItems, const char *pszFields);
1794*418b791dSBob Badour
1795*418b791dSBob Badour Parameters:
1796*418b791dSBob Badour pvDest: Pointer to destination buffer.
1797*418b791dSBob Badour nDestSize: Size of the destination buffer.
1798*418b791dSBob Badour pvSrc: Pointer to buffer containing source data.
1799*418b791dSBob Badour nSrcSize: Size of source data.
1800*418b791dSBob Badour pszFields: Description of the fields that comprise the source data,
1801*418b791dSBob Badour as defined in std_CopyLE.
1802*418b791dSBob Badour
1803*418b791dSBob Badour Return Value:
1804*418b791dSBob Badour
1805*418b791dSBob Badour The number of bytes actually copied or translated in-place. This will be
1806*418b791dSBob Badour the smaller of nDestSize and nSrcSize, or zero if one of them are negative.
1807*418b791dSBob Badour
1808*418b791dSBob Badour =======================================================================
1809*418b791dSBob Badour
1810*418b791dSBob Badour std_swapl()
1811*418b791dSBob Badour
1812*418b791dSBob Badour Description:
1813*418b791dSBob Badour The std_swapl() changes endianness of an unsigned long.
1814*418b791dSBob Badour
1815*418b791dSBob Badour Prototype:
1816*418b791dSBob Badour
1817*418b791dSBob Badour unsigned long std_swapl(unsigned long ul)
1818*418b791dSBob Badour
1819*418b791dSBob Badour Parameters:
1820*418b791dSBob Badour ul: input unsigned long
1821*418b791dSBob Badour
1822*418b791dSBob Badour Return Value:
1823*418b791dSBob Badour ul, reversed in byte-ordering
1824*418b791dSBob Badour
1825*418b791dSBob Badour =======================================================================
1826*418b791dSBob Badour
1827*418b791dSBob Badour std_swaps()
1828*418b791dSBob Badour
1829*418b791dSBob Badour Description:
1830*418b791dSBob Badour The std_swaps() changes endianness of an unsigned short.
1831*418b791dSBob Badour
1832*418b791dSBob Badour Prototype:
1833*418b791dSBob Badour
1834*418b791dSBob Badour unsigned short std_swaps(unsigned short us)
1835*418b791dSBob Badour
1836*418b791dSBob Badour Parameters:
1837*418b791dSBob Badour us: input unsigned short
1838*418b791dSBob Badour
1839*418b791dSBob Badour Return Value:
1840*418b791dSBob Badour us, reversed in byte-ordering
1841*418b791dSBob Badour
1842*418b791dSBob Badour =======================================================================
1843*418b791dSBob Badour
1844*418b791dSBob Badour std_letohs()
1845*418b791dSBob Badour
1846*418b791dSBob Badour Description:
1847*418b791dSBob Badour The std_letohs() changes a short from little-endian to host byte order.
1848*418b791dSBob Badour
1849*418b791dSBob Badour Prototype:
1850*418b791dSBob Badour
1851*418b791dSBob Badour unsigned short std_letohs(unsigned short us)
1852*418b791dSBob Badour
1853*418b791dSBob Badour Parameters:
1854*418b791dSBob Badour us: short to convert
1855*418b791dSBob Badour
1856*418b791dSBob Badour Return Value:
1857*418b791dSBob Badour us converted from little-endian to host byte order. If the
1858*418b791dSBob Badour host is little endian, just returns us
1859*418b791dSBob Badour
1860*418b791dSBob Badour =======================================================================
1861*418b791dSBob Badour
1862*418b791dSBob Badour std_htoles()
1863*418b791dSBob Badour
1864*418b791dSBob Badour Description:
1865*418b791dSBob Badour The std_htoles() converts a short from host byte-order to little-endian.
1866*418b791dSBob Badour
1867*418b791dSBob Badour Prototype:
1868*418b791dSBob Badour
1869*418b791dSBob Badour unsigned short std_htoles(unsigned short us)
1870*418b791dSBob Badour
1871*418b791dSBob Badour Parameters:
1872*418b791dSBob Badour us: short to convert
1873*418b791dSBob Badour
1874*418b791dSBob Badour Return Value:
1875*418b791dSBob Badour us converted from host byte order to little-endian. If the
1876*418b791dSBob Badour host is little endian, just returns us
1877*418b791dSBob Badour
1878*418b791dSBob Badour =======================================================================
1879*418b791dSBob Badour
1880*418b791dSBob Badour std_letohl()
1881*418b791dSBob Badour
1882*418b791dSBob Badour Description:
1883*418b791dSBob Badour The std_letohl() changes a long from little-endian to host byte order.
1884*418b791dSBob Badour
1885*418b791dSBob Badour Prototype:
1886*418b791dSBob Badour
1887*418b791dSBob Badour unsigned long std_letohl(unsigned long ul)
1888*418b791dSBob Badour
1889*418b791dSBob Badour Parameters:
1890*418b791dSBob Badour ul: long to convert
1891*418b791dSBob Badour
1892*418b791dSBob Badour Return Value:
1893*418b791dSBob Badour ul converted from little-endian to host byte order. If the
1894*418b791dSBob Badour host is little endian, just returns ul
1895*418b791dSBob Badour
1896*418b791dSBob Badour =======================================================================
1897*418b791dSBob Badour
1898*418b791dSBob Badour std_htolel()
1899*418b791dSBob Badour
1900*418b791dSBob Badour Description:
1901*418b791dSBob Badour The std_htolel() converts a long from host byte-order to little-endian.
1902*418b791dSBob Badour
1903*418b791dSBob Badour Prototype:
1904*418b791dSBob Badour
1905*418b791dSBob Badour unsigned long std_htolel(unsigned long ul)
1906*418b791dSBob Badour
1907*418b791dSBob Badour Parameters:
1908*418b791dSBob Badour ul: long to convert
1909*418b791dSBob Badour
1910*418b791dSBob Badour Return Value:
1911*418b791dSBob Badour ul converted from host byte order to little-endian. If the
1912*418b791dSBob Badour host is little endian, just returns ul.
1913*418b791dSBob Badour
1914*418b791dSBob Badour
1915*418b791dSBob Badour =======================================================================
1916*418b791dSBob Badour
1917*418b791dSBob Badour std_ntohs()
1918*418b791dSBob Badour
1919*418b791dSBob Badour Description:
1920*418b791dSBob Badour The std_ntohs() changes a short from big-endian to host byte order.
1921*418b791dSBob Badour
1922*418b791dSBob Badour Prototype:
1923*418b791dSBob Badour
1924*418b791dSBob Badour unsigned short std_ntohs(unsigned short us)
1925*418b791dSBob Badour
1926*418b791dSBob Badour Parameters:
1927*418b791dSBob Badour us: short to convert
1928*418b791dSBob Badour
1929*418b791dSBob Badour Return Value:
1930*418b791dSBob Badour us converted from big-endian to host byte order. If the
1931*418b791dSBob Badour host is big endian, just returns us.
1932*418b791dSBob Badour
1933*418b791dSBob Badour =======================================================================
1934*418b791dSBob Badour
1935*418b791dSBob Badour std_htons()
1936*418b791dSBob Badour
1937*418b791dSBob Badour Description:
1938*418b791dSBob Badour The std_htons() converts a short from host byte-order to big-endian.
1939*418b791dSBob Badour
1940*418b791dSBob Badour Prototype:
1941*418b791dSBob Badour
1942*418b791dSBob Badour unsigned short std_htons(unsigned short us)
1943*418b791dSBob Badour
1944*418b791dSBob Badour Parameters:
1945*418b791dSBob Badour us: short to convert
1946*418b791dSBob Badour
1947*418b791dSBob Badour Return Value:
1948*418b791dSBob Badour us converted from host byte order to big-endian. If the
1949*418b791dSBob Badour host is big endian, just returns us.
1950*418b791dSBob Badour
1951*418b791dSBob Badour =======================================================================
1952*418b791dSBob Badour
1953*418b791dSBob Badour std_ntohl()
1954*418b791dSBob Badour
1955*418b791dSBob Badour Description:
1956*418b791dSBob Badour The std_ntohl() changes a long from big-endian to host byte order.
1957*418b791dSBob Badour
1958*418b791dSBob Badour Prototype:
1959*418b791dSBob Badour
1960*418b791dSBob Badour unsigned long std_ntohl(unsigned long ul)
1961*418b791dSBob Badour
1962*418b791dSBob Badour Parameters:
1963*418b791dSBob Badour ul: long to convert
1964*418b791dSBob Badour
1965*418b791dSBob Badour Return Value:
1966*418b791dSBob Badour ul converted from big-endian to host byte order. If the
1967*418b791dSBob Badour host is big endian, just returns ul.
1968*418b791dSBob Badour
1969*418b791dSBob Badour =======================================================================
1970*418b791dSBob Badour
1971*418b791dSBob Badour std_htonl()
1972*418b791dSBob Badour
1973*418b791dSBob Badour Description:
1974*418b791dSBob Badour The std_htonl() converts a long from host byte-order to big-endian.
1975*418b791dSBob Badour
1976*418b791dSBob Badour Prototype:
1977*418b791dSBob Badour
1978*418b791dSBob Badour unsigned long std_htonl(unsigned long ul)
1979*418b791dSBob Badour
1980*418b791dSBob Badour Parameters:
1981*418b791dSBob Badour ul: long to convert
1982*418b791dSBob Badour
1983*418b791dSBob Badour Return Value:
1984*418b791dSBob Badour ul converted from host byte order to big-endian. If the
1985*418b791dSBob Badour host is big endian, just returns ul.
1986*418b791dSBob Badour
1987*418b791dSBob Badour
1988*418b791dSBob Badour =======================================================================
1989*418b791dSBob Badour
1990*418b791dSBob Badour std_strlprintf()
1991*418b791dSBob Badour
1992*418b791dSBob Badour Description:
1993*418b791dSBob Badour
1994*418b791dSBob Badour The functions std_strlprintf() and std_vstrlprintf() write formatted
1995*418b791dSBob Badour output to a string. These functions guarantee NUL-termination of
1996*418b791dSBob Badour the output buffer when its size is greater than zero.
1997*418b791dSBob Badour
1998*418b791dSBob Badour A format string is copied to the output buffer, except for conversion
1999*418b791dSBob Badour specifiers contained within the format string. Conversion specifiers
2000*418b791dSBob Badour begin with a "%" and specify some action that consumes an argument from
2001*418b791dSBob Badour the argument list.
2002*418b791dSBob Badour
2003*418b791dSBob Badour Conversion specifiers have the following form:
2004*418b791dSBob Badour ===pre>
2005*418b791dSBob Badour %[FLAGS] [WIDTH] [.PRECISION] [TYPE] CONV
2006*418b791dSBob Badour ===/pre>
2007*418b791dSBob Badour
2008*418b791dSBob Badour CONV is the only required field. It is always a single character,
2009*418b791dSBob Badour and determines the action to be taken. Supported values are:
2010*418b791dSBob Badour
2011*418b791dSBob Badour ===pre>
2012*418b791dSBob Badour CONV | Description
2013*418b791dSBob Badour ======|=======================================================
2014*418b791dSBob Badour c | Output a single character.
2015*418b791dSBob Badour |
2016*418b791dSBob Badour s | Output a NUL-terminated single-byte character string.
2017*418b791dSBob Badour |
2018*418b791dSBob Badour d, i | Ouptut a signed decimal integer.
2019*418b791dSBob Badour |
2020*418b791dSBob Badour u | Output an unsigned decimal integer.
2021*418b791dSBob Badour |
2022*418b791dSBob Badour o | Output an unsigned octal integer.
2023*418b791dSBob Badour |
2024*418b791dSBob Badour x | Output an unsigned hexadecimal integer, using
2025*418b791dSBob Badour | lower case digits.
2026*418b791dSBob Badour |
2027*418b791dSBob Badour X | Output an unsigned hexadecimal integer, using
2028*418b791dSBob Badour | upper case digits.
2029*418b791dSBob Badour |
2030*418b791dSBob Badour p | Output a pointer value as eight hexadecimal digits,
2031*418b791dSBob Badour | using upper case digits.
2032*418b791dSBob Badour ===/pre>
2033*418b791dSBob Badour
2034*418b791dSBob Badour The next argument from the argument list supplies the value to be
2035*418b791dSBob Badour formatted and output.
2036*418b791dSBob Badour
2037*418b791dSBob Badour FLAGS, WIDTH, and PRECISION can modify the formatting of the value.
2038*418b791dSBob Badour
2039*418b791dSBob Badour FLAGS consists of one or more of the following characters:
2040*418b791dSBob Badour
2041*418b791dSBob Badour ===pre>
2042*418b791dSBob Badour Flag | Meaning
2043*418b791dSBob Badour =====|=================================================================
2044*418b791dSBob Badour + | Prefix positive numbers with "+" (%d and %i only).
2045*418b791dSBob Badour -----|-----------------------------------------------------------------
2046*418b791dSBob Badour - | When padding to meet WIDTH, pad on the right.
2047*418b791dSBob Badour -----|-----------------------------------------------------------------
2048*418b791dSBob Badour 0 | Pad with '0' characters when padding on the left to meet WIDTH.
2049*418b791dSBob Badour -----|-----------------------------------------------------------------
2050*418b791dSBob Badour blank| Prefix positive numbers with " " (%d and %i only).
2051*418b791dSBob Badour space|
2052*418b791dSBob Badour -----|-----------------------------------------------------------------
2053*418b791dSBob Badour # | With %x or %X: prefixes non-zero values with "0x"/"0X".
2054*418b791dSBob Badour | With %o, ensure the value begins with "0" (increasing PRECISION
2055*418b791dSBob Badour | if necessary).
2056*418b791dSBob Badour | Ignored for all other CONV specifiers.
2057*418b791dSBob Badour -----|-----------------------------------------------------------------
2058*418b791dSBob Badour ===/pre>
2059*418b791dSBob Badour
2060*418b791dSBob Badour WIDTH is an unsigned decimal integer or the character "*".
2061*418b791dSBob Badour
2062*418b791dSBob Badour WIDTH gives the minimum number of characters to be written. The
2063*418b791dSBob Badour formatted value will be padded with spaces until the minimum size is
2064*418b791dSBob Badour met; it never causes a value to be truncated The sign of the WIDTH
2065*418b791dSBob Badour integer selects between left and right padding. Padding will be on
2066*418b791dSBob Badour the left unless the "-" flag is specified.
2067*418b791dSBob Badour
2068*418b791dSBob Badour When "*" is used, an 'int' argument is consumed from the argument
2069*418b791dSBob Badour list and used as the WIDTH. A negative argument specifies padding on
2070*418b791dSBob Badour the right, and its absolute value gives the amount of padding.
2071*418b791dSBob Badour
2072*418b791dSBob Badour If the "0" flags is specified, any padding on the left will consist
2073*418b791dSBob Badour of "0" characters. An exception to this rule is that the "0" flag is
2074*418b791dSBob Badour ignored when precision is specified for a numeric value.
2075*418b791dSBob Badour
2076*418b791dSBob Badour PRECISION is a non-negative decimal integer or "*" preceded by ".".
2077*418b791dSBob Badour
2078*418b791dSBob Badour When PRECISION accompanies any of the numeric conversions, it
2079*418b791dSBob Badour specifies the minimum number of digits to output. Values are padded
2080*418b791dSBob Badour on the left with '0' to meet the specified size. PRECISION defaults
2081*418b791dSBob Badour to 1 for numbers.
2082*418b791dSBob Badour
2083*418b791dSBob Badour When PRECISION accompanies other conversions, it specifies the
2084*418b791dSBob Badour maximum number of characters from the value to output. The value
2085*418b791dSBob Badour will be truncated to ensure that at most PRECISION characters are
2086*418b791dSBob Badour output.
2087*418b791dSBob Badour
2088*418b791dSBob Badour TYPE provides information about the type of arguments. This is used
2089*418b791dSBob Badour to determine the size of integer arguments. Values larger than 'int'
2090*418b791dSBob Badour can be properly obtained from the argument list. Their behavior
2091*418b791dSBob Badour should be considered undefined for CONV operations other than integer
2092*418b791dSBob Badour formatting.
2093*418b791dSBob Badour
2094*418b791dSBob Badour ===pre>
2095*418b791dSBob Badour TYPE | Meaning
2096*418b791dSBob Badour =======|=====================
2097*418b791dSBob Badour hh | sizeof(char)
2098*418b791dSBob Badour -------|---------------------
2099*418b791dSBob Badour h | sizeof(short)
2100*418b791dSBob Badour -------|---------------------
2101*418b791dSBob Badour l | sizeof(long)
2102*418b791dSBob Badour -------|---------------------
2103*418b791dSBob Badour L, ll | sizeof(long long)
2104*418b791dSBob Badour -------|---------------------
2105*418b791dSBob Badour j | sizeof(int64)
2106*418b791dSBob Badour -------|---------------------
2107*418b791dSBob Badour z | sizeof(size_t)
2108*418b791dSBob Badour -------|---------------------
2109*418b791dSBob Badour ===/pre>
2110*418b791dSBob Badour
2111*418b791dSBob Badour For 64-bit integers, "ll" may be the most widely-supported type
2112*418b791dSBob Badour specifier in other printf implementation, but "j" has been introduced
2113*418b791dSBob Badour in ISO C99. This implementation supports both.
2114*418b791dSBob Badour
2115*418b791dSBob Badour Note that arguments to variadic functions are promoted to 'int' when
2116*418b791dSBob Badour smaller than 'int', so 'h' and 'hh' have no observable effect.
2117*418b791dSBob Badour Static analysis tools that understand standard format string syntax
2118*418b791dSBob Badour may use this information for other purposes.
2119*418b791dSBob Badour
2120*418b791dSBob Badour Prototype:
2121*418b791dSBob Badour
2122*418b791dSBob Badour int std_strlprintf(char *pszDest, int nDestSize,
2123*418b791dSBob Badour const char *pszFmt, ...);
2124*418b791dSBob Badour Parameters:
2125*418b791dSBob Badour pszDest [out]: output buffer, where output will be placed
2126*418b791dSBob Badour nDestSize: size of pszDest in bytes
2127*418b791dSBob Badour pszFmt: format string
2128*418b791dSBob Badour
2129*418b791dSBob Badour Return Value:
2130*418b791dSBob Badour
2131*418b791dSBob Badour The size required to hold the entire untruncated output, NOT
2132*418b791dSBob Badour including NUL-termination.
2133*418b791dSBob Badour
2134*418b791dSBob Badour Comments:
2135*418b791dSBob Badour
2136*418b791dSBob Badour Notable omissions from std_strlprintf() are lack of support for
2137*418b791dSBob Badour floating point and lack of support for "%n".
2138*418b791dSBob Badour
2139*418b791dSBob Badour Side Effects:
2140*418b791dSBob Badour None
2141*418b791dSBob Badour
2142*418b791dSBob Badour See Also:
2143*418b791dSBob Badour None
2144*418b791dSBob Badour
2145*418b791dSBob Badour =======================================================================
2146*418b791dSBob Badour
2147*418b791dSBob Badour std_vstrlprintf()
2148*418b791dSBob Badour
2149*418b791dSBob Badour Description:
2150*418b791dSBob Badour
2151*418b791dSBob Badour The std_vstrlprintf() is documented with std_strlprintf(), it's the
2152*418b791dSBob Badour vector form of std_strlprintf(). See std_strlprintf() for a
2153*418b791dSBob Badour more complete description.
2154*418b791dSBob Badour
2155*418b791dSBob Badour Prototype:
2156*418b791dSBob Badour int std_vstrlprintf(char *pszDest, int nDestSize,
2157*418b791dSBob Badour const char *pszFmt, AEEVaList args);
2158*418b791dSBob Badour
2159*418b791dSBob Badour Parameters:
2160*418b791dSBob Badour pszDest [out]: output buffer, where output will be placed
2161*418b791dSBob Badour nDestSize: size of pszDest in bytes
2162*418b791dSBob Badour pszFmt: format string
2163*418b791dSBob Badour args: arguments
2164*418b791dSBob Badour
2165*418b791dSBob Badour
2166*418b791dSBob Badour =======================================================================
2167*418b791dSBob Badour
2168*418b791dSBob Badour std_snprintf()
2169*418b791dSBob Badour
2170*418b791dSBob Badour Description:
2171*418b791dSBob Badour
2172*418b791dSBob Badour The functions std_snprintf() and std_vsnprintf() are similar to
2173*418b791dSBob Badour std_strlprintf and std_vstrlprintf that write formatted output to a
2174*418b791dSBob Badour string. Unlike std_strlprintf, std_snprintf also support the floating
2175*418b791dSBob Badour point conversion specifiers. These functions guarantee NUL-termination
2176*418b791dSBob Badour of the output buffer when its size is greater than zero.
2177*418b791dSBob Badour
2178*418b791dSBob Badour A format string is copied to the output buffer, except for conversion
2179*418b791dSBob Badour specifiers contained within the format string. Conversion specifiers
2180*418b791dSBob Badour begin with a "%" and specify some action that consumes an argument from
2181*418b791dSBob Badour the argument list.
2182*418b791dSBob Badour
2183*418b791dSBob Badour Conversion specifiers have the following form:
2184*418b791dSBob Badour ===pre>
2185*418b791dSBob Badour %[FLAGS] [WIDTH] [.PRECISION] [TYPE] CONV
2186*418b791dSBob Badour ===/pre>
2187*418b791dSBob Badour
2188*418b791dSBob Badour CONV is the only required field. It is always a single character,
2189*418b791dSBob Badour and determines the action to be taken. For a detailed description of
2190*418b791dSBob Badour conversion sepcifiers, please refer to the documentation of
2191*418b791dSBob Badour std_strlprintf(). Here. we only provide description of these fields
2192*418b791dSBob Badour as it applies to the additional CONV values supported by
2193*418b791dSBob Badour std_snprintf().
2194*418b791dSBob Badour
2195*418b791dSBob Badour In addition to the values for CONV supported by std_strlprintf, this
2196*418b791dSBob Badour function supports the following values:
2197*418b791dSBob Badour
2198*418b791dSBob Badour ===pre>
2199*418b791dSBob Badour CONV | Description
2200*418b791dSBob Badour ======|=======================================================
2201*418b791dSBob Badour e, E | Outputs a double value representing a floating point
2202*418b791dSBob Badour | number in the style [-]d.ddd e�dd, where there is one
2203*418b791dSBob Badour | digit (which is nonzero if the argument is nonzero)
2204*418b791dSBob Badour | before the decimal-point character and the number of
2205*418b791dSBob Badour | digits after it is equal to the precision. If the
2206*418b791dSBob Badour | precision is missing, it is taken as 6. If the precision
2207*418b791dSBob Badour | is zero and the # flag is not specified, no decimal-point
2208*418b791dSBob Badour | character appears. The value is rounded to the appropriate
2209*418b791dSBob Badour | number of digits. The E conversion specifier produces a
2210*418b791dSBob Badour | number with E instead of e introducing the exponent. The
2211*418b791dSBob Badour | exponent always contains at least two digits, and only as
2212*418b791dSBob Badour | many more digits as necessary to represent the exponent.
2213*418b791dSBob Badour | If the value is zero, the exponent is zero.
2214*418b791dSBob Badour |
2215*418b791dSBob Badour f, F | Outputs a double value representing a floating point
2216*418b791dSBob Badour | number in the style [-]ddd.ddd, where the number of
2217*418b791dSBob Badour | digits after the decimal-point character is equal to the
2218*418b791dSBob Badour | precision specification. If the precision is missing, it
2219*418b791dSBob Badour | is taken as 6. If the precision is zero and the # flag is
2220*418b791dSBob Badour | not specified, no decimal-point character appears. If a
2221*418b791dSBob Badour | decimal-point character appears, at least one digit
2222*418b791dSBob Badour | appears before it. The value is rounded to the appropriate
2223*418b791dSBob Badour | number of digits.
2224*418b791dSBob Badour |
2225*418b791dSBob Badour g, G | Outputs a double value representing a floating point
2226*418b791dSBob Badour | number in the style f or e (or in style F or E in the case
2227*418b791dSBob Badour | of a G conversion specifier), with the precision specifying
2228*418b791dSBob Badour | the number of significant digits. If the precision is zero,
2229*418b791dSBob Badour | it is taken as 1. The style used depends on the value
2230*418b791dSBob Badour | converted. Style e (or E) is used only if the exponent
2231*418b791dSBob Badour | resulting from such a conversion is less than -4 or greater
2232*418b791dSBob Badour | than or equal to the precision. Trailing zeros are removed
2233*418b791dSBob Badour | from the fractional portion of the result unless the # flag
2234*418b791dSBob Badour | is specified; a decimal-point character appears only if it
2235*418b791dSBob Badour | is followed by a digit.
2236*418b791dSBob Badour |
2237*418b791dSBob Badour a, A | Outputs a double value representing a floating point
2238*418b791dSBob Badour | number in the style [-]0xh.hhhh p�d, where there is one
2239*418b791dSBob Badour | non-zero hexadecimal digit before the decimal-point
2240*418b791dSBob Badour | character and the number of hexadecimal digits after it is
2241*418b791dSBob Badour | equal to the precision. If the precision is missing then
2242*418b791dSBob Badour | the precision is assumed to be sufficient for an exact
2243*418b791dSBob Badour | representation of the value, except that trailing zeros
2244*418b791dSBob Badour | may be omitted. If the precision is zero and the # flag is
2245*418b791dSBob Badour | not specified, no decimal point character appears. The
2246*418b791dSBob Badour | letters 'abcdef' are used for '%a' conversion and the
2247*418b791dSBob Badour | letters ABCDEF for '%A' conversion. The '%A' conversion
2248*418b791dSBob Badour | specifier produces a number with 'X' and 'P' instead of 'x'
2249*418b791dSBob Badour | and 'p'. The exponent always contains at least one digit,
2250*418b791dSBob Badour | and only as many more digits as necessary to represent the
2251*418b791dSBob Badour | decimal exponent of 2. If the value is zero, the exponent
2252*418b791dSBob Badour | is zero.
2253*418b791dSBob Badour |
2254*418b791dSBob Badour ===/pre>
2255*418b791dSBob Badour
2256*418b791dSBob Badour For 'e', 'f', 'g' and 'a' convervsion specifiers, a double argument
2257*418b791dSBob Badour representing an infinity is converted in to the style '[-]inf' and
2258*418b791dSBob Badour a double argument representing a NaN is converted in to the stlye
2259*418b791dSBob Badour 'nan'. The 'E', 'F', 'G' and 'A' conversion specifiers result in
2260*418b791dSBob Badour 'INF' or 'NAN' instead of 'inf' or 'nan', respectively.
2261*418b791dSBob Badour
2262*418b791dSBob Badour Prototype:
2263*418b791dSBob Badour
2264*418b791dSBob Badour int std_snprintf(char *pszDest, int nDestSize,
2265*418b791dSBob Badour const char *pszFmt, ...);
2266*418b791dSBob Badour Parameters:
2267*418b791dSBob Badour pszDest [out]: output buffer, where output will be placed
2268*418b791dSBob Badour nDestSize: size of pszDest in bytes
2269*418b791dSBob Badour pszFmt: format string
2270*418b791dSBob Badour
2271*418b791dSBob Badour Return Value:
2272*418b791dSBob Badour
2273*418b791dSBob Badour The size required to hold the entire untruncated output, NOT
2274*418b791dSBob Badour including NUL-termination.
2275*418b791dSBob Badour
2276*418b791dSBob Badour Comments:
2277*418b791dSBob Badour
2278*418b791dSBob Badour Notable omissions from std_strlprintf() lack of support for "%n".
2279*418b791dSBob Badour
2280*418b791dSBob Badour Side Effects:
2281*418b791dSBob Badour None
2282*418b791dSBob Badour
2283*418b791dSBob Badour See Also:
2284*418b791dSBob Badour std_strlprintf()
2285*418b791dSBob Badour
2286*418b791dSBob Badour =======================================================================
2287*418b791dSBob Badour
2288*418b791dSBob Badour std_vsnprintf()
2289*418b791dSBob Badour
2290*418b791dSBob Badour Description:
2291*418b791dSBob Badour
2292*418b791dSBob Badour The std_vsnprintf() is documented with std_snprintf(), it's the
2293*418b791dSBob Badour vector form of std_snprintf(). See std_snprintf() for a more complete
2294*418b791dSBob Badour description.
2295*418b791dSBob Badour
2296*418b791dSBob Badour Prototype:
2297*418b791dSBob Badour int std_vsnprintf(char *pszDest, int nDestSize,
2298*418b791dSBob Badour const char *pszFmt, AEEVaList args);
2299*418b791dSBob Badour
2300*418b791dSBob Badour Parameters:
2301*418b791dSBob Badour pszDest [out]: output buffer, where output will be placed
2302*418b791dSBob Badour nDestSize: size of pszDest in bytes
2303*418b791dSBob Badour pszFmt: format string
2304*418b791dSBob Badour args: arguments
2305*418b791dSBob Badour
2306*418b791dSBob Badour
2307*418b791dSBob Badour =======================================================================
2308*418b791dSBob Badour
2309*418b791dSBob Badour std_scanul()
2310*418b791dSBob Badour
2311*418b791dSBob Badour Description:
2312*418b791dSBob Badour
2313*418b791dSBob Badour The std_scanul() converts an ASCII representation of a number to an unsigned
2314*418b791dSBob Badour long. It expects strings that match the following pattern:
2315*418b791dSBob Badour ===pre>
2316*418b791dSBob Badour spaces [+|-] digits
2317*418b791dSBob Badour ===/pre>
2318*418b791dSBob Badour
2319*418b791dSBob Badour 'Spaces' is zero or more ASCII space or tab characters.
2320*418b791dSBob Badour
2321*418b791dSBob Badour 'Digits' is any number of digits valid in the radix. Letters 'A' through
2322*418b791dSBob Badour 'Z' are treated as digits with values 10 through 35. 'Digits' may begin
2323*418b791dSBob Badour with "0x" when a radix of 0 or 16 is specified.
2324*418b791dSBob Badour
2325*418b791dSBob Badour Upper and lower case letters can be used interchangeably.
2326*418b791dSBob Badour
2327*418b791dSBob Badour
2328*418b791dSBob Badour Prototype:
2329*418b791dSBob Badour
2330*418b791dSBob Badour uint32 std_scanul( const char *pchBuf, int nRadix, const char **ppchEnd,
2331*418b791dSBob Badour int *pnError)
2332*418b791dSBob Badour
2333*418b791dSBob Badour Parameters:
2334*418b791dSBob Badour
2335*418b791dSBob Badour pchBuf [in] : the start of the string to scan.
2336*418b791dSBob Badour
2337*418b791dSBob Badour nRadix [in] : the numeric radix (or base) of the number. Valid values are
2338*418b791dSBob Badour 2 through 36 or zero, which implies auto-detection.
2339*418b791dSBob Badour Auto-detection examines the digits field. If it begins with
2340*418b791dSBob Badour "0x", radix 16 is selected. Otherwise, if it begins with
2341*418b791dSBob Badour "0" radix 8 is selected. Otherwise, radix 10 is selected.
2342*418b791dSBob Badour
2343*418b791dSBob Badour ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
2344*418b791dSBob Badour character that did not match the expected pattern shown
2345*418b791dSBob Badour above, except on STD_BADPARAM and STD_OVERFLOW when it is
2346*418b791dSBob Badour set to the start of the string.
2347*418b791dSBob Badour
2348*418b791dSBob Badour pnError [out] : If pnError is not NULL, *pnError holds the error code,
2349*418b791dSBob Badour which is one of the following:
2350*418b791dSBob Badour ~
2351*418b791dSBob Badour 0 : Numeric value is from 0 to MAX_UINT32.
2352*418b791dSBob Badour
2353*418b791dSBob Badour STD_NEGATIVE : The scanned value was negative and its absolute value was
2354*418b791dSBob Badour from 1 to MAX_UINT32. The result is the negated value
2355*418b791dSBob Badour (cast to a uint32).
2356*418b791dSBob Badour
2357*418b791dSBob Badour STD_NODIGITS : No digits were found. The result is zero.
2358*418b791dSBob Badour
2359*418b791dSBob Badour STD_OVERFLOW : The absolute value exceeded MAX_UINT32. The result
2360*418b791dSBob Badour is set to MAX_UINT32 and *ppchEnd is set to pchBuf.
2361*418b791dSBob Badour
2362*418b791dSBob Badour STD_BADPARAM : An improper value for nRadix was received. The result
2363*418b791dSBob Badour is set to zero, and *ppchEnd is set to pchBuf.
2364*418b791dSBob Badour *
2365*418b791dSBob Badour
2366*418b791dSBob Badour Return Value:
2367*418b791dSBob Badour
2368*418b791dSBob Badour The converted numeric result.
2369*418b791dSBob Badour
2370*418b791dSBob Badour Comments:
2371*418b791dSBob Badour
2372*418b791dSBob Badour The std_scanul() is similar to ANSI C's strtoul() but differs in the following
2373*418b791dSBob Badour respects:
2374*418b791dSBob Badour
2375*418b791dSBob Badour 1. It returns an error/success code. strtoul() results are ambiguous
2376*418b791dSBob Badour unless the caller sets errno to zero before calling it.
2377*418b791dSBob Badour
2378*418b791dSBob Badour 2. std_scanul() is free of references to current locale and errno. Some
2379*418b791dSBob Badour strtoul() implementations use locale; some don't.
2380*418b791dSBob Badour
2381*418b791dSBob Badour 3. It provides more complete reporting of range underflow. strtoul()
2382*418b791dSBob Badour does not distinguish between "-1" and "0xFFFFFFFF", and underflow is
2383*418b791dSBob Badour poorly defined.
2384*418b791dSBob Badour
2385*418b791dSBob Badour 4. std_scanul() reports a "no digits" error code to distinguish "0" from
2386*418b791dSBob Badour whitespace, "+", etc..
2387*418b791dSBob Badour
2388*418b791dSBob Badour See Also:
2389*418b791dSBob Badour
2390*418b791dSBob Badour std_scanull()
2391*418b791dSBob Badour
2392*418b791dSBob Badour =======================================================================
2393*418b791dSBob Badour
2394*418b791dSBob Badour std_scanull()
2395*418b791dSBob Badour
2396*418b791dSBob Badour Description:
2397*418b791dSBob Badour
2398*418b791dSBob Badour The std_scanull() converts an ASCII representation of a number to an
2399*418b791dSBob Badour unsigned long long. It expects strings that match the following pattern:
2400*418b791dSBob Badour ===pre>
2401*418b791dSBob Badour spaces [+|-] digits
2402*418b791dSBob Badour ===/pre>
2403*418b791dSBob Badour
2404*418b791dSBob Badour 'Spaces' is zero or more ASCII space or tab characters.
2405*418b791dSBob Badour
2406*418b791dSBob Badour 'Digits' is any number of digits valid in the radix. Letters 'A' through
2407*418b791dSBob Badour 'Z' are treated as digits with values 10 through 35. 'Digits' may begin
2408*418b791dSBob Badour with "0x" when a radix of 0 or 16 is specified.
2409*418b791dSBob Badour
2410*418b791dSBob Badour Upper and lower case letters can be used interchangeably.
2411*418b791dSBob Badour
2412*418b791dSBob Badour
2413*418b791dSBob Badour Prototype:
2414*418b791dSBob Badour
2415*418b791dSBob Badour uint64 std_scanull(const char *pchBuf, int nRadix, const char **ppchEnd,
2416*418b791dSBob Badour int *pnError)
2417*418b791dSBob Badour
2418*418b791dSBob Badour Parameters:
2419*418b791dSBob Badour
2420*418b791dSBob Badour pchBuf [in] : the start of the string to scan.
2421*418b791dSBob Badour
2422*418b791dSBob Badour nRadix [in] : the numeric radix (or base) of the number. Valid values are
2423*418b791dSBob Badour 2 through 36 or zero, which implies auto-detection.
2424*418b791dSBob Badour Auto-detection examines the digits field. If it begins with
2425*418b791dSBob Badour "0x", radix 16 is selected. Otherwise, if it begins with
2426*418b791dSBob Badour "0" radix 8 is selected. Otherwise, radix 10 is selected.
2427*418b791dSBob Badour
2428*418b791dSBob Badour ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
2429*418b791dSBob Badour character that did not match the expected pattern shown
2430*418b791dSBob Badour above, except on STD_BADPARAM and STD_OVERFLOW when it is
2431*418b791dSBob Badour set to the start of the string.
2432*418b791dSBob Badour
2433*418b791dSBob Badour pnError [out] : If pnError is not NULL, *pnError holds the error code,
2434*418b791dSBob Badour which is one of the following:
2435*418b791dSBob Badour ~
2436*418b791dSBob Badour 0 : Numeric value is from 0 to MAX_UINT64.
2437*418b791dSBob Badour
2438*418b791dSBob Badour STD_NEGATIVE : The scanned value was negative and its absolute value was
2439*418b791dSBob Badour from 1 to MAX_UINT64. The result is the negated value
2440*418b791dSBob Badour (cast to a uint64).
2441*418b791dSBob Badour
2442*418b791dSBob Badour STD_NODIGITS : No digits were found. The result is zero.
2443*418b791dSBob Badour
2444*418b791dSBob Badour STD_OVERFLOW : The absolute value exceeded MAX_UINT64. The result
2445*418b791dSBob Badour is set to MAX_UINT64 and *ppchEnd is set to pchBuf.
2446*418b791dSBob Badour
2447*418b791dSBob Badour STD_BADPARAM : An improper value for nRadix was received. The result
2448*418b791dSBob Badour is set to zero, and *ppchEnd is set to pchBuf.
2449*418b791dSBob Badour *
2450*418b791dSBob Badour
2451*418b791dSBob Badour Return Value:
2452*418b791dSBob Badour
2453*418b791dSBob Badour The converted numeric result.
2454*418b791dSBob Badour
2455*418b791dSBob Badour Comments:
2456*418b791dSBob Badour
2457*418b791dSBob Badour The std_scanull() is similar to ANSI C's strtoull() but differs in the following
2458*418b791dSBob Badour respects:
2459*418b791dSBob Badour
2460*418b791dSBob Badour 1. It returns an error/success code. strtoull() results are ambiguous
2461*418b791dSBob Badour unless the caller sets errno to zero before calling it.
2462*418b791dSBob Badour
2463*418b791dSBob Badour 2. std_scanull() is free of references to current locale and errno. Some
2464*418b791dSBob Badour strtoull() implementations use locale; some don't.
2465*418b791dSBob Badour
2466*418b791dSBob Badour 3. It provides more complete reporting of range underflow. strtoul()
2467*418b791dSBob Badour does not distinguish between "-1" and "0xFFFFFFFFFFFFFFFF", and underflow
2468*418b791dSBob Badour is poorly defined.
2469*418b791dSBob Badour
2470*418b791dSBob Badour 4. std_scanull() reports a "no digits" error code to distinguish "0" from
2471*418b791dSBob Badour whitespace, "+", etc..
2472*418b791dSBob Badour
2473*418b791dSBob Badour See Also:
2474*418b791dSBob Badour
2475*418b791dSBob Badour std_scanul()
2476*418b791dSBob Badour
2477*418b791dSBob Badour =======================================================================
2478*418b791dSBob Badour
2479*418b791dSBob Badour std_qsort()
2480*418b791dSBob Badour
2481*418b791dSBob Badour Description:
2482*418b791dSBob Badour
2483*418b791dSBob Badour An implementation of the quicksort algorithm, a massively recursive,
2484*418b791dSBob Badour in-place sorting algorithm for an array.
2485*418b791dSBob Badour
2486*418b791dSBob Badour The contents of the array are sorted in ascending order according to
2487*418b791dSBob Badour the comparison function pointed to by pfnCompare.
2488*418b791dSBob Badour
2489*418b791dSBob Badour pfnCompare must return a value less than, equal to, or
2490*418b791dSBob Badour greater than zero if the first argument is considered to be
2491*418b791dSBob Badour less than, equal to, or greater than the second, respectively.
2492*418b791dSBob Badour
2493*418b791dSBob Badour std_qsort() is not a stable sort.
2494*418b791dSBob Badour
2495*418b791dSBob Badour Prototype:
2496*418b791dSBob Badour void std_qsort(void* pElems, int nNumElems, int nElemWidth,
2497*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
2498*418b791dSBob Badour void* pCompareCx);
2499*418b791dSBob Badour
2500*418b791dSBob Badour
2501*418b791dSBob Badour Parameters:
2502*418b791dSBob Badour pElems: array of elements to be sorted in place. It's size
2503*418b791dSBob Badour must be nNumElems * nElemWidth in bytes.
2504*418b791dSBob Badour nNumElems: number of elements in pElems
2505*418b791dSBob Badour nElemWidth: the width, in bytes of each element of pElems
2506*418b791dSBob Badour pfnCompare: callback comparison function, should return 0, less than
2507*418b791dSBob Badour zero or greater than zero if the left comparand is equal to, less
2508*418b791dSBob Badour than, or greater than, the right comparand, respectively.
2509*418b791dSBob Badour pCompareCx: the context passed as the first parameter by pfnCompare
2510*418b791dSBob Badour
2511*418b791dSBob Badour Return Value:
2512*418b791dSBob Badour None
2513*418b791dSBob Badour
2514*418b791dSBob Badour Comments:
2515*418b791dSBob Badour If nElemWidth is 2, 4, or 8, pElems is accessed internally as
2516*418b791dSBob Badour integer values for the purposes of reading and writing elements.
2517*418b791dSBob Badour Therefore, pElems must be aligned on a memory boundary compatible
2518*418b791dSBob Badour with integer access of the array elements. I.e. if you pass 4 as
2519*418b791dSBob Badour nElemWidth, *(int*)pElems must succeed.
2520*418b791dSBob Badour
2521*418b791dSBob Badour =======================================================================
2522*418b791dSBob Badour
2523*418b791dSBob Badour std_bisect()
2524*418b791dSBob Badour
2525*418b791dSBob Badour Description:
2526*418b791dSBob Badour
2527*418b791dSBob Badour Find an element in a sorted array of elements. Uses a binary
2528*418b791dSBob Badour search.
2529*418b791dSBob Badour
2530*418b791dSBob Badour Prototype:
2531*418b791dSBob Badour int std_bisect(const void* pElems, int nNumElems, int nElemWidth,
2532*418b791dSBob Badour const void* pElemFind,
2533*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
2534*418b791dSBob Badour void* pCompareCx);
2535*418b791dSBob Badour
2536*418b791dSBob Badour Parameters:
2537*418b791dSBob Badour pElems: array of elements to be searched. It's size
2538*418b791dSBob Badour must be nNumElems * nElemWidth in bytes.
2539*418b791dSBob Badour nNumElems: number of elements in pElems
2540*418b791dSBob Badour nElemWidth: the width, in bytes of each element of pElems
2541*418b791dSBob Badour pElemFind: the element value to find in the array
2542*418b791dSBob Badour pfnCompare: callback comparison function, should return 0, less than
2543*418b791dSBob Badour zero or greater than zero if the left comparand is equal to, less
2544*418b791dSBob Badour than, or greater than, the right comparand, respectively.
2545*418b791dSBob Badour pCompareCx: the context passed as the first parameter by pfnCompare
2546*418b791dSBob Badour
2547*418b791dSBob Badour Return Value:
2548*418b791dSBob Badour index of the element such that pElems[index] <= elem < pElems[index + 1]
2549*418b791dSBob Badour nNumElems if elem is greater than all the elements in the list
2550*418b791dSBob Badour 0 if the elem is less than or equal to the all the elements in the list
2551*418b791dSBob Badour
2552*418b791dSBob Badour =======================================================================
2553*418b791dSBob Badour
2554*418b791dSBob Badour std_merge()
2555*418b791dSBob Badour
2556*418b791dSBob Badour Description:
2557*418b791dSBob Badour
2558*418b791dSBob Badour Merge two sorted arrays into another array.
2559*418b791dSBob Badour
2560*418b791dSBob Badour Prototype:
2561*418b791dSBob Badour void std_merge(void* vpDst, int nDst,
2562*418b791dSBob Badour const void* vpA, int nA,
2563*418b791dSBob Badour const void* vpB, int nB,
2564*418b791dSBob Badour int nElemWidth,
2565*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
2566*418b791dSBob Badour void* pCompareCx);
2567*418b791dSBob Badour
2568*418b791dSBob Badour Parameters:
2569*418b791dSBob Badour vpDst: destination array. It's size must be nDst * nElemWidth in bytes.
2570*418b791dSBob Badour nDst: number of elements that vpDst can accomodate
2571*418b791dSBob Badour vpA: array of elements to be merged, it's size must be nA * nElemWidth
2572*418b791dSBob Badour in bytes.
2573*418b791dSBob Badour nA: number of elements in vpA
2574*418b791dSBob Badour vpB: array of elements to be merged, it's size must be nB * nElemWidth
2575*418b791dSBob Badour in bytes.
2576*418b791dSBob Badour nB: number of elements in vpB
2577*418b791dSBob Badour nElemWidth: the width, in bytes of each element of pElems
2578*418b791dSBob Badour pfnCompare: callback comparison function, should return 0, less than
2579*418b791dSBob Badour zero or greater than zero if the left comparand is equal to, less
2580*418b791dSBob Badour than, or greater than, the right comparand, respectively.
2581*418b791dSBob Badour pCompareCx: the context passed as the first parameter by pfnCompare
2582*418b791dSBob Badour
2583*418b791dSBob Badour Return Value:
2584*418b791dSBob Badour none
2585*418b791dSBob Badour
2586*418b791dSBob Badour =======================================================================
2587*418b791dSBob Badour
2588*418b791dSBob Badour std_uniq()
2589*418b791dSBob Badour
2590*418b791dSBob Badour Description:
2591*418b791dSBob Badour Removes duplicate entries from a sorted array.
2592*418b791dSBob Badour
2593*418b791dSBob Badour Prototype:
2594*418b791dSBob Badour int std_uniq(void* vpElems, int nNumElems, int nElemWidth,
2595*418b791dSBob Badour int (*pfnCompare)(void*, const void*, const void*),
2596*418b791dSBob Badour void* pCompareCx);
2597*418b791dSBob Badour
2598*418b791dSBob Badour Parameters:
2599*418b791dSBob Badour pElems: array of elements to be searched. It's size
2600*418b791dSBob Badour must be nNumElems * nElemWidth in bytes.
2601*418b791dSBob Badour nNumElems: number of elements in pElems
2602*418b791dSBob Badour nElemWidth: the width, in bytes of each element of pElems
2603*418b791dSBob Badour pfnCompare: callback comparison function, should return 0, less than
2604*418b791dSBob Badour zero or greater than zero if the left comparand is equal to, less
2605*418b791dSBob Badour than, or greater than, the right comparand, respectively.
2606*418b791dSBob Badour pCompareCx: the context passed as the first parameter by pfnCompare
2607*418b791dSBob Badour
2608*418b791dSBob Badour Return Value:
2609*418b791dSBob Badour the number of uniq elements left in vpElems
2610*418b791dSBob Badour
2611*418b791dSBob Badour =======================================================================
2612*418b791dSBob Badour
2613*418b791dSBob Badour std_scand()
2614*418b791dSBob Badour
2615*418b791dSBob Badour Description:
2616*418b791dSBob Badour
2617*418b791dSBob Badour The std_scand() converts the initial portion of an input ASCII string
2618*418b791dSBob Badour to it's corresponding floating point value. It expects the input
2619*418b791dSBob Badour string to match the following pattern:
2620*418b791dSBob Badour ===pre>
2621*418b791dSBob Badour <Spaces><Subject String><Rest Of The String>
2622*418b791dSBob Badour ===/pre>
2623*418b791dSBob Badour
2624*418b791dSBob Badour 'Spaces' - is zero or more ASCII space or tab characters.
2625*418b791dSBob Badour 'Subject String' - is the part of the input string that represents a
2626*418b791dSBob Badour valid floating point constant.
2627*418b791dSBob Badour 'Rest Of The String' - is the remaining sequence of one or more
2628*418b791dSBob Badour characters including the terminating null
2629*418b791dSBob Badour character of the input string.
2630*418b791dSBob Badour
2631*418b791dSBob Badour A valid subject string can be one of the following:
2632*418b791dSBob Badour -- <NAN>, ignoring case. This is interpreted as a quiet NAN.
2633*418b791dSBob Badour -- [+|-]<INF|INFINITY>, ignoring case. This is interpreted as an
2634*418b791dSBob Badour infinity.
2635*418b791dSBob Badour -- [+|-]<Valid Floating Point Number>
2636*418b791dSBob Badour
2637*418b791dSBob Badour In general, a valid floating poing number can either be a decimal
2638*418b791dSBob Badour number or an hexadecimal number, and has the following form:
2639*418b791dSBob Badour <Integral Part>[.[<Fractional Part>]][<Exponent>]
2640*418b791dSBob Badour where the intergral, fractional and the exponent part may consist of
2641*418b791dSBob Badour sequence of valid decimal or hexadecimal digits. More specifically:
2642*418b791dSBob Badour
2643*418b791dSBob Badour For a decimal floating point number:
2644*418b791dSBob Badour 'Integral Part' - <Decimal Digits>
2645*418b791dSBob Badour 'Fractional Part' - <Decimal Digits>
2646*418b791dSBob Badour 'Exponent' - <e|E><Decimal Digits>
2647*418b791dSBob Badour For a hexadecimal floating point number:
2648*418b791dSBob Badour 'Integral Part' - <Hexadecimal Digits>
2649*418b791dSBob Badour 'Fractional Part' - <Hexadecimal Digits>
2650*418b791dSBob Badour 'Exponent' - <p|P><Decimal Digits>
2651*418b791dSBob Badour
2652*418b791dSBob Badour where:
2653*418b791dSBob Badour 'Decimal Digits' - is any number of digits in the range [0,10].
2654*418b791dSBob Badour 'Hexadecimal Digits' - is any number of digits in the range [0,10]
2655*418b791dSBob Badour or the alphabets A through F.
2656*418b791dSBob Badour 'e','E','p','P' - represent the exponent characters
2657*418b791dSBob Badour
2658*418b791dSBob Badour Prototype:
2659*418b791dSBob Badour
2660*418b791dSBob Badour double std_scand(const char *pchBuf, const char **ppchEnd);
2661*418b791dSBob Badour
2662*418b791dSBob Badour Parameters:
2663*418b791dSBob Badour
2664*418b791dSBob Badour pchBuf [in] : the start of the string to scan.
2665*418b791dSBob Badour
2666*418b791dSBob Badour ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
2667*418b791dSBob Badour character after the parsed number.
2668*418b791dSBob Badour
2669*418b791dSBob Badour Return Value:
2670*418b791dSBob Badour
2671*418b791dSBob Badour This function returns the converted numeric result. If the string
2672*418b791dSBob Badour does not contain a valid floating point number then the function
2673*418b791dSBob Badour returns zero. If the converted value is outside the range of
2674*418b791dSBob Badour representable values (overflow), [-]INFINITY is
2675*418b791dSBob Badour returned. In case of an underflow, the function returns zero.
2676*418b791dSBob Badour
2677*418b791dSBob Badour =======================================================================*/
2678*418b791dSBob Badour
2679*418b791dSBob Badour #endif // AEESTD_H
2680*418b791dSBob Badour
2681*418b791dSBob Badour
2682