summaryrefslogtreecommitdiff
path: root/include/AEEstd.h
blob: 2cfc653693b9dd776c9adf207eab6bfc92c64818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AEESTD_H
#define AEESTD_H
/*====================================================================

DESCRIPTION:  Standard library; general-purpose utility functions.

====================================================================*/
#include "AEEVaList.h"
#include "AEEStdDef.h"

#define STD_CONSTRAIN( val, min, max ) (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val))
#define STD_BETWEEN( val, minGE, maxLT ) \
                   ( (unsigned long)((unsigned long)(val) - (unsigned long)(minGE)) < \
                   (unsigned long)((unsigned long)(maxLT) - (unsigned long)(minGE)) )
#define STD_ARRAY_SIZE(a)             ((int)((sizeof((a))/sizeof((a)[0]))))
#define STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a))))

#define STD_SIZEOF(x)                 ((int)sizeof(x))
#define STD_OFFSETOF(type,member)     (((char*)(&((type*)1)->member))-((char*)1))

#define STD_RECOVER_REC(type,member,p) ((void)((p)-&(((type*)1)->member)),\
                                        (type*)(void*)(((char*)(void*)(p))-STD_OFFSETOF(type,member)))
#define STD_MIN(a,b)   ((a)<(b)?(a):(b))
#define STD_MAX(a,b)   ((a)>(b)?(a):(b))
//lint -emacro(545,STD_ZEROAT)
#define STD_ZEROAT(p)  std_memset((p), 0, sizeof(*p))

#define _STD_BITS_PER(bits)     (8*sizeof((bits)[0]))

#define STD_BIT_SET(bits, ix)     ((bits)[(ix)/_STD_BITS_PER((bits))] |= 0x1<<((ix) & (_STD_BITS_PER((bits))-1)))
#define STD_BIT_CLEAR(bits, ix)   ((bits)[(ix)/_STD_BITS_PER((bits))] &= ~(0x1<<((ix) & (_STD_BITS_PER((bits))-1))))
#define STD_BIT_TEST(bits, ix)    ((bits)[(ix)/_STD_BITS_PER((bits))] & (0x1<<((ix) & (_STD_BITS_PER((bits))-1))))

//
// Error codes
//
#define STD_NODIGITS   1
#define STD_NEGATIVE   2
#define STD_OVERFLOW   3
#define STD_BADPARAM   4
#define STD_UNDERFLOW  5

#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */

//Version function
extern int           std_getversion(char *pcDst, int nDestSize);

//String functions
extern int           std_strlen(const char *s);
extern int           std_strcmp(const char *s1, const char *s2);
extern int           std_strncmp(const char *s1, const char *s2, int n);
extern int           std_stricmp(const char *s1, const char *s2);
extern int           std_strnicmp(const char *s1, const char *s2, int n);
extern int           std_strlcpy(char *pcDst, const char *pszSrc, int nDestSize);
extern int           std_strlcat(char *pcDst, const char *pszSrc, int nDestSize);
extern char         *std_strstr(const char *pszString, const char *pszSearch);

//Character functions
extern char          std_tolower(char c);
extern char          std_toupper(char c);

// Mem functions
extern void         *std_memset(void *p, int c, int nLen);
extern void         *std_memmove(void *pTo, const void *cpFrom, int nLen);
extern int           std_memcmp(const void *a, const void *b, int length);
extern void         *std_memchr(const void *s, int c, int n);
extern void         *std_memstr(const char *cpHaystack, const char *cpszNeedle, int nHaystackLen);
extern void         *std_memrchr(const void *s, int c, int n);
extern void         *std_memrchrbegin(const void *p, int c, int nLen);
extern void         *std_memchrend(const void *cpcSrch, int c, int nLen);
extern void         *std_memchrsend(const void *cpSrch, const char *cpszChars, int nLen);

//Other String functions
extern char         *std_strchr(const char *s, int c);
extern char         *std_strchrs(const char *sSrch, const char *sChars);
extern char         *std_strrchr(const char *s, int c);
extern char         *std_strchrend(const char *cpszSrch, char c);
extern char         *std_strchrsend(const char *s, const char *cpszSrch);
extern char         *std_strends(const char *cpsz, const char *cpszSuffix);
extern char         *std_striends(const char *cpsz, const char *cpszSuffix);
extern char         *std_strbegins(const char *cpsz, const char *cpszPrefix);
extern char         *std_stribegins(const char *cpsz, const char *cpszPrefix);
extern int           std_strcspn(const char *s, const char *cpszSrch);
extern int           std_strspn(const char *s, const char *cpszSrch);

//Wide char string functions
extern int           std_wstrlen(const AECHAR *s);
extern int           std_wstrlcpy(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize);
extern int           std_wstrlcat(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize);
extern int           std_wstrncmp(const AECHAR *s1, const AECHAR *s2, int nLen);
extern int           std_wstrcmp(const AECHAR *s1, const AECHAR *s2);
extern AECHAR       *std_wstrchr(const AECHAR *cpwszText, AECHAR ch);
extern AECHAR       *std_wstrrchr(const AECHAR *cpwszText, AECHAR ch);

//Path functions
extern int           std_makepath(const char *cpszDir,
                                  const char *cpszFile,
                                  char *pszDest, int nDestSize);
extern char         *std_splitpath(const char *cpszPath, const char *cpszDir);
extern char         *std_cleanpath(char *pszPath);
extern char         *std_basename(const char *pszPath);

//Inet functions, number functions
extern uint32        std_scanul(const char *pchBuf, int nRadix,
                                const char **ppchEnd, int *pnError);
extern uint64        std_scanull(const char *pchBuf, int nRadix,
                                 const char **ppchEnd, int *pnError);
extern double        std_scand(const char *pchBuf, const char **ppchEnd);

// Rand functions
extern unsigned      std_rand_next(unsigned uRand);
extern uint32        std_rand(uint32 uSeed, byte *pDest, int nSize);


// printf functions
extern int           std_vstrlprintf(char *pszDest, int nDestSize,
                                     const char *pszFmt, AEEVaList args);

extern int           std_strlprintf(char *pszDest, int nDestSize,
                                    const char *pszFmt, ...);

extern int           std_vsnprintf(char *pszDest, int nDestSize,
                                   const char *cpszFmt, AEEVaList args);

extern int           std_snprintf(char *pszDest, int nDestSize,
                                  const char *pszFmt, ...);

// endian swapping functions
extern int           std_CopyLE(void *pvDest,       int nDestSize,
                                const void *pvSrc,  int nSrcSize,
                                const char *pszFields);

extern int           std_CopyBE(void *pvDest,      int nDestSize,
                                const void *pvSrc, int nSrcSize,
                                const char *pszFields);

// sorting utilities
extern void  std_qsort(void *pElems, int nNumElems, int nElemWidth,
                       int (*pfnCompare)(void *, const void *, const void *),
                       void *pCompareCx);

extern int   std_bisect(const void *pElems, int nNumElems, int nElemWidth,
                        const void *pElem,
                        int (*pfnCompare)(void *, const void *, const void *),
                        void *pCompareCx);

extern void  std_merge(void *vpDst, int nDst,
                       const void *vpA, int nA,
                       const void *vpB, int nB,
                       int nElemWidth,
                       int (*pfnCompare)(void *, const void *, const void *),
                       void *pCompareCx);

extern int   std_uniq(void *vpElems, int nNumElems, int nElemWidth,
                      int (*pfnCompare)(void *, const void *, const void *),
                      void *pCompareCx);

#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */


#define STD_SWAPS(us) \
   ((((us) & 0xff) << 8) + (((us) & 0xff00) >> 8))


static __inline unsigned short std_swaps(unsigned short us)
{
	return STD_SWAPS(us);
}

/* note, STD_SWAPL() requires that ul be an l-value, and destroyable.
   this macro is not intended for use outside AEEstd.h */
#define STD_SWAPL(ul) \
    (((ul) = (((ul) & 0x00ff00ff) << 8) | (((ul)>>8) & 0x00ff00ff)),(((ul) >> 16) | ((ul) << 16)))

static __inline unsigned long std_swapl(unsigned long ul)
{
	return STD_SWAPL(ul);
}

