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
|
/* Copyright (C) 2002 Manuel Novoa III
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
*
* Besides uClibc, I'm using this code in my libc for elks, which is
* a 16-bit environment with a fairly limited compiler. It would make
* things much easier for me if this file isn't modified unnecessarily.
* In particular, please put any new or replacement functions somewhere
* else, and modify the makefile to use your version instead.
* Thanks. Manuel
*
* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
#define _STDIO_UTILITY
#define _GNU_SOURCE
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#ifdef WANT_WIDE
#include <wchar.h>
#include <wctype.h>
#include <locale.h>
#define Wvoid wchar_t
#define Wchar wchar_t
#define Wuchar __uwchar_t
#define Wint wchar_t
#else
#define Wvoid void
#define Wchar char
typedef unsigned char __string_uchar_t;
#define Wuchar __string_uchar_t
#define Wint int
#endif
/**********************************************************************/
/* NOTE: If we ever do internationalized syserr messages, this will
* have to be changed! */
#if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
#define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
#else
#define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
#endif
#define _SYS_NERR 125
#define _SYS_ERRMSG_MAXLEN 50
extern const char _string_syserrmsgs[];
/**********************************************************************/
#ifdef L__string_syserrmsgs
const char _string_syserrmsgs[] = {
/* 0: 0, 8 */ "Success\0"
/* 1: 8, 24 */ "Operation not permitted\0"
/* 2: 32, 26 */ "No such file or directory\0"
/* 3: 58, 16 */ "No such process\0"
/* 4: 74, 24 */ "Interrupted system call\0"
/* 5: 98, 19 */ "Input/output error\0"
/* 6: 117, 26 */ "No such device or address\0"
/* 7: 143, 23 */ "Argument list too long\0"
/* 8: 166, 18 */ "Exec format error\0"
/* 9: 184, 20 */ "Bad file descriptor\0"
/* 10: 204, 19 */ "No child processes\0"
/* 11: 223, 33 */ "Resource temporarily unavailable\0"
/* 12: 256, 23 */ "Cannot allocate memory\0"
/* 13: 279, 18 */ "Permission denied\0"
/* 14: 297, 12 */ "Bad address\0"
/* 15: 309, 22 */ "Block device required\0"
/* 16: 331, 24 */ "Device or resource busy\0"
/* 17: 355, 12 */ "File exists\0"
/* 18: 367, 26 */ "Invalid cross-device link\0"
/* 19: 393, 15 */ "No such device\0"
/* 20: 408, 16 */ "Not a directory\0"
/* 21: 424, 15 */ "Is a directory\0"
/* 22: 439, 17 */ "Invalid argument\0"
/* 23: 456, 30 */ "Too many open files in system\0"
/* 24: 486, 20 */ "Too many open files\0"
/* 25: 506, 31 */ "Inappropriate ioctl for device\0"
/* 26: 537, 15 */ "Text file busy\0"
/* 27: 552, 15 */ "File too large\0"
/* 28: 567, 24 */ "No space left on device\0"
/* 29: 591, 13 */ "Illegal seek\0"
/* 30: 604, 22 */ "Read-only file system\0"
/* 31: 626, 15 */ "Too many links\0"
/* 32: 641, 12 */ "Broken pipe\0"
/* 33: 653, 33 */ "Numerical argument out of domain\0"
/* 34: 686, 30 */ "Numerical result out of range\0"
/* 35: 716, 26 */ "Resource deadlock avoided\0"
/* 36: 742, 19 */ "File name too long\0"
/* 37: 761, 19 */ "No locks available\0"
/* 38: 780, 25 */ "Function not implemented\0"
/* 39: 805, 20 */ "Directory not empty\0"
/* 40: 825, 34 */ "Too many levels of symbolic links\0"
/* 41: 859, 1 */ "\0"
/* 42: 860, 27 */ "No message of desired type\0"
/* 43: 887, 19 */ "Identifier removed\0"
/* 44: 906, 28 */ "Channel number out of range\0"
/* 45: 934, 25 */ "Level 2 not synchronized\0"
/* 46: 959, 15 */ "Level 3 halted\0"
/* 47: 974, 14 */ "Level 3 reset\0"
/* 48: 988, 25 */ "Link number out of range\0"
/* 49: 1013, 29 */ "Protocol driver not attached\0"
/* 50: 1042, 27 */ "No CSI structure available\0"
/* 51: 1069, 15 */ "Level 2 halted\0"
/* 52: 1084, 17 */ "Invalid exchange\0"
/* 53: 1101, 27 */ "Invalid request descriptor\0"
/* 54: 1128, 14 */ "Exchange full\0"
/* 55: 1142, 9 */ "No anode\0"
/* 56: 1151, 21 */ "Invalid request code\0"
/* 57: 1172, 13 */ "Invalid slot\0"
/* 58: 1185, 1 */ "\0"
/* 59: 1186, 21 */ "Bad font file format\0"
/* 60: 1207, 20 */ "Device not a stream\0"
/* 61: 1227, 18 */ "No data available\0"
/* 62: 1245, 14 */ "Timer expired\0"
/* 63: 1259, 25 */ "Out of streams resources\0"
/* 64: 1284, 30 */ "Machine is not on the network\0"
/* 65: 1314, 22 */ "Package not installed\0"
/* 66: 1336, 17 */ "Object is remote\0"
/* 67: 1353, 22 */ "Link has been severed\0"
/* 68: 1375, 16 */ "Advertise error\0"
/* 69: 1391, 14 */ "Srmount error\0"
/* 70: 1405, 28 */ "Communication error on send\0"
/* 71: 1433, 15 */ "Protocol error\0"
/* 72: 1448, 19 */ "Multihop attempted\0"
/* 73: 1467, 19 */ "RFS specific error\0"
/* 74: 1486, 12 */ "Bad message\0"
/* 75: 1498, 38 */ "Value too large for defined data type\0"
/* 76: 1536, 27 */ "Name not unique on network\0"
/* 77: 1563, 29 */ "File descriptor in bad state\0"
/* 78: 1592, 23 */ "Remote address changed\0"
/* 79: 1615, 39 */ "Can not access a needed shared library\0"
/* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
/* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
/* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
/* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
/* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
/* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
/* 86: 1903, 19 */ "Streams pipe error\0"
/* 87: 1922, 15 */ "Too many users\0"
/* 88: 1937, 31 */ "Socket operation on non-socket\0"
/* 89: 1968, 29 */ "Destination address required\0"
/* 90: 1997, 17 */ "Message too long\0"
/* 91: 2014, 31 */ "Protocol wrong type for socket\0"
/* 92: 2045, 23 */ "Protocol not available\0"
/* 93: 2068, 23 */ "Protocol not supported\0"
/* 94: 2091, 26 */ "Socket type not supported\0"
/* 95: 2117, 24 */ "Operation not supported\0"
/* 96: 2141, 30 */ "Protocol family not supported\0"
/* 97: 2171, 41 */ "Address family not supported by protocol\0"
/* 98: 2212, 23 */ "Address already in use\0"
/* 99: 2235, 32 */ "Cannot assign requested address\0"
/* 100: 2267, 16 */ "Network is down\0"
/* 101: 2283, 23 */ "Network is unreachable\0"
/* 102: 2306, 36 */ "Network dropped connection on reset\0"
/* 103: 2342, 33 */ "Software caused connection abort\0"
/* 104: 2375, 25 */ "Connection reset by peer\0"
/* 105: 2400, 26 */ "No buffer space available\0"
/* 106: 2426, 40 */ "Transport endpoint is already connected\0"
/* 107: 2466, 36 */ "Transport endpoint is not connected\0"
/* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
/* 109: 2548, 35 */ "Too many references: cannot splice\0"
/* 110: 2583, 21 */ "Connection timed out\0"
/* 111: 2604, 19 */ "Connection refused\0"
/* 112: 2623, 13 */ "Host is down\0"
/* 113: 2636, 17 */ "No route to host\0"
/* 114: 2653, 30 */ "Operation already in progress\0"
/* 115: 2683, 26 */ "Operation now in progress\0"
/* 116: 2709, 22 */ "Stale NFS file handle\0"
/* 117: 2731, 25 */ "Structure needs cleaning\0"
/* 118: 2756, 28 */ "Not a XENIX named type file\0"
/* 119: 2784, 30 */ "No XENIX semaphores available\0"
/* 120: 2814, 21 */ "Is a named type file\0"
/* 121: 2835, 17 */ "Remote I/O error\0"
/* 122: 2852, 20 */ "Disk quota exceeded\0"
/* 123: 2872, 16 */ "No medium found\0"
/* 124: 2888, 18 */ "Wrong medium type"
};
#endif
/**********************************************************************/
#ifdef L_sys_errlist
link_warning(_sys_errlist, "sys_nerr and sys_errlist are obsolete and uClibc support for them (in at least some configurations) will probably be unavailable in the near future.")
int sys_nerr = _SYS_NERR;
const char *const sys_errlist[] = {
_string_syserrmsgs + 0,
_string_syserrmsgs + 8,
_string_syserrmsgs + 32,
_string_syserrmsgs + 58,
_string_syserrmsgs + 74,
_string_syserrmsgs + 98,
_string_syserrmsgs + 117,
_string_syserrmsgs + 143,
_string_syserrmsgs + 166,
_string_syserrmsgs + 184,
_string_syserrmsgs + 204,
_string_syserrmsgs + 223,
_string_syserrmsgs + 256,
_string_syserrmsgs + 279,
_string_syserrmsgs + 297,
_string_syserrmsgs + 309,
_string_syserrmsgs + 331,
_string_syserrmsgs + 355,
_string_syserrmsgs + 367,
_string_syserrmsgs + 393,
_string_syserrmsgs + 408,
_string_syserrmsgs + 424,
_string_syserrmsgs + 439,
_string_syserrmsgs + 456,
_string_syserrmsgs + 486,
_string_syserrmsgs + 506,
_string_syserrmsgs + 537,
_string_syserrmsgs + 552,
_string_syserrmsgs + 567,
_string_syserrmsgs + 591,
_string_syserrmsgs + 604,
_string_syserrmsgs + 626,
_string_syserrmsgs + 641,
_string_syserrmsgs + 653,
_string_syserrmsgs + 686,
_string_syserrmsgs + 716,
_string_syserrmsgs + 742,
_string_syserrmsgs + 761,
_string_syserrmsgs + 780,
_string_syserrmsgs + 805,
_string_syserrmsgs + 825,
/* _string_syserrmsgs + 859, */
NULL, /* glibc compatiblity :-( */
_string_syserrmsgs + 860,
_string_syserrmsgs + 887,
_string_syserrmsgs + 906,
_string_syserrmsgs + 934,
_string_syserrmsgs + 959,
_string_syserrmsgs + 974,
_string_syserrmsgs + 988,
_string_syserrmsgs + 1013,
_string_syserrmsgs + 1042,
_string_syserrmsgs + 1069,
_string_syserrmsgs + 1084,
_string_syserrmsgs + 1101,
_string_syserrmsgs + 1128,
_string_syserrmsgs + 1142,
_string_syserrmsgs + 1151,
_string_syserrmsgs + 1172,
/* _string_syserrmsgs + 1185, */
NULL, /* glibc compatiblity :-( */
_string_syserrmsgs + 1186,
_string_syserrmsgs + 1207,
_string_syserrmsgs + 1227,
_string_syserrmsgs + 1245,
_string_syserrmsgs + 1259,
_string_syserrmsgs + 1284,
_string_syserrmsgs + 1314,
_string_syserrmsgs + 1336,
_string_syserrmsgs + 1353,
_string_syserrmsgs + 1375,
_string_syserrmsgs + 1391,
_string_syserrmsgs + 1405,
_string_syserrmsgs + 1433,
_string_syserrmsgs + 1448,
_string_syserrmsgs + 1467,
_string_syserrmsgs + 1486,
_string_syserrmsgs + 1498,
_string_syserrmsgs + 1536,
_string_syserrmsgs + 1563,
_string_syserrmsgs + 1592,
_string_syserrmsgs + 1615,
_string_syserrmsgs + 1654,
_string_syserrmsgs + 1691,
_string_syserrmsgs + 1723,
_string_syserrmsgs + 1771,
_string_syserrmsgs + 1809,
_string_syserrmsgs + 1859,
_string_syserrmsgs + 1903,
_string_syserrmsgs + 1922,
_string_syserrmsgs + 1937,
_string_syserrmsgs + 1968,
_string_syserrmsgs + 1997,
_string_syserrmsgs + 2014,
_string_syserrmsgs + 2045,
_string_syserrmsgs + 2068,
_string_syserrmsgs + 2091,
_string_syserrmsgs + 2117,
_string_syserrmsgs + 2141,
_string_syserrmsgs + 2171,
_string_syserrmsgs + 2212,
_string_syserrmsgs + 2235,
_string_syserrmsgs + 2267,
_string_syserrmsgs + 2283,
_string_syserrmsgs + 2306,
_string_syserrmsgs + 2342,
_string_syserrmsgs + 2375,
_string_syserrmsgs + 2400,
_string_syserrmsgs + 2426,
_string_syserrmsgs + 2466,
_string_syserrmsgs + 2502,
_string_syserrmsgs + 2548,
_string_syserrmsgs + 2583,
_string_syserrmsgs + 2604,
_string_syserrmsgs + 2623,
_string_syserrmsgs + 2636,
_string_syserrmsgs + 2653,
_string_syserrmsgs + 2683,
_string_syserrmsgs + 2709,
_string_syserrmsgs + 2731,
_string_syserrmsgs + 2756,
_string_syserrmsgs + 2784,
_string_syserrmsgs + 2814,
_string_syserrmsgs + 2835,
_string_syserrmsgs + 2852,
_string_syserrmsgs + 2872,
_string_syserrmsgs + 2888,
};
#endif
/**********************************************************************/
#ifdef L_wmemcpy
#define L_memcpy
#define Wmemcpy wmemcpy
#else
#define Wmemcpy memcpy
#endif
#ifdef L_memcpy
Wvoid *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
{
register Wchar *r1 = s1;
register const Wchar *r2 = s2;
#ifdef __BCC__
while (n--) {
*r1++ = *r2++;
}
#else
while (n) {
*r1++ = *r2++;
--n;
}
#endif
return s1;
}
#endif
/**********************************************************************/
#ifdef L_wmemmove
#define L_memmove
#define Wmemmove wmemmove
#else
#define Wmemmove memmove
#endif
#ifdef L_memmove
Wvoid *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
{
#ifdef __BCC__
register Wchar *s = (Wchar *) s1;
register const Wchar *p = (const Wchar *) s2;
if (p >= s) {
while (n--) {
*s++ = *p++;
}
} else {
s += n;
p += n;
while (n--) {
*--s = *--p;
}
}
return s1;
#else
register Wchar *s = (Wchar *) s1;
register const Wchar *p = (const Wchar *) s2;
if (p >= s) {
while (n) {
*s++ = *p++;
--n;
}
} else {
while (n) {
--n;
s[n] = p[n];
}
}
return s1;
#endif
}
#endif
/**********************************************************************/
#ifdef L_wcscpy
#define L_strcpy
#define Wstrcpy wcscpy
#else
#define Wstrcpy strcpy
#endif
#ifdef L_strcpy
Wchar *Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
{
register Wchar *s = s1;
#ifdef __BCC__
do {
*s = *s2++;
} while (*s++ != 0);
#else
while ( (*s++ = *s2++) != 0 );
#endif
return s1;
}
#endif
/**********************************************************************/
#ifdef L_wcsncpy
#define L_strncpy
#define Wstrncpy wcsncpy
#else
#define Wstrncpy strncpy
#endif
#ifdef L_strncpy
Wchar *Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
size_t n)
{
register Wchar *s = s1;
#ifdef __BCC__
while (n--) {
if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
++s;
}
#else
while (n) {
if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
++s;
--n;
}
#endif
return s1;
}
#endif
/**********************************************************************/
#ifdef L_wcscat
#define L_strcat
#define Wstrcat wcscat
#else
#define Wstrcat strcat
#endif
#ifdef L_strcat
Wchar *Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
{
register Wchar *s = s1;
while (*s++);
--s;
while ((*s++ = *s2++) != 0);
return s1;
}
#endif
/**********************************************************************/
#ifdef L_wcsncat
#define L_strncat
#define Wstrncat wcsncat
#else
#define Wstrncat strncat
#endif
#ifdef L_strncat
Wchar *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
size_t n)
{
register Wchar *s = s1;
while (*s++);
--s;
#if __BCC__
while (n-- && ((*s = *s2++) != 0)) ++s;
#else
while (n && ((*s = *s2++) != 0)) {
--n;
++s;
}
#endif
*s = 0;
return s1;
}
#endif
/**********************************************************************/
#ifdef L_wmemcmp
#define L_memcmp
#define Wmemcmp wmemcmp
#else
#define Wmemcmp memcmp
#endif
#ifdef L_memcmp
#ifndef L_wmemcmp
weak_alias(memcmp,bcmp);
#endif
int Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
{
register const Wuchar *r1 = (const Wuchar *) s1;
register const Wuchar *r2 = (const Wuchar *) s2;
#ifdef WANT_WIDE
while (n && (*r1 == *r2)) {
++r1;
++r2;
--n;
}
return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
#else
int r = 0;
while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
return r;
#endif
}
#endif
/**********************************************************************/
#ifdef L_wcscmp
#define L_strcmp
#define Wstrcmp wcscmp
#else
#define Wstrcmp strcmp
#endif
#ifdef L_strcmp
#ifndef L_wcscmp
#warning implement strcoll and remove weak alias (or enable for C locale only)
weak_alias(strcmp,strcoll);
#endif
int Wstrcmp(register const Wchar *s1, register const Wchar *s2)
{
#ifdef WANT_WIDE
while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
if (!*s1++) {
return 0;
}
++s2;
}
return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
#else
int r;
while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
== 0) && *s1++);
return r;
#endif
}
#endif
/**********************************************************************/
#ifdef L_strcoll
#error implement strcoll and remove weak_alias!!
#if 0
extern unsigned char *_ctype_collate;
int strcoll(register const char *s1, const char *s2)
{
int r;
while (!(r = (_ctype_collate[(int)(*s1++)]-_ctype_collate[(int)(*s2++)])));
return r;
}
#endif
#endif
/**********************************************************************/
#ifdef L_wcsncmp
#define L_strncmp
#define Wstrncmp wcsncmp
#else
#define Wstrncmp strncmp
#endif
#ifdef L_strncmp
int Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
{
#ifdef WANT_WIDE
while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
if (!*s1++) {
return 0;
}
++s2;
--n;
}
return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
#else
int r = 0;
while (n--
&& ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
== 0)
&& *s1++);
return r;
#endif
}
#endif
/**********************************************************************/
#ifdef L_strxfrm
#error implement strxfrm
/* size_t strxfrm(char *dst, const char *src, size_t len); */
#endif
/**********************************************************************/
#ifdef L_wmemchr
#define L_memchr
#define Wmemchr wmemchr
#else
#define Wmemchr memchr
#endif
#ifdef L_memchr
Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n)
{
register const Wuchar *r = (const Wuchar *) s;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
#define np n
#endif
while (np) {
if (*r == ((Wuchar)c)) {
return (Wvoid *) r; /* silence the warning */
}
++r;
--np;
}
return NULL;
}
#undef np
#endif
/**********************************************************************/
#ifdef L_wcschr
#define L_strchr
#define Wstrchr wcschr
#else
#define Wstrchr strchr
#endif
#ifdef L_strchr
#ifndef L_wcschr
weak_alias(strchr,index);
#endif
Wchar *Wstrchr(register const Wchar *s, Wint c)
{
do {
if (*s == ((Wchar)c)) {
return (Wchar *) s; /* silence the warning */
}
} while (*s++);
return NULL;
}
#endif
/**********************************************************************/
#ifdef L_wcscspn
#define L_strcspn
#define Wstrcspn wcscspn
#else
#define Wstrcspn strcspn
#endif
#ifdef L_strcspn
size_t Wstrcspn(const Wchar *s1, const Wchar *s2)
{
register const Wchar *s;
register const Wchar *p;
for ( s=s1 ; *s ; s++ ) {
for ( p=s2 ; *p ; p++ ) {
if (*p == *s) goto done;
}
}
done:
return s - s1;
}
#endif
/**********************************************************************/
#ifdef L_wcspbrk
#define L_strpbrk
#define Wstrpbrk wcspbrk
#else
#define Wstrpbrk strpbrk
#endif
#ifdef L_strpbrk
Wchar *Wstrpbrk(const Wchar *s1, const Wchar *s2)
{
register const Wchar *s;
register const Wchar *p;
for ( s=s1 ; *s ; s++ ) {
for ( p=s2 ; *p ; p++ ) {
if (*p == *s) return (Wchar *) s; /* silence the warning */
}
}
return NULL;
}
#endif
/**********************************************************************/
#ifdef L_wcsrchr
#define L_strrchr
#define Wstrrchr wcsrchr
#else
#define Wstrrchr strrchr
#endif
#ifdef L_strrchr
#ifndef L_wcsrchr
weak_alias(strrchr,rindex);
#endif
Wchar *Wstrrchr(register const Wchar *s, Wint c)
{
register const Wchar *p;
p = NULL;
do {
if (*s == (Wchar) c) {
p = s;
}
} while (*s++);
return (Wchar *) p; /* silence the warning */
}
#endif
/**********************************************************************/
#ifdef L_wcsspn
#define L_strspn
#define Wstrspn wcsspn
#else
#define Wstrspn strspn
#endif
#ifdef L_strspn
size_t Wstrspn(const Wchar *s1, const Wchar *s2)
{
register const Wchar *s = s1;
register const Wchar *p = s2;
while (*p) {
if (*p++ == *s) {
++s;
p = s2;
}
}
return s - s1;
}
#endif
/**********************************************************************/
#ifdef L_wcsstr
#define L_strstr
#define Wstrstr wcsstr
#else
#define Wstrstr strstr
#endif
#ifdef L_strstr
/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
#ifdef L_wcsstr
weak_alias(wcsstr,wcswcs);
#endif
Wchar *Wstrstr(const Wchar *s1, const Wchar *s2)
{
register const Wchar *s = s1;
register const Wchar *p = s2;
do {
if (!*p) {
return (Wchar *) s1;;
}
if (*p == *s) {
++p;
++s;
} else {
p = s2;
if (!*s) {
return NULL;
}
s = ++s1;
}
} while (1);
}
#endif
/**********************************************************************/
#ifdef L_wcstok
#define L_strtok_r
#define Wstrtok_r wcstok
#define Wstrspn wcsspn
#define Wstrpbrk wcspbrk
#else
#define Wstrtok_r strtok_r
#define Wstrspn strspn
#define Wstrpbrk strpbrk
#endif
#ifdef L_strtok_r
Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
Wchar ** __restrict next_start)
{
register Wchar *s;
register Wchar *p;
#if 1
if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
if (*(s += Wstrspn(s, s2))) {
if ((p = Wstrpbrk(s, s2)) != NULL) {
*p++ = 0;
}
} else {
p = s = NULL;
}
*next_start = p;
}
return s;
#else
if (!(s = s1)) {
s = *next_start;
}
if (s && *(s += Wstrspn(s, s2))) {
if (*(p = s + Wstrcspn(s, s2))) {
*p++ = 0;
}
*next_start = p;
return s;
}
return NULL; /* TODO: set *next_start = NULL for safety? */
#endif
}
#endif
/**********************************************************************/
/* #ifdef L_wcstok */
/* #define L_strtok */
/* #define Wstrtok wcstok */
/* #define Wstrtok_r wcstok_r */
/* #else */
/* #define Wstrtok strtok */
/* #define Wstrtok_r strtok_r */
/* #endif */
#ifdef L_strtok
#define Wstrtok strtok
#define Wstrtok_r strtok_r
Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
{
static Wchar *next_start; /* Initialized to 0 since in bss. */
return Wstrtok_r(s1, s2, &next_start);
}
#endif
/**********************************************************************/
#ifdef L_wmemset
#define L_memset
#define Wmemset wmemset
#else
#define Wmemset memset
#endif
#ifdef L_memset
Wvoid *Wmemset(Wvoid *s, Wint c, size_t n)
{
register Wuchar *p = (Wuchar *) s;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
#define np n
#endif
while (np) {
*p++ = (Wuchar) c;
--np;
}
return s;
}
#undef np
#endif
/**********************************************************************/
#ifdef L_wcslen
#define L_strlen
#define Wstrlen wcslen
#else
#define Wstrlen strlen
#endif
#ifdef L_strlen
size_t Wstrlen(const Wchar *s)
{
register const Wchar *p;
for (p=s ; *p ; p++);
return p - s;
}
#endif
/**********************************************************************/
/* ANSI/ISO end here */
/**********************************************************************/
#ifdef L_ffs
int ffs(int i)
{
#if 1
/* inlined binary search method */
char n = 1;
#if UINT_MAX == 0xffffU
/* nothing to do here -- just trying to avoiding possible problems */
#elif UINT_MAX == 0xffffffffU
if (!(i & 0xffff)) {
n += 16;
i >>= 16;
}
#else
#error ffs needs rewriting!
#endif
if (!(i & 0xff)) {
n += 8;
i >>= 8;
}
if (!(i & 0x0f)) {
n += 4;
i >>= 4;
}
if (!(i & 0x03)) {
n += 2;
i >>= 2;
}
return (i) ? (n + ((i+1) & 0x01)) : 0;
#else
/* linear search -- slow, but small */
int n;
for (n = 0 ; i ; ++n) {
i >>= 1;
}
return n;
#endif
}
#endif
/**********************************************************************/
#ifdef L_wcscasecmp
#define L_strcasecmp
#define Wstrcasecmp wcscasecmp
#else
#define Wstrcasecmp strcasecmp
#endif
#ifdef L_strcasecmp
int Wstrcasecmp(register const Wchar *s1, register const Wchar *s2)
{
#ifdef WANT_WIDE
while ((*s1 == *s2) || (towlower(*s1) == towlower(*s2))) {
if (!*s1++) {
return 0;
}
++s2;
}
return (((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1;
/* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
#else
int r = 0;
while ( ((s1 == s2) ||
!(r = ((int)( tolower(*((Wuchar *)s1))))
- tolower(*((Wuchar *)s2))))
&& (++s2, *s1++));
return r;
#endif
}
#endif
/**********************************************************************/
#ifdef L_wcsncasecmp
#define L_strncasecmp
#define Wstrncasecmp wcsncasecmp
#else
#define Wstrncasecmp strncasecmp
#endif
#ifdef L_strncasecmp
int Wstrncasecmp(register const Wchar *s1, register const Wchar *s2, size_t n)
{
#ifdef WANT_WIDE
while (n && ((*s1 == *s2) || (towlower(*s1) == towlower(*s2)))) {
if (!*s1++) {
return 0;
}
++s2;
--n;
}
return (n == 0)
? 0
: ((((Wuchar)towlower(*s1)) < ((Wuchar)towlower(*s2))) ? -1 : 1);
/* TODO -- should wide cmp funcs do wchar or Wuchar compares? */
#else
int r = 0;
while ( n
&& ((s1 == s2) ||
!(r = ((int)( tolower(*((unsigned char *)s1))))
- tolower(*((unsigned char *)s2))))
&& (--n, ++s2, *s1++));
return r;
#endif
}
#endif
/**********************************************************************/
#ifdef L_wcsnlen
#define L_strnlen
#define Wstrnlen wcsnlen
#else
#define Wstrnlen strnlen
#endif
#ifdef L_strnlen
size_t Wstrnlen(const Wchar *s, size_t max)
{
register const Wchar *p = s;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *maxp = (const char *) max;
#else
#define maxp max
#endif
while (maxp && *p) {
++p;
--maxp;
}
return p - s;
}
#undef maxp
#endif
/**********************************************************************/
/* No wide analog. */
#ifdef L_memccpy
void *memccpy(void * __restrict s1, const void * __restrict s2, int c, size_t n)
{
register char *r1 = s1;
register const char *r2 = s2;
while (n-- && (((unsigned char)(*r1++ = *r2++)) != ((unsigned char) c)));
return (n == (size_t) -1) ? NULL : r1;
}
#endif
/**********************************************************************/
#ifdef L_wcsdup
#define L_strdup
#define Wstrdup wcsdup
#define Wstrlen wcslen
#define Wstrcpy wcscpy
#else
#define Wstrdup strdup
#define Wstrlen strlen
#define Wstrcpy strcpy
#endif
#ifdef L_strdup
Wchar *Wstrdup(register const Wchar *s1)
{
register Wchar *s;
if ((s = malloc((Wstrlen(s1) + 1) * sizeof(Wchar))) != NULL) {
Wstrcpy(s, s1);
}
return s;
}
#endif
/**********************************************************************/
#ifdef L_strerror
char *strerror(int errnum)
{
static char buf[_SYS_ERRMSG_MAXLEN];
return (_susv3_strerror_r(errnum, buf, sizeof(buf)) == 0) ? buf : NULL;
}
#endif
/**********************************************************************/
/* SUSv3 functions. */
/**********************************************************************/
#ifdef L__susv3_strerror_r
int _susv3_strerror_r(int errnum, char *strerrbuf, size_t buflen)
{
register char *s;
int i, retval;
char buf[_SYS_ERRMSG_MAXLEN];
static const char unknown[14] = {
'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' '
};
retval = EINVAL;
if (((unsigned int) errnum) < _SYS_NERR) {
/* Trade time for space. This function should rarely be called
* so rather than keeping an array of pointers for the different
* messages, just run through the buffer until we find the
* correct string. */
for (s = (char *) _string_syserrmsgs, i = errnum ; i ; ++s) {
if (!*s) {
--i;
}
}
if (*s) { /* Make sure we have an actual message. */
retval = 0;
goto GOT_MESG;
}
}
s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown);
memcpy(s, unknown, sizeof(unknown));
GOT_MESG:
if (!strerrbuf) { /* SUSv3 */
buflen = 0;
}
i = strlen(s) + 1;
if (i > buflen) {
i = buflen;
retval = ERANGE;
}
if (i) {
memcpy(strerrbuf, s, i);
strerrbuf[i-1] = 0; /* In case buf was too small. */
}
if (retval) {
__set_errno(retval);
}
return retval;
}
#endif
/**********************************************************************/
/* GNU extension functions. */
/**********************************************************************/
#ifdef L__glibc_strerror_r
weak_alias(_glibc_strerror_r,__strerror_r);
char *_glibc_strerror_r(int errnum, char *strerrbuf, size_t buflen)
{
_susv3_strerror_r(errnum, strerrbuf, buflen);
return strerrbuf;
}
#endif
/**********************************************************************/
#ifdef L_wmempcpy
#define L_mempcpy
#define Wmempcpy wmempcpy
#else
#define Wmempcpy mempcpy
#endif
#ifdef L_mempcpy
#ifndef L_wmempcpy
/* uClibc's old string implementation did this to cater to some app. */
weak_alias(mempcpy,__mempcpy);
#endif
Wvoid *Wmempcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
{
register Wchar *r1 = s1;
register const Wchar *r2 = s2;
#ifdef __BCC__
while (n--) {
*r1++ = *r2++;
}
#else
while (n) {
*r1++ = *r2++;
--n;
}
#endif
return r1;
}
#endif
/**********************************************************************/
#ifdef L_memrchr
void *memrchr(const void *s, int c, size_t n)
{
register const unsigned char *r;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
#define np n
#endif
r = ((unsigned char *)s) + ((size_t) np);
while (np) {
if (*--r == ((unsigned char)c)) {
return (void *) r; /* silence the warning */
}
--np;
}
return NULL;
}
#undef np
#endif
/**********************************************************************/
#ifdef L_wcpcpy
#define L_stpcpy
#define Wstpcpy wcpcpy
#else
#define Wstpcpy stpcpy
#endif
#ifdef L_stpcpy
Wchar *Wstpcpy(register Wchar * __restrict s1, const Wchar * __restrict s2)
{
#ifdef __BCC__
do {
*s1 = *s2++;
} while (*s1++ != 0);
#else
while ( (*s1++ = *s2++) != 0 );
#endif
return s1 - 1;
}
#endif
/**********************************************************************/
#ifdef L_wcpncpy
#define L_stpncpy
#define Wstpncpy wcpncpy
#else
#define Wstpncpy stpncpy
#endif
#ifdef L_stpncpy
Wchar *Wstpncpy(register Wchar * __restrict s1,
register const Wchar * __restrict s2,
size_t n)
{
Wchar *s = s1;
const Wchar *p = s2;
#ifdef __BCC__
while (n--) {
if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
++s;
}
return s1 + (s2 - p);
#else
while (n) {
if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
++s;
--n;
}
return s1 + (s2 - p);
#endif
}
#endif
/**********************************************************************/
#ifdef L_bzero
void bzero(void *s, size_t n)
{
register unsigned char *p = s;
#ifdef __BCC__
/* bcc can optimize the counter if it thinks it is a pointer... */
register const char *np = (const char *) n;
#else
#define np n
#endif
while (np) {
*p++ = 0;
--np;
}
}
#undef np
#endif
/**********************************************************************/
#ifdef L_bcopy
void bcopy(const void *s2, void *s1, size_t n)
{
#if 1
memmove(s1, s2, n);
#else
#ifdef __BCC__
register char *s;
register const char *p;
s = s1;
p = s2;
if (p >= s) {
while (n--) {
*s++ = *p++;
}
} else {
s += n;
p += n;
while (n--) {
*--s = *--p;
}
}
#else
register char *s;
register const char *p;
s = s1;
p = s2;
if (p >= s) {
while (n) {
*s++ = *p++;
--n;
}
} else {
while (n) {
--n;
s[n] = p[n];
}
}
#endif
#endif
}
#endif
/**********************************************************************/
#ifdef L_strcasestr
char *strcasestr(const char *s1, const char *s2)
{
register const char *s = s1;
register const char *p = s2;
#if 1
do {
if (!*p) {
return (char *) s1;;
}
if ((*p == *s)
|| (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
) {
++p;
++s;
} else {
p = s2;
if (!*s) {
return NULL;
}
s = ++s1;
}
} while (1);
#else
while (*p && *s) {
if ((*p == *s)
|| (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s)))
) {
++p;
++s;
} else {
p = s2;
s = ++s1;
}
}
return (*p) ? NULL : (char *) s1;
#endif
}
#endif
/**********************************************************************/
#ifdef L_strndup
char *strndup(register const char *s1, size_t n)
{
register char *s;
n = strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
if ((s = malloc(n + 1)) != NULL) {
memcpy(s, s1, n);
s[n] = 0;
}
return s;
}
#endif
/**********************************************************************/
#ifdef L_strsep
char *strsep(char ** __restrict s1, const char * __restrict s2)
{
register char *s = *s1;
register char *p;
#if 1
p = NULL;
if (s && *s && (p = strpbrk(s, s2))) {
*p++ = 0;
}
#else
if (s && *s && *(p = s + strcspn(s, s2))) {
*p++ = 0;
} else {
p = NULL;
}
#endif
*s1 = p;
return s;
}
#endif
/**********************************************************************/
#ifdef L_wcschrnul
#define L_strchrnul
#define Wstrchrnul wcschrnul
#else
#define Wstrchrnul strchrnul
#endif
#ifdef L_strchrnul
Wchar *Wstrchrnul(register const Wchar *s, Wint c)
{
--s;
while (*++s && (*s != ((Wchar)c)));
return (Wchar *) s;
}
#endif
/**********************************************************************/
#ifdef L_rawmemchr
void *rawmemchr(const void *s, int c)
{
register const unsigned char *r = s;
while (*r != ((unsigned char)c)) ++r;
return (void *) r; /* silence the warning */
}
#endif
/**********************************************************************/
#ifdef L_basename
char *basename(const char *path)
{
register const char *s;
register const char *p;
p = s = path;
while (*s) {
if (*s++ == '/') {
p = s;
}
}
return (char *) p;
}
#endif
/**********************************************************************/
#ifdef L___xpg_basename
char *__xpg_basename(register char *path)
{
static const char null_or_empty[] = ".";
char *first;
register char *last;
first = (char *) null_or_empty;
if (path && *path) {
first = path;
last = path - 1;
do {
if ((*path != '/') && (path > ++last)) {
last = first = path;
}
} while (*++path);
if (*first == '/') {
last = first;
}
last[1] = 0;
}
return first;
}
#endif
/**********************************************************************/
#ifdef L_dirname
char *dirname(char *path)
{
static const char null_or_empty_or_noslash[] = ".";
register char *s;
register char *last;
char *first;
last = s = path;
if (s != NULL) {
LOOP:
while (*s && (*s != '/')) ++s;
first = s;
while (*s == '/') ++s;
if (*s) {
last = first;
goto LOOP;
}
if (last == path) {
if (*last != '/') {
goto DOT;
}
if ((*++last == '/') && (last[1] == 0)) {
++last;
}
}
*last = 0;
return path;
}
DOT:
return (char *) null_or_empty_or_noslash;
}
#endif
/**********************************************************************/
#ifdef L_strlcat
/* OpenBSD function:
* Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst.
* Returns strlen(src) + strlen({original} dst), so truncation occurred if the
* return val is >= n.
* Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is
* taken as n. */
size_t strlcat(register char *__restrict dst,
register const char *__restrict src,
size_t n)
{
size_t len;
char dummy[1];
len = 0;
while (1) {
if (len >= n) {
dst = dummy;
break;
}
if (!*dst) {
break;
}
++dst;
++len;
}
while ((*dst = *src) != 0) {
if (++len < n) {
++dst;
}
++src;
}
return len;
}
#endif
/**********************************************************************/
#ifdef L_strlcpy
/* OpenBSD function:
* Copy at most n-1 chars from src to dst and nul-terminate dst.
* Returns strlen(src), so truncation occurred if the return value is >= n. */
size_t strlcpy(register char *__restrict dst,
register const char *__restrict src,
size_t n)
{
const char *src0 = src;
char dummy[1];
if (!n) {
dst = dummy;
} else {
--n;
}
while ((*dst = *src) != 0) {
if (n) {
--n;
++dst;
}
++src;
}
return src - src0;
}
#endif
/**********************************************************************/
|