#ifdef AEE_BIGENDIAN
#  define STD_HTONL(u)     (u)
#  define STD_HTONS(u)     (u)
#  define STD_HTOLEL(u)    (STD_SWAPL(u))
#  define STD_HTOLES(u)    (STD_SWAPS(u))
#else
#  define STD_HTONL(u)     (STD_SWAPL(u))
#  define STD_HTONS(u)     (STD_SWAPS(u))
#  define STD_HTOLEL(u)    (u)
#  define STD_HTOLES(u)    (u)
#endif

static __inline unsigned short std_letohs(unsigned short us)
{
	return STD_HTOLES(us);
}

static __inline unsigned short std_htoles(unsigned short us)
{
	return STD_HTOLES(us);
}

static __inline unsigned long std_letohl(unsigned long ul)
{
	return STD_HTOLEL(ul);
}

static __inline unsigned long std_htolel(unsigned long ul)
{
	return STD_HTOLEL(ul);
}

static __inline unsigned short std_ntohs(unsigned short us)
{
	return STD_HTONS(us);
}

static __inline unsigned short std_htons(unsigned short us)
{
	return STD_HTONS(us);
}

static __inline unsigned long std_ntohl(unsigned long ul)
{
	return STD_HTONL(ul);
}

static __inline unsigned long std_htonl(unsigned long ul)
{
	return STD_HTONL(ul);
}


#undef STD_HTONL   // private macro; not exported as a supported API
#undef STD_HTONS   // private macro; not exported as a supported API
#undef STD_HTOLEL  // private macro; not exported as a supported API
#undef STD_HTOLES  // private macro; not exported as a supported API
#undef STD_SWAPS   // private macro; not exported as a supported API
#undef STD_SWAPL   // private macro; not exported as a supported API


/*
=======================================================================
MACROS DOCUMENTATION
=======================================================================

STD_CONTSTRAIN()

Description:
  STD_CONTSTRAIN() constrains a number to be between two other numbers.

Definition:
   STD_CONSTRAIN( val, min, max ) \
          (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val))

Parameters:
  val: number to constrain
  min: number to stay greater than or equal to
  max: number to stay less than or equal to

Evaluation Value:
   the constrained number

=======================================================================

STD_BETWEEN()

Description:
    STD_BETWEEN() tests whether a number is between two other numbers.

Definition:
    STD_BETWEEN( val, minGE, maxLT ) \
               ((unsigned)((unsigned)(val) - (unsigned)(minGE)) < \
                (unsigned)((unsigned)(maxLT) - (unsigned)(minGE)))

Parameters:
     val: value to test
     minGE: lower bound
     maxLT: upper bound

Evaluation Value:
     1 if val >= minGE and val < maxLT

=======================================================================

STD_ARRAY_SIZE()

Description:
   STD_ARRAY_SIZE() gives the number of elements in a statically allocated array.

Definition:
    STD_ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0]))

Parameters:
    a: array to test

Evaluation Value:
    number of elements in a

=======================================================================

STD_ARRAY_MEMBER()

Description:
   STD_ARRAY_MEMBER() tests whether an item is a member of a statically allocated array.

Definition:
   STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a))))

Parameters:
    p: item to test
    a: array to check

Evaluation Value:
    1 if p is in a

=======================================================================

STD_OFFSETOF()

Description:
  STD_OFFSETOF() gives the offset of member of a struct.

Definition:
   STD_OFFSETOF(type,member) (((char *)(&((type *)0)->member))-((char *)0))

Parameters:
    type: structured type
    member: name of member in the struct

Evaluation Value:
    offset of member (in bytes) in type

=======================================================================

STD_RECOVER_REC()

Description:
  STD_RECOVER_REC() provides a safe cast from a pointer to a member
    of a struct to a pointer to the containing struct

Definition:
  STD_RECOVER_REC(type,member,p) ((type*)(((char*)(p))-STD_OFFSETOF(type,member)))

Parameters:
    type: structured type
    member: name of member in the struct
    p: pointer to the member of the struct

Evaluation Value:
    a pointer of type type to the containing struct

=======================================================================

STD_MIN()

Description:
   STD_MIN() finds the smaller of two values.

Definition:
   STD_MIN(a,b)   ((a)<(b)?(a):(b))

Parameters:
    a, b: values to compare

Evaluation Value:
    smaller of a and b

=======================================================================

STD_MAX()

Description:
  STD_MAX() finds the larger of two values.

Definition:
   STD_MAX(a,b)   ((a)>(b)?(a):(b))

Parameters:
    a, b: values to compare

Evaluation Value:
    larger of a and b

=======================================================================

STD_ZEROAT()

Description:
   STD_ZEROAT() zero-initializes the contents of a typed chunk of memory.

Definition:
   STD_ZEROAT(p)  std_memset((p), 0, sizeof(*p))

Parameters:
    p: the chunk to initialize

Evaluation Value:
    p

=======================================================================

STD_BIT_SET()

Description:
   STD_BIT_SET(bits, ix) sets the bit in the memory stored in bits at
                         index ix

Parameters:
    bits: the memory address holding the  bits
    ix:   the index of the bit to set;

=======================================================================

STD_BIT_CLEAR()

Description:
   STD_BIT_CLEAR(bits, ix) clears the bit in the memory stored in bits
                           at index ix

Parameters:
    bits: the memory address holding the  bits
    ix:   the index of the bit to clear

=======================================================================

STD_BIT_TEST()

Description:
   STD_BIT_TEST(bits, ix) returns the bit in the memory stored in bits
                          at index ix

Parameters:
    bits: the memory address holding the bits
    ix:   the index of the bit to test

Evaluation Value:
    0x1 if set 0x0 if not set

=====================================================================
INTERFACES DOCUMENTATION
=======================================================================

std Interface

Description:
   This library provides a set of general-purpose utility functions.
   Functionality may overlap that of a subset of the C standard library, but
   this library differs in a few respects:

   - Functions are fully reentrant and avoid use of static variables.

   - The library can be supported consistently across all environments.
   Compiler-supplied libraries sometimes behave inconsistently and are
   unavailable in some environments.

   - Omits "unsafe" functions.  C standard library includes many functions
   that are best avoided entirely: strcpy, strcat, strtok, etc.


=======================================================================

std_getversion()

Description:

   The std_getversion() copies the stdlib version to pcDst.  This function
   takes the size of the destination buffer as an argument and guarantees
   to zero-terminate the result and not to overflow the nDestSize size.

   This function copies up to size-1 characters from the stdlib version
   string to pcDest and NUL-terminates the pcDest string.

Prototype:
   int  std_getversion(char *pcDst, int nDestSize)


Parameters:
   pcDst :     Destination string
   nDestSize:  Size of the destination buffer in bytes

Return Value:

   Returns the length of the version string (in characters).

=======================================================================

std_strlen()

Description:
   The std_strlen() computes the length of the given string.

Prototype:
   int std_strlen(const char *cpszStr)

Parameters:
   cpszStr : String whose length will be computed

Return Value:
   Length of the string in characters that precede the terminating NULL character.

=======================================================================

std_strcmp()

Description:
   The std_strcmp() compares two NUL-terminated character strings.
   Comparison is strictly by byte values with no character set
   interpretation.

Prototype:

   int std_strcmp(const char *s1, const char *s2);

Parameters:
   s1, s2: strings to compare

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

See Also:
   std_wstrcmp

=======================================================================

std_strncmp()

Description:
   The std_strncmp() compares at most n bytes of two NUL-terminated character strings.

Prototype:

   int std_strncmp(const char *s1, const char *s2, int n);

Parameters:
   s1, s2: strings to compare
   n: maximum number of bytes to compare.  if either s1 or s2 is
       shorter than n, the function terminates there

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

See Also:
   std_wstrncmp

=======================================================================

std_stricmp()

Description:
   The std_stricmp() compares two NUL-terminated character strings, case-folding any
   ASCII characters.

Prototype:

   int std_stricmp(const char *s1, const char *s2);

Parameters:
   s1, s2: strings to compare

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

=======================================================================

std_strnicmp()

Description:
   The std_strnicmp() compares at most n bytes of 2 NUL-terminated character strings,
   case-folding any ASCII characters.

Prototype:

   int std_strnicmp(const char *s1, const char *s2, int n);

Parameters:
   s1, s2: strings to compare
   n: maximum number of bytes to compare.  if either s1 or s2 is
       shorter than n, the function terminates there

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

=======================================================================

std_strlcpy()

Description:

   The std_strlcpy() copies pszSrc string to the pcDst.  It is a safer
   alternative to strcpy() or strncpy().  This function takes the size of the
   destination buffer as an argument and guarantees to NUL-terminate the
   result and not to overflow the nDestSize size.

   This function copies up to nDestSize-1 characters from the pszSrc string
   to pcDest and NUL-terminates the pcDest string.

Prototype:
   int std_strlcpy(char *pcDst, const char *pszSrc, int nDestSize)

Parameters:
   pcDst :     Destination string
   pcSrc :     Source string
   nDestSize:  Size of the destination buffer in bytes

Return Value:

   Returns the length of the string (in characters) it tried to create,
   which is same as length of pszSrc.

   Example:

   {
      char buf[64];
      if (std_strlcpy(buf, file_name, STD_ARRAY_SIZE(buf) >=
          STD_ARRAY_SIZE(buf)) {
         //Truncated -- Handle overflow....
      }
   }

Comment:

   Unlike strlcpy, std_strlcpy accepts an integer size and does nothing when a
   negative value is passed.  When passing valid sizes for objects on our
   supported platforms, this should not result in any observed difference.
   However, calling strlcpy() with UINT_MAX will result in the entire source
   string being copied, whereas std_strlcpy() will do nothing.  Passing INT_MAX
   to str_strlcpy() will achieve the same result (although both these cases are
   bad practice since they defeat bounds checking).


=======================================================================

std_strlcat()

Description:

   The std_strlcat() function concatenates a string to a string already
   residing in a buffer.  It is a safer alternative to strcat() or strncat().
   This function takes the size of the destination buffer as an argument and
   guarantees not to create an improperly terminated string and not to
   overflow the nDestSize size.

   This function appends pszSrc to pcDst, copying at most nDestSize minus
   the length of the string in pcDest minus 1 bytes, always NUL-terminating
   the result.

   For compatibility with "strlcat()", std_strlcat() does *not* zero-terminate
   the destination buffer in cases where the buffer lacks termination on entry
   to the function.  Do not rely on std_strlcat() to zero-terminate a buffer
   that is not already zero-terminated; instead ensure that the buffer is
   properly initialized using std_strlcpy() or some other means.

Prototype:

   int std_strlcat(char *pcDst, const char *pszSrc, int nDestSize)

Parameters:

   pcDst :     Destination string
   pcSrc :     Source string
   nDestSize:  Size of the destination buffer in bytes

Return Value:

   Returns the length of the string (in characters) it tried to create,
   which is same as length of pszSrc plus the length of pszDest.

   Example:

   {
      char buf[64];
      if (std_strlcat(buf, file_name, STD_ARRAY_SIZE(buf) >=
          STD_ARRAY_SIZE(buf)) {
         //Truncated -- Handle overflow....
      }
   }


=======================================================================

std_strstr()

Description:
   The std_strstr() finds the first occurrence of a substring in a string.

Prototype:

   char * std_strstr(const char *pszString, const char *pszSearch);

Parameters:
   pszString: string to search
   pszSearch: sub string to search for

Return Value:
   A pointer to the first character in the first occurrence of the substring if found, NULL otherwise

=======================================================================

std_tolower()

Description:
   The std_tolower() converts an uppercase letter to the corresponding
   lowercase letter.

Prototype:
   char std_tolower(char c);

Parameters:
   c: A character.

Return Value:
   the corresponding lowercase letter if c is an ASCII character whose
   value is representable as an uppercase letter, else the same character
   c is returned.

=======================================================================

std_toupper()

Description:
   The std_toupper() converts an lowercase letter to the corresponding
   uppercase letter.

Prototype:
   char std_toupper(char c);

Parameters:
   c: is a character.

Return Value:
   The corresponding uppercase letter if c is an ASCII character whose
   value is representable as an lowercase letter; else the same character
   c is returned.

=======================================================================

std_memset()

Description:
   The std_memset() sets each byte in a block of memory to a value.

Prototype:

   void *std_memset(void *p, int c, int nLen);

Parameters:
   p: memory block to set
   c: value to set each byte to
   nLen: size of p in bytes

Return Value:
   p

=======================================================================

std_memmove()

Description:
   The std_memmove() copies a block of memory from one buffer to another.

Prototype:

   void *std_memmove(void *pTo, const void *cpFrom, int nLen);

Parameters:
   pTo: destination buffer
   cpFrom: source buffer
   nLen: number of bytes to copy

Return Value:
   pTo

=======================================================================

std_memcmp()

Description:
   The std_memcmp() compares two memory buffers, byte-wise.

Prototype:

   int std_memcmp(const void *a, const void *b, int length);

Parameters:
   a, b: buffers to compare
   length: number of bytes to compare

Return Value:
   0 if buffers are the same for nLength ~
   < 0 if a is less than b ~
   > 0 if a is greater than b

=======================================================================

std_memchr()

Description:
   The std_memchr() finds the first occurrence of a character in a memory
   buffer.

Prototype:

   void *std_memchr(const void* s, int c, int n);

Parameters:
   s: buffer to search
   c: value of byte to look for
   n: size of s in bytes

Return Value:
   A pointer to the occurrence of c. NULL if not found.

=======================================================================

std_memstr()

Description:
   The std_memstr() finds the first occurrence of a substring in a memory
   buffer.

Prototype:

   void *std_memstr(const char* cpHaystack, const char* cpszNeedle,
                    int nHaystackLen);

Parameters:
   cpHaystack: buffer to search
   cpszNeedle: NUL-terminated string to search for
   nHaystackLen: size of cpHaystack in bytes

Return Value:
   a pointer to the first occurrence of cpszNeedle if found,
       NULL otherwise

Comments:
   None

Side Effects:
   None

See Also:
   None

=======================================================================

std_memrchr()

Description:

   The std_memrchr() finds the last occurrence of a character in a memory
   buffer.

Prototype:

   void *std_memrchr(const void* s, int c, int n);

Parameters:
   s: buffer to search
   c: value of byte to look for
   n: size of s in bytes

Return Value:
   a pointer to the last occurrence of c, NULL if not found

=======================================================================

std_memrchrbegin()

Description:
   The std_memrchrbegin() finds the last occurrence of a character in a
   memory buffer.

Prototype:

   void *std_memrchrbegin(const void* s, int c, int n);

Parameters:
   s: buffer to search
   c: value of byte to look for
   n: size of s in bytes

Return Value:
   a pointer to the last occurrence of c, or s if not found

=======================================================================

std_memchrend()

Description:
   The std_memchrend() finds the first occurrence of a character in a
   memory buffer.

Prototype:

   void *std_memchrend(const void* s, int c, int n);

Parameters:
   s: buffer to search
   c: value of byte to look for
   n: size of s in bytes

Return Value:
   a pointer to the occurrence of c, s + n if not found

=======================================================================
std_memchrsend()

Description:
   The std_memchrsend() finds the first occurrence of any character in a
   NUL-terminated list of characters in a memory buffer.

Prototype:

   void *std_memchrend(const void* s, const char* cpszChars, int n);

Parameters:
   s: buffer to search
   cpszChars: characters to look for
   n: size of s in bytes

Return Value:
   a pointer to the first occurrence of one of cpszChars, s + n if not found

=======================================================================

std_strchr()

Description:
   The std_strchr() finds the first occurrence of a character in a
   NUL-terminated string.

Prototype:

   char *std_strchr(const char* s, int c);

Parameters:
   s: string to search
   c: char to search for

Return Value:
   pointer to first occurrence, NULL if not found

See Also:
   std_wstrchr

=======================================================================

std_strchrs()

Description:
   The std_strchrs() searches s, a NUL-terminated string, for the first
   occurrence of any characters in cpszSrch, a NUL-terminated list of
   characters.

Prototype:

   char *std_strchrs(const char* s, const char *cpszSrch);

Parameters:
   s: string to search
   cpszSrch: a list of characters to search for

Return Value:
   first occurrence of any of cpszSrch, NULL if not found

=======================================================================

std_strrchr()

Description:
   The std_strrchr() finds the last occurrence of a character in a
   NUL-terminated string.

Prototype:

   char *std_strrchr(const char* s, int c);

Parameters:
   s: string to search
   c: char to search for

Return Value:
   pointer to last occurrence, NULL if not found

See Also:
   std_wstrrchr

=======================================================================

std_strchrend()

Description:
   The std_strchrend() finds the first occurrence of a character in a
   NUL-terminated string.

Prototype:

   char *std_strchrend(const char* s, int c);

Parameters:
   s: string to search
   c: char to search for

Return Value:
   pointer to first occurrence, s + std_strlen(s) if not found

=======================================================================

std_strchrsend()

Description:
   The std_strchrsend() searches s, a NUL-terminated string, for the first
   occurrence of any characters in cpszSrch, a NUL-terminated list of
   characters.

Prototype:

   char *std_strchrsend(const char* s, const char* cpszSrch);

Parameters:
   s: string to search
   cpszSrch: a list of characters to search for

Return Value:
   first occurrence of any of cpszSrch or s+strlen(s) if not found

=======================================================================

std_strends()

Description:
   The std_strends() tests whether a string ends in a particular suffix.

Prototype:

   char *std_strends(const char* cpsz, const char* cpszSuffix);

Parameters:
   cpsz: string to test
   cpszSuffix: suffix to test for

Return Value:
   the first character of cpsz+std_strlen(cpsz)-std_strlen(cpszSuffix)
     if cpsz ends with cpszSuffix.  NULL otherwise.

=======================================================================

std_striends()

Description:
   The std_striends() tests whether a string ends in a particular suffix,
   case-folding ASCII characters.

Prototype:

   char *std_striends(const char* cpsz, const char* cpszSuffix);

Parameters:
   cpsz: string to test
   cpszSuffix: suffix to test for

Return Value:
   the first character of cpsz+std_strlen(cpsz)-std_strlen(cpszSuffix)
     if cpsz ends with cpszSuffix.  NULL otherwise.

=======================================================================

std_strbegins()

Description:
   The std_strbegins() tests whether a string begins with a particular
   prefix string.

Prototype:

   char *std_strbegins(const char* cpsz, const char* cpszPrefix);

Parameters:
   cpsz: string to test
   cpszPrefix: prefix to test for

Return Value:
   cpsz + std_strlen(cpszPrefix) if cpsz does begin with cpszPrefix,
     NULL otherwise

=======================================================================

std_stribegins()

Description:
   The std_stribegins() tests whether a string begins with a particular
   prefix string, case-folding ASCII characters.

Prototype:

   char *std_stribegins(const char* cpsz, const char* cpszPrefix);

Parameters:
   cpsz: string to test
   cpszPrefix: prefix to test for

Return Value:
   cpsz + std_strlen(cpszPrefix) if cpsz does begin with cpszPrefix,
     NULL otherwise


=======================================================================

std_strcspn()

Description:
   The std_strcspn() function searches s, a NUL-terminated string, for
   the first occurrence of any characters in cpszSrch, a NUL-terminated
   list of characters. This function returns the length of the longest
   initial substring of s which consists of characters not present in
   cpszSrch.

Prototype:

   int std_strcspn(const char* s, const char* cpszSrch);

Parameters:
   s: string to search
   cpszSrch: a list of characters to search for

Return Value:
   The index into the string s of the first occurrence of any of the
   characters in cpszSrch. If no match is found, then index of the
   terminating NUL character is returned.

See Also:
   std_strspn, std_strchr, std_strchrs

=======================================================================

std_strspn()

Description:
   The std_strspn() functions searches s, a NUL-terminated string, for
   the first occurrence of a character that matches none of the
   characters in cpszSrch, a NUL-terminated list of characters. This
   function returns the length of the longest initial substring of s
   which consists of characters present in cpszSrch.

Prototype:

   int std_strspn(const char* s, const char* cpszSrch);

Parameters:
   s: string to search
   cpszSrch: a list of characters to search for

Return Value:
   The index into the string s of the first occurrence of any character
   that matches none of the characters in cpszSrch. If all characters
   in s are present in cpszSrch, the index of the terminating NUL
   character is returned.

See Also:
   std_strcspn, std_strchr, std_strchrs

=======================================================================

std_wstrlcpy()

Description:

   The std_wstrlcpy() function copies a string.  It is equivalent to
   str_strlcpy() except that it operates on wide (16-bit) character strings.
   See std_strlcpy() for details.


Prototype:

   int std_wstrlcpy(AECHAR *pcDest, const AECHAR *pszSrc, int nDestSize);

Parameters:
   pcDst: destination string
   pszSrc: source string
   int nDestSize: size of pcDest __in AECHARs__

Return Value:
   Returns the length of the string (in AECHARs) it tried to create,
   which is same as length of pszSrc.

   Example:

   {
      AECHAR buf[64];
      if (std_wstrlcpy(buf, file_name, STD_ARRAY_SIZE(buf)) >=
          STD_ARRAY_SIZE(buf)) {
         //Truncated -- Handle overflow....
      }
   }

See Also:
   std_wstrlcat

=======================================================================

std_wstrlcat()

Description:

   The std_wstrlcat() function concatenates two strings.  It is equivalent to
   std_strlcat() except that it operates on wide (16-bit) character strings.
   See std_strlcat() for more information.

Prototype:
   int std_wstrlcat(AECHAR *pcDst, const AECHAR *pszSrc, int nDestSize)

Parameters:
   pcDst[out]: Destination string
   pcSrc :     Source string
   nDestSize:  Size of the destination buffer in AECHARs

Return Value:
   Returns the length of the string (in AECHARs) it tried to create,
   which is same as length of pszSrc + the length of pszDest.

   Example:

   {
      char buf[64];
      if (std_wstrlcat(buf, file_name, STD_ARRAY_SIZE(buf)) >=
          STD_ARRAY_SIZE(buf)) {
         //Truncated -- Handle overflow....
      }
   }

See Also:
   std_wstrlcpy

=======================================================================

std_wstrncmp()

Description:

   The std_wstrncmp() function compares up to a specified number of bytes
   in two NUL-terminated strings. It is equivalent to std_strncmp() except
   that it operates on wide (16-bit) character strings.

Prototype:
   int std_wstrncmp(const AECHAR* s1, const AECHAR* s2, int nLen);

Parameters:
   s1, s2: strings to compare
   n: maximum number of AECHARs to compare.  if either s1 or s2 is
      shorter than n, the function terminates there.

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

See Also:
   std_strncmp

=======================================================================

std_wstrcmp()

Description:
   The std_wstrcmp() compares two NUL-terminated strings. It is equivalent
   to std_strncmp() except that it operates on wide (16-bit) character
   strings. Comparison is strictly by byte values with no character set
   interpretation.

Prototype:

   int std_wstrcmp(const AECHAR* s1, const AECHAR* s2);

Parameters:
   s1, s2: strings to compare

Return Value:
   0 if strings are the same ~
   < 0 if s1 is less than s2 ~
   > 0 if s1 is greater than s2

See Also:
   std_strcmp

=======================================================================

std_wstrchr()

Description:
   This function is the wide string counterpart of std_strchr().
   The std_wstrchr() finds the first occurrence of a character in a
   NUL-terminated wide (16-bit) character string.

Prototype:

   AECHAR* std_wstrchr(const AECHAR* s, AECHAR ch);

Parameters:
   s: string to search
   ch: char to search for

Return Value:
   pointer to first occurrence, NULL if not found

See Also:
   std_strchr

=======================================================================

std_wstrrchr()

Description:
   This function is the wide string counterpart of std_strrchr().
   The std_wstrrchr() finds the last occurrence of a character in a
   NUL-terminated wide (16-bit) character string.

Prototype:

   AECHAR* std_wstrrchr(const AECHAR* s, AECHAR ch);

Parameters:
   s: string to search
   ch: char to search for

Return Value:
   pointer to last occurrence, NULL if not found

See Also:
   std_strrchr

=======================================================================

std_makepath()

Description:
   The std_makepath() constructs a path from a directory portion and a file
   portion, using forward slashes, adding necessary slashes and deleting extra
    slashes.  This function guarantees NUL-termination of pszDest

Prototype:

   int std_makepath(const char *cpszDir, const char *cpszFile,
                    char *pszDest, int nDestSize)

Parameters:
   cpszDir: directory part
   cpszFile: file part
   pszDest: output buffer
   nDestSize: size of output buffer in bytes

Return Value:
   the required length to construct the path, not including
   NUL-termination

Comments:
   The following list of examples shows the strings returned by
   std_makepath() for different paths.

Example:

   cpszDir  cpszFile  std_makepath()
   ""        ""           ""
   ""        "/"          ""
   "/"       ""           "/"
   "/"       "/"          "/"
   "/"       "f"          "/f"
   "/"       "/f"         "/f"
   "d"       "f"          "d/f"
   "d/"      "f"          "d/f"
   "d"       "/f"         "d/f"
   "d/"      "/f"         "d/f"

See Also:
   std_splitpath

=======================================================================

std_splitpath()

Description:
   The std_splitpath() finds the filename part of a path given an inclusive
   directory, tests for cpszPath being in cpszDir. The forward slashes are
   used as directory delimiters.

Prototype:

   char *std_splitpath(const char *cpszPath, const char *cpszDir);

Parameters:
   cpszPath: path to test for inclusion
   cpszDir: directory that cpszPath might be in

Return Value:
   the part of cpszPath that actually falls beneath cpszDir, NULL if
   cpszPath is not under cpszDir

Comments:
   The std_splitpath() is similar to std_strbegins(), but it ignores trailing
   slashes on cpszDir, and it returns a pointer to the first character of
   the subpath.

   The return value of std_splitpath() will never begin with a '/'.

   The following list of examples shows the strings returned by
   std_splitpath() for different paths.

Example:
   cpszPath cpszDir  std_splitpath()
   ""        ""           ""
   ""        "/"          ""
   "/"       ""           ""
   "/"       "/"          ""
   "/d"      "d"          null
   "/d"      "/"          "d"
   "/d/"     "/d"         ""
   "/d/f"    "/"          "d/f"
   "/d/f"    "/d"         "f"
   "/d/f"    "/d/"        "f"

See Also:
   std_makepath

=======================================================================

std_cleanpath()

Description:
   The std_cleanpath() removes double slashes, ".", and ".." from
   slash-delimited paths,. It operates in-place.

Prototype:

   char *std_cleanpath(char *pszPath);

Parameters:
   pszPath[in/out]: path to "clean"

Return Value:
   pszPath

Comments:
   Passing an "fs:/" path to this function may produce undesirable
   results.  This function assumes '/' is the root.

Examples:
       pszPath  std_cleanpath()
         "",           "",
         "/",          "/",

         // here"s, mostly alone
         "./",         "/",
         "/.",         "/",
         "/./",        "/",

         // "up"s, mostly alone
         "..",         "",
         "/..",        "/",
         "../",        "/",
         "/../",       "/",

         // fun with x
         "x/.",        "x",
         "x/./",       "x/",
         "x/..",       "",
         "/x/..",      "/",
         "x/../",      "/",
         "/x/../",     "/",
         "/x/../..",   "/",
         "x/../..",    "",
         "x/../../",   "/",
         "x/./../",    "/",
         "x/././",     "x/",
         "x/.././",    "/",
         "x/../.",     "",
         "x/./..",     "",
         "../x",       "/x",
         "../../x",    "/x",
         "/../x",      "/x",
         "./../x",     "/x",

         // double slashes
         "//",         "/",
         "///",        "/",
         "////",       "/",
         "x//x",       "x/x",


Side Effects:
   None

See Also:
   None


=======================================================================

std_basename()

Description:
   The std_basename() returns the filename part of a string,
   assuming '/' delimited filenames.

Prototype:

   char *std_basename(const char *cpszPath);

Parameters:
   cpszPath: path of interest

Return Value:
   pointer into cpszPath that denotes part of the string immediately
   following the last '/'

Examples:
     cpszPath       std_basename()
         ""            ""
         "/"           ""
         "x"           "x"
         "/x"          "x"
         "y/x"         "x"
         "/y/x"        "x"

 See Also:
    None

=======================================================================

std_rand_next()

Description:
  The std_rand_next() generates pseudo-random bytes.

Prototype:

   unsigned std_rand_next(unsigned uRand);

Parameters:
   uRand: a seed for the pseudo-random generator

Return Value:
   the next value in the generator from uRand

Comments:
   for best results, this function should be called with its last
   generated output.

   This is an example of code to generate 256 bytes of pseudo-random data.

   This is not crypto quality and should not be used for key generation
   and the like.

Example:
   {
       unsigned rand_buf[256/sizeof(unsigned)];
       int      i;
       unsigned uLast = std_rand_next(uCurrentTime);
       for (i = 0; i < STD_ARRAY_SIZE(rand_buf); i++) {
          rand_buf[i] = (uLast = std_rand_next(uLast));
       }
   }

See Also:
   std_rand()

=======================================================================

std_rand()

Description:
  The std_rand() functions generates pseudo-random bytes and places it
  in an output buffer of specified size.

Prototype:

   uint32 std_rand(uint32 uSeed, byte* pDest, int nSize);

Parameters:
   uSeed: A seed for the pseudo-random generator
   pDest: The output buffer where the random bytes are placed.
   nSize: The size in bytes of pDest.

Return Value:
   The new seed value that can be used in a subsequent call to
   std_rand().

Comments:

   std_rand() is a linear congruent psuedo-random number generator that
   is seeded using the input seed. This makes the ouput predictable if
   you can determine (or influence) the seed value used. Furthermore,
   the random sequence of bytes generated by two different calls to this
   function will be identical if both the calls use the same seed value.

   This is not crypto quality and should not be used for key generation
   and other cryptographic uses.

See Also:
   std_rand_next()

=======================================================================

std_CopyLE()

Description:

   The std_CopyLE() function copies data while translating numeric values
   between host byte ordering and "little endian" byte ordering.

   pvDest and pvSrc are NOT required to be 16 or 32-bit word aligned.

   Behavior is undefined when the destination and source arrays overlap,
   except in the special case where pvDest and pvSrc are equal.  In that case,
   std_CopyLE() modifies the buffer in-place.

   When the target byte ordering (little endian) matches the host byte
   ordering, in-place translations reduce to a no-op, and copies are
   delegated directly to std_memmove().


Prototype:
   int std_CopyLE(void *pvDest, int nDestSize,
                  const void *pvSrc,  int nSrcSize,
                  const char *pszFields);

Parameters:
   pvDest:    Pointer to destination buffer.
   nDestSize: Size of the destination buffer.
   pvSrc:     Pointer to buffer containing source data.
   nSrcSize:  Size of source data.
   pszFields: Description of the fields that comprise the source data.

              Each field size is given by a positive decimal integer or one of
              the following characters: "S", "L", "Q", or "*".  The letters
              denote fields that should be converted to the desired byte
              ordering:

===pre>
                S : a 2 byte (16 bit) value.
                L : a 4 byte (32 bit) value.
                Q : a 8 byte (64 bit) value.
===/pre>

              An integer gives a number of bytes and "*" represents the
              remainder of the pvSrc[] buffer.  No reordering is performed on
              data in these fields.

              Comparisons are case-sensitive.  Behavior is undefined when
              other characters are supplied in pszFields.

              For example: "L12S*" would be appropriate to copy a structure
              containing a uint32 followed by a 12 byte character array,
              followed by a uint16, followed by an arbitrary amount of
              character data.

              If nSrcSize is greater than the structure size (total of all the
              sizes in pszFields[]) then pvSrc[] is treated as an array of
              structures, each of which is described by pszFields.

Return Value:

   The number of bytes actually copied or translated in-place.  This will be
   the smaller of nDestSize and nSrcSize, or zero if one of them are negative.


=======================================================================

std_CopyBE()

Description:

   The std_CopyBE() function has the same semantics as std_CopyLE() except it
   copies between host byte ordering and big-endian ("network") byte order.

   See std_CopyLE() for more details.


Prototype:
   void *std_CopyBE(void *pvDest, const void *pvSrc,
                           int cbDest, int nItems, const char *pszFields);

Parameters:
   pvDest:    Pointer to destination buffer.
   nDestSize: Size of the destination buffer.
   pvSrc:     Pointer to buffer containing source data.
   nSrcSize:  Size of source data.
   pszFields: Description of the fields that comprise the source data,
              as defined in std_CopyLE.

Return Value:

   The number of bytes actually copied or translated in-place.  This will be
   the smaller of nDestSize and nSrcSize, or zero if one of them are negative.

=======================================================================

std_swapl()

Description:
   The std_swapl() changes endianness of an unsigned long.

Prototype:

   unsigned long std_swapl(unsigned long ul)

Parameters:
   ul: input unsigned long

Return Value:
   ul, reversed in byte-ordering

=======================================================================

std_swaps()

Description:
   The std_swaps() changes endianness of an unsigned short.

Prototype:

   unsigned short std_swaps(unsigned short us)

Parameters:
   us: input unsigned short

Return Value:
   us, reversed in byte-ordering

=======================================================================

std_letohs()

Description:
   The std_letohs() changes a short from little-endian to host byte order.

Prototype:

   unsigned short std_letohs(unsigned short us)

Parameters:
   us: short to convert

Return Value:
   us converted from little-endian to host byte order.  If the
     host is little endian, just returns us

=======================================================================

std_htoles()

Description:
   The std_htoles() converts a short from host byte-order to little-endian.

Prototype:

   unsigned short std_htoles(unsigned short us)

Parameters:
   us: short to convert

Return Value:
   us converted from host byte order to little-endian.  If the
   host is little endian, just returns us

=======================================================================

std_letohl()

Description:
   The std_letohl() changes a long from little-endian to host byte order.

Prototype:

   unsigned long std_letohl(unsigned long ul)

Parameters:
   ul: long to convert

Return Value:
   ul converted from little-endian to host byte order.  If the
   host is little endian, just returns ul

=======================================================================

std_htolel()

Description:
   The std_htolel() converts a long from host byte-order to little-endian.

Prototype:

   unsigned long std_htolel(unsigned long ul)

Parameters:
   ul: long to convert

Return Value:
   ul converted from host byte order to little-endian.  If the
   host is little endian, just returns ul.


=======================================================================

std_ntohs()

Description:
   The std_ntohs() changes a short from big-endian to host byte order.

Prototype:

   unsigned short std_ntohs(unsigned short us)

Parameters:
   us: short to convert

Return Value:
   us converted from big-endian to host byte order.  If the
   host is big endian, just returns us.

=======================================================================

std_htons()

Description:
   The std_htons() converts a short from host byte-order to big-endian.

Prototype:

   unsigned short std_htons(unsigned short us)

Parameters:
   us: short to convert

Return Value:
   us converted from host byte order to big-endian.  If the
   host is big endian, just returns us.

=======================================================================

std_ntohl()

Description:
   The std_ntohl() changes a long from big-endian to host byte order.

Prototype:

   unsigned long std_ntohl(unsigned long ul)

Parameters:
   ul: long to convert

Return Value:
   ul converted from big-endian to host byte order.  If the
   host is big endian, just returns ul.

=======================================================================

std_htonl()

Description:
   The std_htonl() converts a long from host byte-order to big-endian.

Prototype:

   unsigned long std_htonl(unsigned long ul)

Parameters:
   ul: long to convert

Return Value:
   ul converted from host byte order to big-endian.  If the
   host is big endian, just returns ul.


=======================================================================

std_strlprintf()

Description:

   The functions std_strlprintf() and std_vstrlprintf() write formatted
   output to a string.  These functions guarantee NUL-termination of
   the output buffer when its size is greater than zero.

   A format string is copied to the output buffer, except for conversion
   specifiers contained within the format string.  Conversion specifiers
   begin with a "%" and specify some action that consumes an argument from
   the argument list.

   Conversion specifiers have the following form:
===pre>
       %[FLAGS] [WIDTH] [.PRECISION] [TYPE] CONV
===/pre>

   CONV is the only required field.  It is always a single character,
   and determines the action to be taken.  Supported values are:

===pre>
    CONV | Description
   ======|=======================================================
     c   | Output a single character.
         |
     s   | Output a NUL-terminated single-byte character string.
         |
    d, i | Ouptut a signed decimal integer.
         |
     u   | Output an unsigned decimal integer.
         |
     o   | Output an unsigned octal integer.
         |
     x   | Output an unsigned hexadecimal integer, using
         | lower case digits.
         |
     X   | Output an unsigned hexadecimal integer, using
         | upper case digits.
         |
     p   | Output a pointer value as eight hexadecimal digits,
         | using upper case digits.
===/pre>

   The next argument from the argument list supplies the value to be
   formatted and output.

   FLAGS, WIDTH, and PRECISION can modify the formatting of the value.

   FLAGS consists of one or more of the following characters:

===pre>
   Flag | Meaning
   =====|=================================================================
     +  | Prefix positive numbers with "+" (%d and %i only).
   -----|-----------------------------------------------------------------
     -  | When padding to meet WIDTH, pad on the right.
   -----|-----------------------------------------------------------------
     0  | Pad with '0' characters when padding on the left to meet WIDTH.
   -----|-----------------------------------------------------------------
   blank| Prefix positive numbers with " " (%d and %i only).
   space|
   -----|-----------------------------------------------------------------
     #  | With %x or %X: prefixes non-zero values with "0x"/"0X".
        | With %o, ensure the value begins with "0" (increasing PRECISION
        |    if necessary).
        | Ignored for all other CONV specifiers.
   -----|-----------------------------------------------------------------
===/pre>

   WIDTH is an unsigned decimal integer or the character "*".

   WIDTH gives the minimum number of characters to be written.  The
   formatted value will be padded with spaces until the minimum size is
   met; it never causes a value to be truncated The sign of the WIDTH
   integer selects between left and right padding.  Padding will be on
   the left unless the "-" flag is specified.

   When "*" is used, an 'int' argument is consumed from the argument
   list and used as the WIDTH.  A negative argument specifies padding on
   the right, and its absolute value gives the amount of padding.

   If the "0" flags is specified, any padding on the left will consist
   of "0" characters.  An exception to this rule is that the "0" flag is
   ignored when precision is specified for a numeric value.

   PRECISION is a non-negative decimal integer or "*" preceded by ".".

   When PRECISION accompanies any of the numeric conversions, it
   specifies the minimum number of digits to output.  Values are padded
   on the left with '0' to meet the specified size.  PRECISION defaults
   to 1 for numbers.

   When PRECISION accompanies other conversions, it specifies the
   maximum number of characters from the value to output.  The value
   will be truncated to ensure that at most PRECISION characters are
   output.

   TYPE provides information about the type of arguments.  This is used
   to determine the size of integer arguments. Values larger than 'int'
   can be properly obtained from the argument list.  Their behavior
   should be considered undefined for CONV operations other than integer
   formatting.

===pre>
    TYPE  | Meaning
   =======|=====================
     hh   | sizeof(char)
   -------|---------------------
      h   | sizeof(short)
   -------|---------------------
      l   | sizeof(long)
   -------|---------------------
    L, ll | sizeof(long long)
   -------|---------------------
      j   | sizeof(int64)
   -------|---------------------
      z   | sizeof(size_t)
   -------|---------------------
===/pre>

   For 64-bit integers, "ll" may be the most widely-supported type
   specifier in other printf implementation, but "j" has been introduced
   in ISO C99. This implementation supports both.

   Note that arguments to variadic functions are promoted to 'int' when
   smaller than 'int', so 'h' and 'hh' have no observable effect.
   Static analysis tools that understand standard format string syntax
   may use this information for other purposes.

Prototype:

   int std_strlprintf(char *pszDest, int nDestSize,
                      const char *pszFmt, ...);
Parameters:
   pszDest [out]: output buffer, where output will be placed
   nDestSize:     size of pszDest in bytes
   pszFmt:        format string

Return Value:

   The size required to hold the entire untruncated output, NOT
   including NUL-termination.

Comments:

   Notable omissions from std_strlprintf() are lack of support for
   floating point and lack of support for "%n".

Side Effects:
   None

See Also:
   None

=======================================================================

std_vstrlprintf()

Description:

  The std_vstrlprintf() is documented with std_strlprintf(), it's the
  vector form of std_strlprintf().  See std_strlprintf() for a
  more complete description.

Prototype:
   int std_vstrlprintf(char *pszDest, int nDestSize,
                       const char *pszFmt, AEEVaList args);

Parameters:
   pszDest [out]: output buffer, where output will be placed
   nDestSize:     size of pszDest in bytes
   pszFmt:        format string
   args:          arguments


=======================================================================

std_snprintf()

Description:

   The functions std_snprintf() and std_vsnprintf() are similar to
   std_strlprintf and std_vstrlprintf that write formatted output to a
   string. Unlike std_strlprintf, std_snprintf also support the floating
   point conversion specifiers. These functions guarantee NUL-termination
   of the output buffer when its size is greater than zero.

   A format string is copied to the output buffer, except for conversion
   specifiers contained within the format string.  Conversion specifiers
   begin with a "%" and specify some action that consumes an argument from
   the argument list.

   Conversion specifiers have the following form:
===pre>
       %[FLAGS] [WIDTH] [.PRECISION] [TYPE] CONV
===/pre>

   CONV is the only required field.  It is always a single character,
   and determines the action to be taken.  For a detailed description of
   conversion sepcifiers, please refer to the documentation of
   std_strlprintf(). Here. we only provide description of these fields
   as it applies to the additional CONV values supported by
   std_snprintf().

   In addition to the values for CONV supported by std_strlprintf, this
   function supports the following values:

===pre>
    CONV | Description
   ======|=======================================================
    e, E | Outputs a double value representing a floating point
         | number in the style [-]d.ddd e±dd, where there is one
         | digit (which is nonzero if the argument is nonzero)
         | before the decimal-point character and the number of
         | digits after it is equal to the precision. If the
         | precision is missing, it is taken as 6. If the precision
         | is zero and the # flag is not specified, no decimal-point
         | character appears. The value is rounded to the appropriate
         | number of digits. The E conversion specifier produces a
         | number with E instead of e introducing the exponent. The
         | exponent always contains at least two digits, and only as
         | many more digits as necessary to represent the exponent.
         | If the value is zero, the exponent is zero.
         |
    f, F | Outputs a double value representing a floating point
         | number in the style [-]ddd.ddd, where the number of
         | digits after the decimal-point character is equal to the
         | precision specification. If the precision is missing, it
         | is taken as 6. If the precision is zero and the # flag is
         | not specified, no decimal-point character appears. If a
         | decimal-point character appears, at least one digit
         | appears before it. The value is rounded to the appropriate
         | number of digits.
         |
    g, G | Outputs a double value representing a floating point
         | number in the style f or e (or in style F or E in the case
         | of a G conversion specifier), with the precision specifying
         | the number of significant digits. If the precision is zero,
         | it is taken as 1. The style used depends on the value
         | converted. Style e (or E) is used only if the exponent
         | resulting from such a conversion is less than -4 or greater
         | than or equal to the precision. Trailing zeros are removed
         | from the fractional portion of the result unless the # flag
         | is specified; a decimal-point character appears only if it
         | is followed by a digit.
         |
    a, A | Outputs a double value representing a floating point
         | number in the style [-]0xh.hhhh p±d, where there is one
         | non-zero hexadecimal digit before the decimal-point
         | character and the number of hexadecimal digits after it is
         | equal to the precision. If the precision is missing then
         | the precision is assumed to be sufficient for an exact
         | representation of the value, except that trailing zeros
         | may be omitted. If the precision is zero and the # flag is
         | not specified, no decimal point character appears. The
         | letters 'abcdef' are used for '%a' conversion and the
         | letters ABCDEF for '%A' conversion. The '%A' conversion
         | specifier produces a number with 'X' and 'P' instead of 'x'
         | and 'p'. The exponent always contains at least one digit,
         | and only as many more digits as necessary to represent the
         | decimal exponent of 2. If the value is zero, the exponent
         | is zero.
         |
===/pre>

   For 'e', 'f', 'g' and 'a' convervsion specifiers, a double argument
   representing an infinity is converted in to the style '[-]inf' and
   a double argument representing a NaN is converted in to the stlye
   'nan'. The 'E', 'F', 'G' and 'A' conversion specifiers result in
   'INF' or 'NAN' instead of 'inf' or 'nan', respectively.

Prototype:

   int std_snprintf(char *pszDest, int nDestSize,
                    const char *pszFmt, ...);
Parameters:
   pszDest [out]: output buffer, where output will be placed
   nDestSize:     size of pszDest in bytes
   pszFmt:        format string

Return Value:

   The size required to hold the entire untruncated output, NOT
   including NUL-termination.

Comments:

   Notable omissions from std_strlprintf() lack of support for "%n".

Side Effects:
   None

See Also:
   std_strlprintf()

=======================================================================

std_vsnprintf()

Description:

  The std_vsnprintf() is documented with std_snprintf(), it's the
  vector form of std_snprintf(). See std_snprintf() for a more complete
  description.

Prototype:
   int std_vsnprintf(char *pszDest, int nDestSize,
                     const char *pszFmt, AEEVaList args);

Parameters:
   pszDest [out]: output buffer, where output will be placed
   nDestSize:     size of pszDest in bytes
   pszFmt:        format string
   args:          arguments


=======================================================================

std_scanul()

Description:

    The std_scanul() converts an ASCII representation of a number to an unsigned
    long.  It expects strings that match the following pattern:
===pre>
         spaces [+|-] digits
===/pre>

    'Spaces' is zero or more ASCII space or tab characters.

    'Digits' is any number of digits valid in the radix.  Letters 'A' through
    'Z' are treated as digits with values 10 through 35.  'Digits' may begin
    with "0x" when a radix of 0 or 16 is specified.

    Upper and lower case letters can be used interchangeably.


Prototype:

    uint32 std_scanul( const char *pchBuf, int nRadix, const char **ppchEnd,
                       int *pnError)

Parameters:

    pchBuf [in] : the start of the string to scan.

    nRadix [in] : the numeric radix (or base) of the number.  Valid values are
                  2 through 36 or zero, which implies auto-detection.
                  Auto-detection examines the digits field.  If it begins with
                  "0x", radix 16 is selected.  Otherwise, if it begins with
                  "0" radix 8 is selected.  Otherwise, radix 10 is selected.

    ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
                    character that did not match the expected pattern shown
                    above, except on STD_BADPARAM and STD_OVERFLOW when it is
                    set to the start of the string.

    pnError [out] : If pnError is not NULL, *pnError holds the error code,
                    which is one of the following:
~
        0 : Numeric value is from 0 to MAX_UINT32.

        STD_NEGATIVE : The scanned value was negative and its absolute value was
                       from 1 to MAX_UINT32.  The result is the negated value
                       (cast to a uint32).

        STD_NODIGITS : No digits were found.  The result is zero.

        STD_OVERFLOW : The absolute value exceeded MAX_UINT32.  The result
                       is set to MAX_UINT32 and *ppchEnd is set to pchBuf.

        STD_BADPARAM : An improper value for nRadix was received.  The result
                       is set to zero, and *ppchEnd is set to pchBuf.
*

Return Value:

    The converted numeric result.

Comments:

   The std_scanul() is similar to ANSI C's strtoul() but differs in the following
   respects:

     1. It returns an error/success code.  strtoul() results are ambiguous
        unless the caller sets errno to zero before calling it.

     2. std_scanul() is free of references to current locale and errno.  Some
        strtoul() implementations use locale; some don't.

     3. It provides more complete reporting of range underflow.  strtoul()
        does not distinguish between "-1" and "0xFFFFFFFF", and underflow is
        poorly defined.

     4. std_scanul() reports a "no digits" error code to distinguish "0" from
        whitespace, "+", etc..

See Also:

   std_scanull()

=======================================================================

std_scanull()

Description:

    The std_scanull() converts an ASCII representation of a number to an
    unsigned long long.  It expects strings that match the following pattern:
===pre>
         spaces [+|-] digits
===/pre>

    'Spaces' is zero or more ASCII space or tab characters.

    'Digits' is any number of digits valid in the radix.  Letters 'A' through
    'Z' are treated as digits with values 10 through 35.  'Digits' may begin
    with "0x" when a radix of 0 or 16 is specified.

    Upper and lower case letters can be used interchangeably.


Prototype:

    uint64 std_scanull(const char *pchBuf, int nRadix, const char **ppchEnd,
                       int *pnError)

Parameters:

    pchBuf [in] : the start of the string to scan.

    nRadix [in] : the numeric radix (or base) of the number.  Valid values are
                  2 through 36 or zero, which implies auto-detection.
                  Auto-detection examines the digits field.  If it begins with
                  "0x", radix 16 is selected.  Otherwise, if it begins with
                  "0" radix 8 is selected.  Otherwise, radix 10 is selected.

    ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
                    character that did not match the expected pattern shown
                    above, except on STD_BADPARAM and STD_OVERFLOW when it is
                    set to the start of the string.

    pnError [out] : If pnError is not NULL, *pnError holds the error code,
                    which is one of the following:
~
        0 : Numeric value is from 0 to MAX_UINT64.

        STD_NEGATIVE : The scanned value was negative and its absolute value was
                       from 1 to MAX_UINT64.  The result is the negated value
                       (cast to a uint64).

        STD_NODIGITS : No digits were found.  The result is zero.

        STD_OVERFLOW : The absolute value exceeded MAX_UINT64.  The result
                       is set to MAX_UINT64 and *ppchEnd is set to pchBuf.

        STD_BADPARAM : An improper value for nRadix was received.  The result
                       is set to zero, and *ppchEnd is set to pchBuf.
*

Return Value:

    The converted numeric result.

Comments:

   The std_scanull() is similar to ANSI C's strtoull() but differs in the following
   respects:

     1. It returns an error/success code.  strtoull() results are ambiguous
        unless the caller sets errno to zero before calling it.

     2. std_scanull() is free of references to current locale and errno.  Some
        strtoull() implementations use locale; some don't.

     3. It provides more complete reporting of range underflow.  strtoul()
        does not distinguish between "-1" and "0xFFFFFFFFFFFFFFFF", and underflow
        is poorly defined.

     4. std_scanull() reports a "no digits" error code to distinguish "0" from
        whitespace, "+", etc..

See Also:

   std_scanul()

=======================================================================

std_qsort()

Description:

  An implementation of the quicksort algorithm, a massively recursive,
  in-place sorting algorithm for an array.

  The contents of the array are sorted in ascending order according to
  the comparison function pointed to by pfnCompare.

  pfnCompare must return a value less than, equal to, or
  greater than zero if the first argument is considered to be
  less than, equal to, or greater than the second, respectively.

  std_qsort() is not a stable sort.

Prototype:
   void std_qsort(void* pElems, int nNumElems, int nElemWidth,
                  int (*pfnCompare)(void*, const void*, const void*),
                  void* pCompareCx);


Parameters:
   pElems: array of elements to be sorted in place.  It's size
           must be nNumElems * nElemWidth in bytes.
   nNumElems: number of elements in pElems
   nElemWidth: the width, in bytes of each element of pElems
   pfnCompare: callback comparison function, should return 0, less than
               zero or greater than zero if the left comparand is equal to, less
               than, or greater than, the right comparand, respectively.
   pCompareCx: the context passed as the first parameter by pfnCompare

Return Value:
   None

Comments:
   If nElemWidth is 2, 4, or 8, pElems is accessed internally as
   integer values for the purposes of reading and writing elements.
   Therefore, pElems must be aligned on a memory boundary compatible
   with integer access of the array elements.  I.e. if you pass 4 as
   nElemWidth, *(int*)pElems must succeed.

=======================================================================

std_bisect()

Description:

   Find an element in a sorted array of elements.  Uses a binary
   search.

Prototype:
   int std_bisect(const void* pElems, int nNumElems, int nElemWidth,
                  const void* pElemFind,
                  int (*pfnCompare)(void*, const void*, const void*),
                  void* pCompareCx);

Parameters:
   pElems: array of elements to be searched.  It's size
           must be nNumElems * nElemWidth in bytes.
   nNumElems: number of elements in pElems
   nElemWidth: the width, in bytes of each element of pElems
   pElemFind: the element value to find in the array
   pfnCompare: callback comparison function, should return 0, less than
               zero or greater than zero if the left comparand is equal to, less
               than, or greater than, the right comparand, respectively.
   pCompareCx: the context passed as the first parameter by pfnCompare

Return Value:
   index of the element such that pElems[index] <= elem < pElems[index + 1]
   nNumElems if elem is greater than all the elements in the list
   0 if the elem is less than or equal to the all the elements in the list

=======================================================================

std_merge()

Description:

   Merge two sorted arrays into another array.

Prototype:
   void std_merge(void* vpDst, int nDst,
                  const void* vpA, int nA,
                  const void* vpB, int nB,
                  int nElemWidth,
                  int (*pfnCompare)(void*, const void*, const void*),
                  void* pCompareCx);

Parameters:
   vpDst: destination array.  It's size must be nDst * nElemWidth in bytes.
   nDst: number of elements that vpDst can accomodate
   vpA: array of elements to be merged,  it's size must be nA * nElemWidth
         in bytes.
   nA: number of elements in vpA
   vpB: array of elements to be merged,  it's size must be nB * nElemWidth
         in bytes.
   nB: number of elements in vpB
   nElemWidth: the width, in bytes of each element of pElems
   pfnCompare: callback comparison function, should return 0, less than
               zero or greater than zero if the left comparand is equal to, less
               than, or greater than, the right comparand, respectively.
   pCompareCx: the context passed as the first parameter by pfnCompare

Return Value:
  none

=======================================================================

std_uniq()

Description:
   Removes duplicate entries from a sorted array.

Prototype:
   int std_uniq(void* vpElems, int nNumElems, int nElemWidth,
                int (*pfnCompare)(void*, const void*, const void*),
                void* pCompareCx);

Parameters:
   pElems: array of elements to be searched.  It's size
           must be nNumElems * nElemWidth in bytes.
   nNumElems: number of elements in pElems
   nElemWidth: the width, in bytes of each element of pElems
   pfnCompare: callback comparison function, should return 0, less than
               zero or greater than zero if the left comparand is equal to, less
               than, or greater than, the right comparand, respectively.
   pCompareCx: the context passed as the first parameter by pfnCompare

Return Value:
   the number of uniq elements left in vpElems

=======================================================================

std_scand()

Description:

   The std_scand() converts the initial portion of an input ASCII string
   to it's corresponding floating point value. It expects the input
   string to match the following pattern:
===pre>
         <Spaces><Subject String><Rest Of The String>
===/pre>

   'Spaces' - is zero or more ASCII space or tab characters.
   'Subject String' - is the part of the input string that represents a
                      valid floating point constant.
   'Rest Of The String' - is the remaining sequence of one or more
                          characters including the terminating null
                          character of the input string.

   A valid subject string can be one of the following:
      -- <NAN>, ignoring case. This is interpreted as a quiet NAN.
      -- [+|-]<INF|INFINITY>, ignoring case. This is interpreted as an
         infinity.
      -- [+|-]<Valid Floating Point Number>

   In general, a valid floating poing number can either be a decimal
   number or an hexadecimal number, and has the following form:
      <Integral Part>[.[<Fractional Part>]][<Exponent>]
   where the intergral, fractional and the exponent part may consist of
   sequence of valid decimal or hexadecimal digits. More specifically:

   For a decimal floating point number:
      'Integral Part' - <Decimal Digits>
      'Fractional Part' - <Decimal Digits>
      'Exponent' - <e|E><Decimal Digits>
   For a hexadecimal floating point number:
      'Integral Part' - <Hexadecimal Digits>
      'Fractional Part' - <Hexadecimal Digits>
      'Exponent' - <p|P><Decimal Digits>

   where:
      'Decimal Digits' - is any number of digits in the range [0,10].
      'Hexadecimal Digits' - is any number of digits in the range [0,10]
                             or the alphabets A through F.
      'e','E','p','P' - represent the exponent characters

Prototype:

    double std_scand(const char *pchBuf, const char **ppchEnd);

Parameters:

    pchBuf [in] : the start of the string to scan.

    ppchEnd [out] : if ppchEnd is not NULL, *ppchEnd points to the first
                    character after the parsed number.

Return Value:

    This function returns the converted numeric result. If the string
    does not contain a valid floating point number then the function
    returns zero. If the converted value is outside the range of
    representable values (overflow), [-]INFINITY is
    returned. In case of an underflow, the function returns zero.

=======================================================================*/

#endif // AEESTD_H