aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0001-git-0.9.15-to-3e02ce1b411.patch
blob: 07bd03f7784d8b64b3b8c216b0d1440e1481195e (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
diff --git a/arch/arm/bits/termios.h b/arch/arm/bits/termios.h
index 61c888f..f0d81b1 100644
--- a/arch/arm/bits/termios.h
+++ b/arch/arm/bits/termios.h
@@ -42,6 +42,7 @@ struct termios
 #define IXANY   0004000
 #define IXOFF   0010000
 #define IMAXBEL 0020000
+#define IUTF8   0040000
 
 #define OPOST  0000001
 #define OLCUC  0000002
@@ -75,9 +76,6 @@ struct termios
 #define VT0    0000000
 #define VT1    0040000
 
-/* ?? */
-#define XTABS  0014000
-
 #define B0       0000000
 #define B50      0000001
 #define B75      0000002
@@ -125,8 +123,6 @@ struct termios
 #define HUPCL  0002000
 #define CLOCAL 0004000
 
-#define CRTSCTS  020000000000
-
 #define ISIG   0000001
 #define ICANON 0000002
 #define ECHO   0000010
@@ -137,14 +133,11 @@ struct termios
 #define TOSTOP 0000400
 #define IEXTEN 0100000
 
-/* Extensions? */
-#define CBAUDEX 0010000
 #define ECHOCTL 0001000
 #define ECHOPRT 0002000
 #define ECHOKE 0004000
 #define FLUSHO 0010000
 #define PENDIN 0040000
-#define EXTPROC 0200000
 
 #define TCOOFF 0
 #define TCOON  1
@@ -158,3 +151,10 @@ struct termios
 #define TCSANOW   0
 #define TCSADRAIN 1
 #define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#endif
diff --git a/arch/i386/bits/termios.h b/arch/i386/bits/termios.h
index 61c888f..f0d81b1 100644
--- a/arch/i386/bits/termios.h
+++ b/arch/i386/bits/termios.h
@@ -42,6 +42,7 @@ struct termios
 #define IXANY   0004000
 #define IXOFF   0010000
 #define IMAXBEL 0020000
+#define IUTF8   0040000
 
 #define OPOST  0000001
 #define OLCUC  0000002
@@ -75,9 +76,6 @@ struct termios
 #define VT0    0000000
 #define VT1    0040000
 
-/* ?? */
-#define XTABS  0014000
-
 #define B0       0000000
 #define B50      0000001
 #define B75      0000002
@@ -125,8 +123,6 @@ struct termios
 #define HUPCL  0002000
 #define CLOCAL 0004000
 
-#define CRTSCTS  020000000000
-
 #define ISIG   0000001
 #define ICANON 0000002
 #define ECHO   0000010
@@ -137,14 +133,11 @@ struct termios
 #define TOSTOP 0000400
 #define IEXTEN 0100000
 
-/* Extensions? */
-#define CBAUDEX 0010000
 #define ECHOCTL 0001000
 #define ECHOPRT 0002000
 #define ECHOKE 0004000
 #define FLUSHO 0010000
 #define PENDIN 0040000
-#define EXTPROC 0200000
 
 #define TCOOFF 0
 #define TCOON  1
@@ -158,3 +151,10 @@ struct termios
 #define TCSANOW   0
 #define TCSADRAIN 1
 #define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#endif
diff --git a/arch/microblaze/bits/termios.h b/arch/microblaze/bits/termios.h
index 61c888f..f0d81b1 100644
--- a/arch/microblaze/bits/termios.h
+++ b/arch/microblaze/bits/termios.h
@@ -42,6 +42,7 @@ struct termios
 #define IXANY   0004000
 #define IXOFF   0010000
 #define IMAXBEL 0020000
+#define IUTF8   0040000
 
 #define OPOST  0000001
 #define OLCUC  0000002
@@ -75,9 +76,6 @@ struct termios
 #define VT0    0000000
 #define VT1    0040000
 
-/* ?? */
-#define XTABS  0014000
-
 #define B0       0000000
 #define B50      0000001
 #define B75      0000002
@@ -125,8 +123,6 @@ struct termios
 #define HUPCL  0002000
 #define CLOCAL 0004000
 
-#define CRTSCTS  020000000000
-
 #define ISIG   0000001
 #define ICANON 0000002
 #define ECHO   0000010
@@ -137,14 +133,11 @@ struct termios
 #define TOSTOP 0000400
 #define IEXTEN 0100000
 
-/* Extensions? */
-#define CBAUDEX 0010000
 #define ECHOCTL 0001000
 #define ECHOPRT 0002000
 #define ECHOKE 0004000
 #define FLUSHO 0010000
 #define PENDIN 0040000
-#define EXTPROC 0200000
 
 #define TCOOFF 0
 #define TCOON  1
@@ -158,3 +151,10 @@ struct termios
 #define TCSANOW   0
 #define TCSADRAIN 1
 #define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#endif
diff --git a/arch/mips/bits/termios.h b/arch/mips/bits/termios.h
index 179af8e..487c1d4 100644
--- a/arch/mips/bits/termios.h
+++ b/arch/mips/bits/termios.h
@@ -77,9 +77,6 @@ struct termios
 #define VT0    0000000
 #define VT1    0040000
 
-/* ?? */
-#define XTABS  0014000
-
 #define B0       0000000
 #define B50      0000001
 #define B75      0000002
@@ -129,12 +126,6 @@ struct termios
 #define PARODD 0001000
 #define HUPCL  0002000
 #define CLOCAL 0004000
-#define CBAUDEX 0010000
-
-#define CIBAUD   002003600000
-#define CMSPAR   010000000000
-#define CRTSCTS  020000000000
-#define IBSHIFT 16
 
 #define ISIG   0000001
 #define ICANON 0000002
@@ -152,9 +143,6 @@ struct termios
 #define PENDIN 0040000
 #define TOSTOP 0100000
 #define ITOSTOP 0100000
-#define EXTPROC 0200000
-
-#define TIOCSER_TEMT 1
 
 #define TCOOFF 0
 #define TCOON  1
@@ -168,3 +156,14 @@ struct termios
 #define TCSANOW   0
 #define TCSADRAIN 1
 #define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CIBAUD   002003600000
+#define IBSHIFT 16
+#define CMSPAR   010000000000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#define TIOCSER_TEMT 1
+#endif
diff --git a/arch/powerpc/bits/termios.h b/arch/powerpc/bits/termios.h
index 3022759..9f8016c 100644
--- a/arch/powerpc/bits/termios.h
+++ b/arch/powerpc/bits/termios.h
@@ -66,7 +66,6 @@ struct termios
 #define TAB1	00002000
 #define TAB2	00004000
 #define TAB3	00006000
-#define XTABS	00006000
 #define CRDLY	00030000
 #define CR0	00000000
 #define CR1	00010000
@@ -101,7 +100,6 @@ struct termios
 #define B38400	0000017
 #define EXTA	B19200
 #define EXTB	B38400
-#define CBAUDEX	0000000
 #define B57600	00020
 #define B115200	00021
 #define B230400	00022
@@ -120,9 +118,6 @@ struct termios
 #define B4000000	00036
 #define BOTHER	00037
 
-#define CIBAUD	077600000
-#define IBSHIFT 16
-
 #define CSIZE	00001400
 #define CS5	00000000
 #define CS6	00000400
@@ -136,8 +131,6 @@ struct termios
 #define HUPCL	00040000
 
 #define CLOCAL	00100000
-#define CMSPAR	010000000000
-#define CRTSCTS	020000000000
 
 #define ISIG	0x00000080
 #define ICANON	0x00000100
@@ -154,7 +147,6 @@ struct termios
 #define FLUSHO	0x00800000
 #define PENDIN	0x20000000
 #define IEXTEN	0x00000400
-#define EXTPROC 0x10000000
 
 #define TCOOFF	0
 #define TCOON	1
@@ -168,3 +160,13 @@ struct termios
 #define TCSANOW		0
 #define TCSADRAIN	1
 #define TCSAFLUSH	2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX	0000000
+#define CIBAUD	077600000
+#define IBSHIFT 16
+#define CMSPAR	010000000000
+#define CRTSCTS	020000000000
+#define EXTPROC 0x10000000
+#define XTABS	00006000
+#endif
diff --git a/arch/x86_64/atomic.h b/arch/x86_64/atomic.h
index 0d3da6f..124b37a 100644
--- a/arch/x86_64/atomic.h
+++ b/arch/x86_64/atomic.h
@@ -5,38 +5,36 @@
 
 static inline int a_ctz_64(uint64_t x)
 {
-	long r;
-	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
-	return r;
+	__asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
+	return x;
 }
 
 static inline int a_ctz_l(unsigned long x)
 {
-	long r;
-	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
-	return r;
+	__asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
+	return x;
 }
 
 static inline void a_and_64(volatile uint64_t *p, uint64_t v)
 {
-	__asm__( "lock ; andq %1, %0"
-			 : "=m"(*(long *)p) : "r"(v) : "memory" );
+	__asm__( "lock ; and %1, %0"
+			 : "=m"(*p) : "r"(v) : "memory" );
 }
 
 static inline void a_or_64(volatile uint64_t *p, uint64_t v)
 {
-	__asm__( "lock ; orq %1, %0"
-			 : "=m"(*(long *)p) : "r"(v) : "memory" );
+	__asm__( "lock ; or %1, %0"
+			 : "=m"(*p) : "r"(v) : "memory" );
 }
 
 static inline void a_store_l(volatile void *p, long x)
 {
-	__asm__( "movq %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" );
+	__asm__( "mov %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" );
 }
 
 static inline void a_or_l(volatile void *p, long v)
 {
-	__asm__( "lock ; orq %1, %0"
+	__asm__( "lock ; or %1, %0"
 		: "=m"(*(long *)p) : "r"(v) : "memory" );
 }
 
@@ -56,7 +54,7 @@ static inline long a_cas_l(volatile void *p, long t, long s)
 
 static inline int a_cas(volatile int *p, int t, int s)
 {
-	__asm__( "lock ; cmpxchgl %3, %1"
+	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
@@ -74,13 +72,13 @@ static inline long a_swap_l(volatile void *x, long v)
 
 static inline void a_or(volatile void *p, int v)
 {
-	__asm__( "lock ; orl %1, %0"
+	__asm__( "lock ; or %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
 static inline void a_and(volatile void *p, int v)
 {
-	__asm__( "lock ; andl %1, %0"
+	__asm__( "lock ; and %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
@@ -110,7 +108,7 @@ static inline void a_dec(volatile int *x)
 
 static inline void a_store(volatile int *p, int x)
 {
-	__asm__( "movl %1, %0" : "=m"(*p) : "r"(x) : "memory" );
+	__asm__( "mov %1, %0" : "=m"(*p) : "r"(x) : "memory" );
 }
 
 static inline void a_spin()
diff --git a/arch/x86_64/bits/stat.h b/arch/x86_64/bits/stat.h
index 2145796..081237c 100644
--- a/arch/x86_64/bits/stat.h
+++ b/arch/x86_64/bits/stat.h
@@ -2,7 +2,7 @@
  * by the corresponding correctly-sized userspace types. */
 
 struct stat {
-	unsigned long st_dev;
+	dev_t st_dev;
 	ino_t st_ino;
 	nlink_t st_nlink;
 
diff --git a/arch/x86_64/bits/termios.h b/arch/x86_64/bits/termios.h
index 61c888f..f0d81b1 100644
--- a/arch/x86_64/bits/termios.h
+++ b/arch/x86_64/bits/termios.h
@@ -42,6 +42,7 @@ struct termios
 #define IXANY   0004000
 #define IXOFF   0010000
 #define IMAXBEL 0020000
+#define IUTF8   0040000
 
 #define OPOST  0000001
 #define OLCUC  0000002
@@ -75,9 +76,6 @@ struct termios
 #define VT0    0000000
 #define VT1    0040000
 
-/* ?? */
-#define XTABS  0014000
-
 #define B0       0000000
 #define B50      0000001
 #define B75      0000002
@@ -125,8 +123,6 @@ struct termios
 #define HUPCL  0002000
 #define CLOCAL 0004000
 
-#define CRTSCTS  020000000000
-
 #define ISIG   0000001
 #define ICANON 0000002
 #define ECHO   0000010
@@ -137,14 +133,11 @@ struct termios
 #define TOSTOP 0000400
 #define IEXTEN 0100000
 
-/* Extensions? */
-#define CBAUDEX 0010000
 #define ECHOCTL 0001000
 #define ECHOPRT 0002000
 #define ECHOKE 0004000
 #define FLUSHO 0010000
 #define PENDIN 0040000
-#define EXTPROC 0200000
 
 #define TCOOFF 0
 #define TCOON  1
@@ -158,3 +151,10 @@ struct termios
 #define TCSANOW   0
 #define TCSADRAIN 1
 #define TCSAFLUSH 2
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define CBAUDEX 0010000
+#define CRTSCTS  020000000000
+#define EXTPROC 0200000
+#define XTABS  0014000
+#endif
diff --git a/arch/x86_64/pthread_arch.h b/arch/x86_64/pthread_arch.h
index 77c8387..29e4590 100644
--- a/arch/x86_64/pthread_arch.h
+++ b/arch/x86_64/pthread_arch.h
@@ -1,7 +1,7 @@
 static inline struct pthread *__pthread_self()
 {
 	struct pthread *self;
-	__asm__ __volatile__ ("movq %%fs:0,%0" : "=r" (self) );
+	__asm__ __volatile__ ("mov %%fs:0,%0" : "=r" (self) );
 	return self;
 }
 
diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index 5dcadaa..37f8c11 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -20,7 +20,7 @@ int inet_pton (int, const char *__restrict, void *__restrict);
 const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t);
 
 int inet_aton (const char *, struct in_addr *);
-struct in_addr inet_makeaddr(int, int);
+struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
 in_addr_t inet_lnaof(struct in_addr);
 in_addr_t inet_netof(struct in_addr);
 
diff --git a/include/dlfcn.h b/include/dlfcn.h
index db26194..78fb073 100644
--- a/include/dlfcn.h
+++ b/include/dlfcn.h
@@ -31,7 +31,7 @@ typedef struct {
 	const char *dli_sname;
 	void *dli_saddr;
 } Dl_info;
-int dladdr(void *, Dl_info *);
+int dladdr(const void *, Dl_info *);
 int dlinfo(void *, int, void *);
 #endif
 
diff --git a/include/fcntl.h b/include/fcntl.h
index 55a89f9..e01a4d1 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -148,6 +148,7 @@ struct f_owner_ex {
 #define SPLICE_F_MORE 4
 #define SPLICE_F_GIFT 8
 int fallocate(int, int, off_t, off_t);
+#define fallocate64 fallocate
 ssize_t readahead(int, off_t, size_t);
 int sync_file_range(int, off_t, off_t, unsigned);
 ssize_t vmsplice(int, const struct iovec *, size_t, unsigned);
diff --git a/include/netdb.h b/include/netdb.h
index 2dd799b..dfc70e2 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -131,6 +131,7 @@ int *__h_errno_location(void);
 #define TRY_AGAIN      2
 #define NO_RECOVERY    3
 #define NO_DATA        4
+#define NO_ADDRESS     NO_DATA
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/include/netinet/in.h b/include/netinet/in.h
index db96144..2e25afe 100644
--- a/include/netinet/in.h
+++ b/include/netinet/in.h
@@ -149,7 +149,7 @@ uint16_t ntohs(uint16_t);
         (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe))
 
 #define __ARE_4_EQUAL(a,b) \
-	(!( 0[a]-0[b] | 1[a]-1[b] | 2[a]-2[b] | 3[a]-3[b] ))
+	(!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) ))
 #define IN6_ARE_ADDR_EQUAL(a,b) \
 	__ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))
 
@@ -211,19 +211,6 @@ uint16_t ntohs(uint16_t);
 #define IP_MULTICAST_ALL   49
 #define IP_UNICAST_IF      50
 
-#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define MCAST_JOIN_GROUP   42
-#define MCAST_BLOCK_SOURCE 43
-#define MCAST_UNBLOCK_SOURCE      44
-#define MCAST_LEAVE_GROUP  45
-#define MCAST_JOIN_SOURCE_GROUP   46
-#define MCAST_LEAVE_SOURCE_GROUP  47
-#define MCAST_MSFILTER     48
-
-#define MCAST_EXCLUDE 0
-#define MCAST_INCLUDE 1
-#endif
-
 #define IP_RECVRETOPTS IP_RETOPTS
 
 #define IP_PMTUDISC_DONT   0
@@ -231,8 +218,6 @@ uint16_t ntohs(uint16_t);
 #define IP_PMTUDISC_DO     2
 #define IP_PMTUDISC_PROBE  3
 
-#define SOL_IP 0
-
 #define IP_DEFAULT_MULTICAST_TTL        1
 #define IP_DEFAULT_MULTICAST_LOOP       1
 #define IP_MAX_MEMBERSHIPS              20
@@ -243,6 +228,19 @@ struct ip_opts
 	char ip_opts[40];
 };
 
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+
+#define MCAST_JOIN_GROUP   42
+#define MCAST_BLOCK_SOURCE 43
+#define MCAST_UNBLOCK_SOURCE      44
+#define MCAST_LEAVE_GROUP  45
+#define MCAST_JOIN_SOURCE_GROUP   46
+#define MCAST_LEAVE_SOURCE_GROUP  47
+#define MCAST_MSFILTER     48
+
+#define MCAST_EXCLUDE 0
+#define MCAST_INCLUDE 1
+
 struct ip_mreq
 {
 	struct in_addr imr_multiaddr;
@@ -273,7 +271,6 @@ struct ip_msfilter {
 	(sizeof(struct ip_msfilter) - sizeof(struct in_addr) \
 	+ (numsrc) * sizeof(struct in_addr))
 
-#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 struct group_req {
 	uint32_t gr_interface;
 	struct sockaddr_storage gr_group;
@@ -295,7 +292,6 @@ struct group_filter {
 #define GROUP_FILTER_SIZE(numsrc) \
 	(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \
 	+ (numsrc) * sizeof(struct sockaddr_storage))
-#endif
 
 struct in_pktinfo
 {
@@ -315,6 +311,7 @@ struct ip6_mtuinfo
 	struct sockaddr_in6 ip6m_addr;
 	uint32_t ip6m_mtu;
 };
+#endif
 
 #define IPV6_ADDRFORM           1
 #define IPV6_2292PKTINFO        2
@@ -324,7 +321,6 @@ struct ip6_mtuinfo
 #define IPV6_2292PKTOPTIONS     6
 #define IPV6_CHECKSUM           7
 #define IPV6_2292HOPLIMIT       8
-#define SCM_SRCRT               IPV6_RXSRCRT
 #define IPV6_NEXTHOP            9
 #define IPV6_AUTHHDR            10
 #define IPV6_UNICAST_HOPS       16
@@ -363,15 +359,11 @@ struct ip6_mtuinfo
 #define IPV6_RXHOPOPTS          IPV6_HOPOPTS
 #define IPV6_RXDSTOPTS          IPV6_DSTOPTS
 
-
 #define IPV6_PMTUDISC_DONT      0
 #define IPV6_PMTUDISC_WANT      1
 #define IPV6_PMTUDISC_DO        2
 #define IPV6_PMTUDISC_PROBE     3
 
-#define SOL_IPV6        41
-#define SOL_ICMPV6      58
-
 #define IPV6_RTHDR_LOOSE        0
 #define IPV6_RTHDR_STRICT       1
 
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index 5639b89..d3db042 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -44,42 +44,80 @@
 #define SOL_TCP 6
 #include <sys/types.h>
 #include <sys/socket.h>
-#endif
+#include <stdint.h>
+#include <endian.h>
+
+typedef uint32_t tcp_seq;
 
+#define TH_FIN 0x01
+#define TH_SYN 0x02
+#define TH_RST 0x04
+#define TH_PUSH 0x08
+#define TH_ACK 0x10
+#define TH_URG 0x20
+
+struct tcphdr {
 #ifdef _GNU_SOURCE
-#include <endian.h>
-struct tcphdr
-{
-	u_int16_t source;
-	u_int16_t dest;
-	u_int32_t seq;
-	u_int32_t ack_seq;
+#ifdef __GNUC__
+	__extension__
+#endif
+	union { struct {
+
+	uint16_t source;
+	uint16_t dest;
+	uint32_t seq;
+	uint32_t ack_seq;
 #if __BYTE_ORDER == __LITTLE_ENDIAN
-	u_int16_t res1:4;
-	u_int16_t doff:4;
-	u_int16_t fin:1;
-	u_int16_t syn:1;
-	u_int16_t rst:1;
-	u_int16_t psh:1;
-	u_int16_t ack:1;
-	u_int16_t urg:1;
-	u_int16_t res2:2;
+	uint16_t res1:4;
+	uint16_t doff:4;
+	uint16_t fin:1;
+	uint16_t syn:1;
+	uint16_t rst:1;
+	uint16_t psh:1;
+	uint16_t ack:1;
+	uint16_t urg:1;
+	uint16_t res2:2;
 #else
-	u_int16_t doff:4;
-	u_int16_t res1:4;
-	u_int16_t res2:2;
-	u_int16_t urg:1;
-	u_int16_t ack:1;
-	u_int16_t psh:1;
-	u_int16_t rst:1;
-	u_int16_t syn:1;
-	u_int16_t fin:1;
+	uint16_t doff:4;
+	uint16_t res1:4;
+	uint16_t res2:2;
+	uint16_t urg:1;
+	uint16_t ack:1;
+	uint16_t psh:1;
+	uint16_t rst:1;
+	uint16_t syn:1;
+	uint16_t fin:1;
+#endif
+	uint16_t window;
+	uint16_t check;
+	uint16_t urg_ptr;
+
+	}; struct {
+#endif
+
+	uint16_t th_sport;
+	uint16_t th_dport;
+	uint32_t th_seq;
+	uint32_t th_ack;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+	uint8_t th_x2:4;
+	uint8_t th_off:4;
+#else
+	uint8_t th_off:4;
+	uint8_t th_x2:4;
+#endif
+	uint8_t th_flags;
+	uint16_t th_win;
+	uint16_t th_sum;
+	uint16_t th_urp;
+
+#ifdef _GNU_SOURCE
+	}; };
 #endif
-	u_int16_t window;
-	u_int16_t check;
-	u_int16_t urg_ptr;
 };
+#endif
 
+#ifdef _GNU_SOURCE
 #define TCPI_OPT_TIMESTAMPS	1
 #define TCPI_OPT_SACK		2
 #define TCPI_OPT_WSCALE		4
@@ -93,37 +131,37 @@ struct tcphdr
 
 struct tcp_info
 {
-	u_int8_t tcpi_state;
-	u_int8_t tcpi_ca_state;
-	u_int8_t tcpi_retransmits;
-	u_int8_t tcpi_probes;
-	u_int8_t tcpi_backoff;
-	u_int8_t tcpi_options;
-	u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
-	u_int32_t tcpi_rto;
-	u_int32_t tcpi_ato;
-	u_int32_t tcpi_snd_mss;
-	u_int32_t tcpi_rcv_mss;
-	u_int32_t tcpi_unacked;
-	u_int32_t tcpi_sacked;
-	u_int32_t tcpi_lost;
-	u_int32_t tcpi_retrans;
-	u_int32_t tcpi_fackets;
-	u_int32_t tcpi_last_data_sent;
-	u_int32_t tcpi_last_ack_sent;
-	u_int32_t tcpi_last_data_recv;
-	u_int32_t tcpi_last_ack_recv;
-	u_int32_t tcpi_pmtu;
-	u_int32_t tcpi_rcv_ssthresh;
-	u_int32_t tcpi_rtt;
-	u_int32_t tcpi_rttvar;
-	u_int32_t tcpi_snd_ssthresh;
-	u_int32_t tcpi_snd_cwnd;
-	u_int32_t tcpi_advmss;
-	u_int32_t tcpi_reordering;
-	u_int32_t tcpi_rcv_rtt;
-	u_int32_t tcpi_rcv_space;
-	u_int32_t tcpi_total_retrans;
+	uint8_t tcpi_state;
+	uint8_t tcpi_ca_state;
+	uint8_t tcpi_retransmits;
+	uint8_t tcpi_probes;
+	uint8_t tcpi_backoff;
+	uint8_t tcpi_options;
+	uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
+	uint32_t tcpi_rto;
+	uint32_t tcpi_ato;
+	uint32_t tcpi_snd_mss;
+	uint32_t tcpi_rcv_mss;
+	uint32_t tcpi_unacked;
+	uint32_t tcpi_sacked;
+	uint32_t tcpi_lost;
+	uint32_t tcpi_retrans;
+	uint32_t tcpi_fackets;
+	uint32_t tcpi_last_data_sent;
+	uint32_t tcpi_last_ack_sent;
+	uint32_t tcpi_last_data_recv;
+	uint32_t tcpi_last_ack_recv;
+	uint32_t tcpi_pmtu;
+	uint32_t tcpi_rcv_ssthresh;
+	uint32_t tcpi_rtt;
+	uint32_t tcpi_rttvar;
+	uint32_t tcpi_snd_ssthresh;
+	uint32_t tcpi_snd_cwnd;
+	uint32_t tcpi_advmss;
+	uint32_t tcpi_reordering;
+	uint32_t tcpi_rcv_rtt;
+	uint32_t tcpi_rcv_space;
+	uint32_t tcpi_total_retrans;
 };
 
 #define TCP_MD5SIG_MAXKEYLEN    80
@@ -131,10 +169,10 @@ struct tcp_info
 struct tcp_md5sig
 {
 	struct sockaddr_storage tcpm_addr;
-	u_int16_t __tcpm_pad1;
-	u_int16_t tcpm_keylen;
-	u_int32_t __tcpm_pad2;
-	u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
+	uint16_t __tcpm_pad1;
+	uint16_t tcpm_keylen;
+	uint32_t __tcpm_pad2;
+	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
 };
 
 #endif
diff --git a/include/netinet/udp.h b/include/netinet/udp.h
index 15b9145..b1b0eb8 100644
--- a/include/netinet/udp.h
+++ b/include/netinet/udp.h
@@ -5,19 +5,22 @@
 extern "C" {
 #endif
 
+#include <features.h>
 #include <stdint.h>
 
-struct udphdr {
-	uint16_t source;
-	uint16_t dest;
-	uint16_t len;
-	uint16_t check;
-};
-
+#ifdef _GNU_SOURCE
 #define uh_sport source
 #define uh_dport dest
 #define uh_ulen len
 #define uh_sum check
+#endif
+
+struct udphdr {
+	uint16_t uh_sport;
+	uint16_t uh_dport;
+	uint16_t uh_ulen;
+	uint16_t uh_sum;
+};
 
 #define UDP_CORK	1
 #define UDP_ENCAP	100
diff --git a/include/sched.h b/include/sched.h
index 6a6b2fc..105dac9 100644
--- a/include/sched.h
+++ b/include/sched.h
@@ -78,7 +78,7 @@ int __sched_cpucount(size_t, const cpu_set_t *);
 int sched_getaffinity(pid_t, size_t, cpu_set_t *);
 int sched_setaffinity(pid_t, size_t, const cpu_set_t *);
 
-#define __CPU_op_S(i, size, set, op) ( (i)/8 >= (size) ? 0 : \
+#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
 	((set)->__bits[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
 
 #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=)
diff --git a/include/signal.h b/include/signal.h
index 6f10a118..8ef5ff1 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -227,8 +227,8 @@ typedef void (*sig_t)(int);
 typedef void (*sighandler_t)(int);
 void (*bsd_signal(int, void (*)(int)))(int);
 int sigisemptyset(const sigset_t *);
-int sigorset (sigset_t *, sigset_t *, sigset_t *);
-int sigandset(sigset_t *, sigset_t *, sigset_t *);
+int sigorset (sigset_t *, const sigset_t *, const sigset_t *);
+int sigandset(sigset_t *, const sigset_t *, const sigset_t *);
 
 #define SA_NOMASK SA_NODEFER
 #define SA_ONESHOT SA_RESETHAND
diff --git a/include/stdlib.h b/include/stdlib.h
index 1e67b89..f034c6e 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -93,7 +93,7 @@ size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
 #define WSTOPSIG(s) WEXITSTATUS(s)
 #define WIFEXITED(s) (!WTERMSIG(s))
 #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
-#define WIFSIGNALED(s) (((s)&0xffff)-1 < 0xffu)
+#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
 
 int posix_memalign (void **, size_t, size_t);
 int setenv (const char *, const char *, int);
diff --git a/include/sys/inotify.h b/include/sys/inotify.h
index a5bf96a..46638ca 100644
--- a/include/sys/inotify.h
+++ b/include/sys/inotify.h
@@ -48,7 +48,7 @@ struct inotify_event {
 int inotify_init(void);
 int inotify_init1(int);
 int inotify_add_watch(int, const char *, uint32_t);
-int inotify_rm_watch(int, uint32_t);
+int inotify_rm_watch(int, int);
 
 #ifdef __cplusplus
 }
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 9a1e60f..a34448a 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -33,7 +33,7 @@ int munlockall (void);
 
 #ifdef _GNU_SOURCE
 void *mremap (void *, size_t, size_t, int, ...);
-int remap_file_pages (void *, size_t, int, ssize_t, int);
+int remap_file_pages (void *, size_t, int, size_t, int);
 #endif
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/include/sys/shm.h b/include/sys/shm.h
index c20f033..d97e582 100644
--- a/include/sys/shm.h
+++ b/include/sys/shm.h
@@ -37,14 +37,16 @@ struct shminfo {
 	unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4];
 };
 
-struct shm_info {
-	int used_ids;
-	unsigned long shm_tot, shm_rss, shm_swp;
 #ifdef _GNU_SOURCE
-	unsigned long swap_attempts, swap_successes;
-#else
-	unsigned long __reserved[2];
+#define __used_ids used_ids
+#define __swap_attempts swap_attempts
+#define __swap_successes swap_successes
 #endif
+
+struct shm_info {
+	int __used_ids;
+	unsigned long shm_tot, shm_rss, shm_swp;
+	unsigned long __swap_attempts, __swap_successes;
 };
 
 typedef unsigned long shmatt_t;
diff --git a/include/sys/socket.h b/include/sys/socket.h
index 82edd6f..79a41cc 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -207,6 +207,10 @@ struct linger
 #define SOL_SOCKET      1
 #endif
 
+#define SOL_IP          0
+#define SOL_IPV6        41
+#define SOL_ICMPV6      58
+
 #define SOL_RAW         255
 #define SOL_DECNET      261
 #define SOL_X25         262
diff --git a/include/sys/sysctl.h b/include/sys/sysctl.h
deleted file mode 100644
index c358b79..0000000
--- a/include/sys/sysctl.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef	_SYS_SYSCTL_H
-#define	_SYS_SYSCTL_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define __NEED_size_t
-#include <bits/alltypes.h>
-
-int sysctl (int *, int, void *, size_t *, void *, size_t);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/sys/time.h b/include/sys/time.h
index b6787c3..bfe1414 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -51,6 +51,17 @@ int adjtime (const struct timeval *, struct timeval *);
 	((a)->tv_usec += 1000000, (a)->tv_sec--) )
 #endif
 
+#if defined(_GNU_SOURCE)
+#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
+	(ts)->tv_sec = (tv)->tv_sec, \
+	(ts)->tv_nsec = (tv)->tv_usec * 1000, \
+	(void)0 )
+#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
+	(tv)->tv_sec = (ts)->tv_sec, \
+	(tv)->tv_usec = (ts)->tv_nsec / 1000, \
+	(void)0 )
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/wait.h b/include/sys/wait.h
index c794f5d..50c5c70 100644
--- a/include/sys/wait.h
+++ b/include/sys/wait.h
@@ -50,7 +50,7 @@ pid_t wait4 (pid_t, int *, int, struct rusage *);
 #define WCOREDUMP(s) ((s) & 0x80)
 #define WIFEXITED(s) (!WTERMSIG(s))
 #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
-#define WIFSIGNALED(s) (((s)&0xffff)-1 < 0xffu)
+#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
 #define WIFCONTINUED(s) ((s) == 0xffff)
 
 #ifdef __cplusplus
diff --git a/include/syslog.h b/include/syslog.h
index f7f545f..71dbd99 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -21,7 +21,7 @@ extern "C" {
 #define	LOG_MAKEPRI(f, p) (((f)<<3)|(p))
 
 #define LOG_MASK(p) (1<<(p))
-#define LOG_UPTO(p) ((1<<(p)+1)-1)
+#define LOG_UPTO(p) ((1<<((p)+1))-1)
 
 #define LOG_KERN     (0<<3)
 #define LOG_USER     (1<<3)
diff --git a/include/time.h b/include/time.h
index 7057409..dc88070 100644
--- a/include/time.h
+++ b/include/time.h
@@ -125,7 +125,7 @@ struct tm *getdate (const char *);
 
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-int stime(time_t *);
+int stime(const time_t *);
 time_t timegm(struct tm *);
 #endif
 
diff --git a/include/utmp.h b/include/utmp.h
index b357ac8..e9ba23e 100644
--- a/include/utmp.h
+++ b/include/utmp.h
@@ -10,6 +10,7 @@ extern "C" {
 #define ACCOUNTING 9
 #define UT_NAMESIZE 32
 #define UT_HOSTSIZE 256
+#define UT_LINESIZE 32
 
 struct lastlog {
 	time_t ll_time;
@@ -22,6 +23,8 @@ struct lastlog {
 #define ut_addr ut_addr_v6[0]
 #define utmp utmpx
 #define utmpname(x) (-1)
+#define e_exit __e_exit
+#define e_termination __e_termination
 
 void         endutent(void);
 struct utmp *getutent(void);
diff --git a/include/utmpx.h b/include/utmpx.h
index fd5f515..f0c3b01 100644
--- a/include/utmpx.h
+++ b/include/utmpx.h
@@ -5,6 +5,8 @@
 extern "C" {
 #endif
 
+#include <features.h>
+
 #define __NEED_pid_t
 #define __NEED_time_t
 #define __NEED_suseconds_t
@@ -12,19 +14,17 @@ extern "C" {
 
 #include <bits/alltypes.h>
 
-#define UT_LINESIZE 32
-
 struct utmpx
 {
 	short ut_type;
 	pid_t ut_pid;
-	char ut_line[UT_LINESIZE];
+	char ut_line[32];
 	char ut_id[4];
 	char ut_user[32];
 	char ut_host[256];
 	struct {
-		short e_termination;
-		short e_exit;
+		short __e_termination;
+		short __e_exit;
 	} ut_exit;
 	long ut_session;
 	struct timeval ut_tv;
@@ -39,7 +39,11 @@ struct utmpx *getutxline(const struct utmpx *);
 struct utmpx *pututxline(const struct utmpx *);
 void          setutxent(void);
 
+#if defined(_BSD_SOURCE) | defined(_GNU_SOURCE)
+#define e_exit __e_exit
+#define e_termination __e_termination
 void updwtmpx(const char *, const struct utmpx *);
+#endif
 
 #define EMPTY           0
 #define RUN_LVL         1
diff --git a/src/crypt/crypt_des.c b/src/crypt/crypt_des.c
index dc95dca..d5766a7 100644
--- a/src/crypt/crypt_des.c
+++ b/src/crypt/crypt_des.c
@@ -692,7 +692,7 @@ static uint32_t setup_salt(uint32_t salt)
 	return saltbits;
 }
 
-static void des_setkey(const unsigned char *key, struct expanded_key *ekey)
+void __des_setkey(const unsigned char *key, struct expanded_key *ekey)
 {
 	uint32_t k0, k1, rawkey0, rawkey1;
 	unsigned int shifts, round, i, ibit;
@@ -753,7 +753,7 @@ static void des_setkey(const unsigned char *key, struct expanded_key *ekey)
 /*
  * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
  */
-static void do_des(uint32_t l_in, uint32_t r_in,
+void __do_des(uint32_t l_in, uint32_t r_in,
     uint32_t *l_out, uint32_t *r_out,
     uint32_t count, uint32_t saltbits, const struct expanded_key *ekey)
 {
@@ -862,7 +862,7 @@ static void des_cipher(const unsigned char *in, unsigned char *out,
 	    ((uint32_t)in[5] << 16) |
 	    ((uint32_t)in[4] << 24);
 
-	do_des(rawl, rawr, &l_out, &r_out, count, saltbits, ekey);
+	__do_des(rawl, rawr, &l_out, &r_out, count, saltbits, ekey);
 
 	out[0] = l_out >> 24;
 	out[1] = l_out >> 16;
@@ -894,7 +894,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
 		if (*key)
 			key++;
 	}
-	des_setkey(keybuf, &ekey);
+	__des_setkey(keybuf, &ekey);
 
 	if (*setting == _PASSWORD_EFMT1) {
 		/*
@@ -929,7 +929,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
 			q = keybuf;
 			while (q <= &keybuf[sizeof(keybuf) - 1] && *key)
 				*q++ ^= *key++ << 1;
-			des_setkey(keybuf, &ekey);
+			__des_setkey(keybuf, &ekey);
 		}
 
 		memcpy(output, setting, 9);
@@ -957,7 +957,7 @@ static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char
 	/*
 	 * Do it.
 	 */
-	do_des(0, 0, &r0, &r1, count, setup_salt(salt), &ekey);
+	__do_des(0, 0, &r0, &r1, count, setup_salt(salt), &ekey);
 
 	/*
 	 * Now encode the result...
diff --git a/src/crypt/encrypt.c b/src/crypt/encrypt.c
new file mode 100644
index 0000000..9332a6d
--- /dev/null
+++ b/src/crypt/encrypt.c
@@ -0,0 +1,60 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+struct expanded_key {
+        uint32_t l[16], r[16];
+};
+
+void __des_setkey(const unsigned char *key, struct expanded_key *ekey);
+void __do_des(uint32_t l_in, uint32_t r_in,
+    uint32_t *l_out, uint32_t *r_out,
+    uint32_t count, uint32_t saltbits, const struct expanded_key *ekey);
+
+
+static struct expanded_key __encrypt_key;
+
+void setkey(const char *key)
+{
+	unsigned char bkey[8];
+	int i, j;
+
+	for (i = 0; i < 8; i++) {
+		bkey[i] = 0;
+		for (j = 7; j >= 0; j--, key++)
+			bkey[i] |= (uint32_t)(*key & 1) << j;
+	}
+
+	__des_setkey(bkey, &__encrypt_key);
+}
+
+void encrypt(char *block, int edflag)
+{
+	struct expanded_key decrypt_key, *key;
+	uint32_t b[2];
+	int i, j;
+	char *p;
+
+	p = block;
+	for (i = 0; i < 2; i++) {
+		b[i] = 0;
+		for (j = 31; j >= 0; j--, p++)
+			b[i] |= (uint32_t)(*p & 1) << j;
+	}
+
+	key = &__encrypt_key;
+	if (edflag) {
+		key = &decrypt_key;
+		for (i = 0; i < 16; i++) {
+			decrypt_key.l[i] = __encrypt_key.l[15-i];
+			decrypt_key.r[i] = __encrypt_key.r[15-i];
+		}
+	}
+
+	__do_des(b[0], b[1], b, b + 1, 1, 0, key);
+
+	p = block;
+	for (i = 0; i < 2; i++)
+		for (j = 31; j >= 0; j--)
+			*p++ = b[i]>>j & 1;
+}
diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c
index 4c34ba0..4a713fd 100644
--- a/src/fcntl/fcntl.c
+++ b/src/fcntl/fcntl.c
@@ -13,11 +13,11 @@ int fcntl(int fd, int cmd, ...)
 	arg = va_arg(ap, long);
 	va_end(ap);
 	if (cmd == F_SETFL) arg |= O_LARGEFILE;
-	if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, arg);
+	if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
 	if (cmd == F_GETOWN) {
 		struct f_owner_ex ex;
 		int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex);
-		if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, arg);
+		if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg);
 		if (ret) return __syscall_ret(ret);
 		return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid;
 	}
@@ -37,5 +37,14 @@ int fcntl(int fd, int cmd, ...)
 		if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC);
 		return __syscall_ret(ret);
 	}
-	return syscall(SYS_fcntl, fd, cmd, arg);
+	switch (cmd) {
+	case F_SETLK:
+	case F_SETLKW:
+	case F_GETLK:
+	case F_GETOWN_EX:
+	case F_SETOWN_EX:
+		return syscall(SYS_fcntl, fd, cmd, (void *)arg);
+	default:
+		return syscall(SYS_fcntl, fd, cmd, arg);
+	}
 }
diff --git a/src/fcntl/posix_fadvise.c b/src/fcntl/posix_fadvise.c
index 2170209..d5360e0 100644
--- a/src/fcntl/posix_fadvise.c
+++ b/src/fcntl/posix_fadvise.c
@@ -1,8 +1,11 @@
 #include <fcntl.h>
 #include "syscall.h"
+#include "libc.h"
 
 int posix_fadvise(int fd, off_t base, off_t len, int advice)
 {
 	return -(__syscall)(SYS_fadvise, fd, __SYSCALL_LL_O(base),
 		__SYSCALL_LL_E(len), advice);
 }
+
+LFS64(posix_fadvise);
diff --git a/src/fcntl/posix_fallocate.c b/src/fcntl/posix_fallocate.c
index 80a65cb..91d8063 100644
--- a/src/fcntl/posix_fallocate.c
+++ b/src/fcntl/posix_fallocate.c
@@ -1,8 +1,11 @@
 #include <fcntl.h>
 #include "syscall.h"
+#include "libc.h"
 
 int posix_fallocate(int fd, off_t base, off_t len)
 {
 	return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
 		__SYSCALL_LL_E(len));
 }
+
+LFS64(posix_fallocate);
diff --git a/src/fenv/i386/fenv.s b/src/fenv/i386/fenv.s
index f6036d6..a189ca2 100644
--- a/src/fenv/i386/fenv.s
+++ b/src/fenv/i386/fenv.s
@@ -126,7 +126,7 @@ fesetenv:
 	push %eax
 	push %eax
 	push %eax
-	push %eax
+	pushl $0xffff
 	push %eax
 	pushl $0x37f
 	fldenv (%esp)
diff --git a/src/fenv/x86_64/fenv.s b/src/fenv/x86_64/fenv.s
index 6aaf25e..b5aeaf4 100644
--- a/src/fenv/x86_64/fenv.s
+++ b/src/fenv/x86_64/fenv.s
@@ -76,7 +76,7 @@ fesetenv:
 	ret
 1:	push %rax
 	push %rax
-	push %rax
+	pushq $0xffff
 	pushq $0x37f
 	fldenv (%rsp)
 	pushq $0x1f80
diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
index 2083b2f..79be9fd 100644
--- a/src/internal/stdio_impl.h
+++ b/src/internal/stdio_impl.h
@@ -17,6 +17,7 @@
 #define F_EOF 16
 #define F_ERR 32
 #define F_SVB 64
+#define F_APP 128
 
 struct _IO_FILE {
 	unsigned flags;
diff --git a/src/ipc/semctl.c b/src/ipc/semctl.c
index 274e2cf..3d79f50 100644
--- a/src/ipc/semctl.c
+++ b/src/ipc/semctl.c
@@ -3,16 +3,22 @@
 #include "syscall.h"
 #include "ipc.h"
 
+union semun {
+	int val;
+	struct semid_ds *buf;
+	unsigned short *array;
+};
+
 int semctl(int id, int num, int cmd, ...)
 {
-	long arg;
+	union semun arg;
 	va_list ap;
 	va_start(ap, cmd);
-	arg = va_arg(ap, long);
+	arg = va_arg(ap, union semun);
 	va_end(ap);
 #ifdef SYS_semctl
-	return syscall(SYS_semctl, id, num, cmd | IPC_64, arg);
+	return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf);
 #else
-	return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg);
+	return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg.buf);
 #endif
 }
diff --git a/src/ldso/dladdr.c b/src/ldso/dladdr.c
index 265bb68..7ca718f 100644
--- a/src/ldso/dladdr.c
+++ b/src/ldso/dladdr.c
@@ -1,9 +1,9 @@
 #define _GNU_SOURCE
 #include <dlfcn.h>
 
-int __dladdr(void *, Dl_info *);
+int __dladdr(const void *, Dl_info *);
 
-int dladdr(void *addr, Dl_info *info)
+int dladdr(const void *addr, Dl_info *info)
 {
 	return __dladdr(addr, info);
 }
diff --git a/src/ldso/dynlink.c b/src/ldso/dynlink.c
index 27d92f2..a1bdf0f 100644
--- a/src/ldso/dynlink.c
+++ b/src/ldso/dynlink.c
@@ -253,7 +253,8 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
 			name = strings + sym->st_name;
 			ctx = IS_COPY(type) ? head->next : head;
 			def = find_sym(ctx, name, IS_PLT(type));
-			if (!def.sym && sym->st_info>>4 != STB_WEAK) {
+			if (!def.sym && (sym->st_shndx != SHN_UNDEF
+			    || sym->st_info>>4 != STB_WEAK)) {
 				snprintf(errbuf, sizeof errbuf,
 					"Error relocating %s: %s: symbol not found",
 					dso->name, name);
@@ -1331,7 +1332,7 @@ failed:
 	return 0;
 }
 
-int __dladdr(void *addr, Dl_info *info)
+int __dladdr(const void *addr, Dl_info *info)
 {
 	struct dso *p;
 	Sym *sym;
@@ -1441,7 +1442,7 @@ void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra)
 {
 	return 0;
 }
-int __dladdr (void *addr, Dl_info *info)
+int __dladdr (const void *addr, Dl_info *info)
 {
 	return 0;
 }
diff --git a/src/linux/clone.c b/src/linux/clone.c
new file mode 100644
index 0000000..b9e5594
--- /dev/null
+++ b/src/linux/clone.c
@@ -0,0 +1,19 @@
+#include <stdarg.h>
+#include <unistd.h>
+#include "pthread_impl.h"
+#include "syscall.h"
+
+int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
+{
+	va_list ap;
+	pid_t *ptid, *ctid;
+	void  *tls;
+
+	va_start(ap, arg);
+	ptid = va_arg(ap, pid_t *);
+	tls  = va_arg(ap, void *);
+	ctid = va_arg(ap, pid_t *);
+	va_end(ap);
+
+	return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid));
+}
diff --git a/src/linux/fallocate.c b/src/linux/fallocate.c
index 9146350..ae766d5 100644
--- a/src/linux/fallocate.c
+++ b/src/linux/fallocate.c
@@ -1,9 +1,13 @@
 #define _GNU_SOURCE
 #include <fcntl.h>
 #include "syscall.h"
+#include "libc.h"
 
 int fallocate(int fd, int mode, off_t base, off_t len)
 {
 	return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
 		__SYSCALL_LL_E(len));
 }
+
+#undef fallocate64
+LFS64(fallocate);
diff --git a/src/linux/inotify.c b/src/linux/inotify.c
index d3b4fa0..a417c89 100644
--- a/src/linux/inotify.c
+++ b/src/linux/inotify.c
@@ -15,7 +15,7 @@ int inotify_add_watch(int fd, const char *pathname, uint32_t mask)
 	return syscall(SYS_inotify_add_watch, fd, pathname, mask);
 }
 
-int inotify_rm_watch(int fd, uint32_t wd)
+int inotify_rm_watch(int fd, int wd)
 {
 	return syscall(SYS_inotify_rm_watch, fd, wd);
 }
diff --git a/src/linux/remap_file_pages.c b/src/linux/remap_file_pages.c
index f95c4cc..a9699ce 100644
--- a/src/linux/remap_file_pages.c
+++ b/src/linux/remap_file_pages.c
@@ -2,7 +2,7 @@
 #include <sys/mman.h>
 #include "syscall.h"
 
-int remap_file_pages(void *addr, size_t size, int prot, ssize_t pgoff, int flags)
+int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags)
 {
 	return syscall(SYS_remap_file_pages, addr, size, prot, pgoff, flags);
 }
diff --git a/src/linux/stime.c b/src/linux/stime.c
index 29a1ec6..7d0443b 100644
--- a/src/linux/stime.c
+++ b/src/linux/stime.c
@@ -2,7 +2,7 @@
 #include <time.h>
 #include <sys/time.h>
 
-int stime(time_t *t)
+int stime(const time_t *t)
 {
 	struct timeval tv = { .tv_sec = *t, .tv_usec = 0 };
 	return settimeofday(&tv, (void *)0);
diff --git a/src/locale/wcsxfrm.c b/src/locale/wcsxfrm.c
index cb79c97..5d89e7d 100644
--- a/src/locale/wcsxfrm.c
+++ b/src/locale/wcsxfrm.c
@@ -6,10 +6,12 @@
 size_t __wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t loc)
 {
 	size_t l = wcslen(src);
-	if (l >= n) {
+	if (l < n) {
+		wmemcpy(dest, src, l+1);
+	} else if (n) {
 		wmemcpy(dest, src, n-1);
 		dest[n-1] = 0;
-	} else wcscpy(dest, src);
+	}
 	return l;
 }
 
diff --git a/src/math/i386/remainder.s b/src/math/i386/remainder.s
index 47ee340..7f4be05 100644
--- a/src/math/i386/remainder.s
+++ b/src/math/i386/remainder.s
@@ -1,6 +1,9 @@
 .global remainder
 .type remainder,@function
 remainder:
+.weak drem
+.type drem,@function
+drem:
 	fldl 12(%esp)
 	fldl 4(%esp)
 1:	fprem1
diff --git a/src/math/i386/remainderf.s b/src/math/i386/remainderf.s
index 5b5fc23..ac6e367 100644
--- a/src/math/i386/remainderf.s
+++ b/src/math/i386/remainderf.s
@@ -1,6 +1,9 @@
 .global remainderf
 .type remainderf,@function
 remainderf:
+.weak dremf
+.type dremf,@function
+dremf:
 	flds 8(%esp)
 	flds 4(%esp)
 1:	fprem1
diff --git a/src/misc/nftw.c b/src/misc/nftw.c
index b2e84bc..efb2b89 100644
--- a/src/misc/nftw.c
+++ b/src/misc/nftw.c
@@ -46,8 +46,7 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
 		type = FTW_F;
 	}
 
-	if ((flags & FTW_MOUNT) && h
-	 && (st.st_dev != h->dev || st.st_ino != h->ino))
+	if ((flags & FTW_MOUNT) && h && st.st_dev != h->dev)
 		return 0;
 	
 	new.chain = h;
diff --git a/src/network/inet_legacy.c b/src/network/inet_legacy.c
index 0a0ad6f..de5b75c 100644
--- a/src/network/inet_legacy.c
+++ b/src/network/inet_legacy.c
@@ -16,9 +16,8 @@ int inet_aton(const char *cp, struct in_addr *inp)
 	return 1;
 }
 
-struct in_addr inet_makeaddr(int net, int host)
+struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h)
 {
-	uint32_t n = net, h = host;
 	if (n < 256) h |= n<<24;
 	else if (n < 65536) h |= n<<16;
 	else h |= n<<8;
diff --git a/src/network/proto.c b/src/network/proto.c
index 031003a..3d0f584 100644
--- a/src/network/proto.c
+++ b/src/network/proto.c
@@ -4,7 +4,7 @@
 /* do we really need all these?? */
 
 static int idx;
-static const unsigned char protos[][6] = {
+static const unsigned char protos[][8] = {
 	"\000ip",
 	"\001icmp",
 	"\002igmp",
@@ -13,7 +13,9 @@ static const unsigned char protos[][6] = {
 	"\014pup",
 	"\021udp",
 	"\026idp",
-	"\377raw"
+	"\051ipv6",
+	"\072icmpv6",
+	"\377raw",
 	"\0\0"
 };
 
diff --git a/src/prng/random.c b/src/prng/random.c
index 4ad6205..e250e28 100644
--- a/src/prng/random.c
+++ b/src/prng/random.c
@@ -1,10 +1,3 @@
-/*
- * random.c - Copyright © 2011 Szabolcs Nagy
- * Permission to use, copy, modify, and/or distribute this code
- * for any purpose with or without fee is hereby granted.
- * There is no warranty.
-*/
-
 #include <stdlib.h>
 #include <stdint.h>
 #include "libc.h"
@@ -12,11 +5,7 @@
 /*
 this code uses the same lagged fibonacci generator as the
 original bsd random implementation except for the seeding
-
-different seeds produce different sequences with long period
-(other libcs seed the state with a park-miller generator
-when seed=0 some fail to produce good random sequence
-others produce the same sequence as another seed)
+which was broken in the original
 */
 
 static uint32_t init[] = {
@@ -98,6 +87,7 @@ char *initstate(unsigned seed, char *state, size_t size) {
 		n = 63;
 	x = (uint32_t*)state + 1;
 	__srandom(seed);
+	savestate();
 	UNLOCK(lock);
 	return old;
 }
diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c
index eb98f9f..f675a13 100644
--- a/src/process/posix_spawn.c
+++ b/src/process/posix_spawn.c
@@ -166,7 +166,7 @@ int __posix_spawnx(pid_t *restrict res, const char *restrict path,
 
 	close(args.p[0]);
 
-	if (!ec) *res = pid;
+	if (!ec && res) *res = pid;
 
 	pthread_sigmask(SIG_SETMASK, &args.oldmask, 0);
 	pthread_setcancelstate(cs, 0);
diff --git a/src/signal/sigandset.c b/src/signal/sigandset.c
index e0c6f48..974186f 100644
--- a/src/signal/sigandset.c
+++ b/src/signal/sigandset.c
@@ -3,7 +3,7 @@
 
 #define SST_SIZE (_NSIG/8/sizeof(long))
 
-int sigandset(sigset_t *dest, sigset_t *left, sigset_t *right)
+int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
 {
 	unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
 	for(; i < SST_SIZE; i++) d[i] = l[i] & r[i];
diff --git a/src/signal/sigorset.c b/src/signal/sigorset.c
index df1b1b1..ed48873 100644
--- a/src/signal/sigorset.c
+++ b/src/signal/sigorset.c
@@ -3,7 +3,7 @@
 
 #define SST_SIZE (_NSIG/8/sizeof(long))
 
-int sigorset(sigset_t *dest, sigset_t *left, sigset_t *right)
+int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
 {
 	unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right;
 	for(; i < SST_SIZE; i++) d[i] = l[i] | r[i];
diff --git a/src/stdio/__fdopen.c b/src/stdio/__fdopen.c
index 59690f6..a6ae73a 100644
--- a/src/stdio/__fdopen.c
+++ b/src/stdio/__fdopen.c
@@ -32,7 +32,9 @@ FILE *__fdopen(int fd, const char *mode)
 	/* Set append mode on fd if opened for append */
 	if (*mode == 'a') {
 		int flags = __syscall(SYS_fcntl, fd, F_GETFL);
-		__syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND);
+		if (!(flags & O_APPEND))
+			__syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND);
+		f->flags |= F_APP;
 	}
 
 	f->fd = fd;
diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c
index 82371e3..bb62897 100644
--- a/src/stdio/ftell.c
+++ b/src/stdio/ftell.c
@@ -4,7 +4,9 @@
 
 off_t __ftello_unlocked(FILE *f)
 {
-	off_t pos = f->seek(f, 0, SEEK_CUR);
+	off_t pos = f->seek(f, 0,
+		(f->flags & F_APP) && f->wpos > f->wbase
+		? SEEK_END : SEEK_CUR);
 	if (pos < 0) return pos;
 
 	/* Adjust for data in buffer. */
diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c
index 0091a8d..d4d2454 100644
--- a/src/stdio/vfscanf.c
+++ b/src/stdio/vfscanf.c
@@ -328,3 +328,5 @@ match_fail:
 	FUNLOCK(f);
 	return matches;
 }
+
+weak_alias(vfscanf,__isoc99_vfscanf);
diff --git a/src/thread/__wait.c b/src/thread/__wait.c
index 041a066..a1e4780 100644
--- a/src/thread/__wait.c
+++ b/src/thread/__wait.c
@@ -10,6 +10,6 @@ void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
 	}
 	if (waiters) a_inc(waiters);
 	while (*addr==val)
-		__syscall(SYS_futex, (long)addr, FUTEX_WAIT|priv, val, 0);
+		__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0);
 	if (waiters) a_dec(waiters);
 }
diff --git a/src/thread/arm/clone.s b/src/thread/arm/clone.s
index daf8f55..d146999 100644
--- a/src/thread/arm/clone.s
+++ b/src/thread/arm/clone.s
@@ -1,10 +1,7 @@
 .text
 .global __clone
-.weak clone
 .type   __clone,%function
-.type   clone,%function
 __clone:
-clone:
 	stmfd sp!,{r4,r5,r6,r7}
 	mov r7,#120
 	mov r6,r3
diff --git a/src/thread/clone.c b/src/thread/clone.c
index 339e28a..be80c8e 100644
--- a/src/thread/clone.c
+++ b/src/thread/clone.c
@@ -1,10 +1,7 @@
 #include <errno.h>
-#include "libc.h"
+#include "pthread_impl.h"
 
 int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
 {
-	errno = ENOSYS;
-	return -1;
+	return -ENOSYS;
 }
-
-weak_alias(__clone, clone);
diff --git a/src/thread/i386/clone.s b/src/thread/i386/clone.s
index bebf01a..52fe7ef 100644
--- a/src/thread/i386/clone.s
+++ b/src/thread/i386/clone.s
@@ -1,10 +1,7 @@
 .text
 .global __clone
-.weak clone
 .type   __clone,@function
-.type   clone,@function
 __clone:
-clone:
 	push %ebp
 	mov %esp,%ebp
 	push %ebx
diff --git a/src/thread/microblaze/clone.s b/src/thread/microblaze/clone.s
index 030a9c3..13448a3 100644
--- a/src/thread/microblaze/clone.s
+++ b/src/thread/microblaze/clone.s
@@ -1,14 +1,11 @@
 .global __clone
-.weak clone
 .type   __clone,@function
-.type   clone,@function
 
 # r5, r6, r7, r8, r9, r10, stack
 # fn, st, fl, ar, pt, tl, ct
 # fl, st, __, pt, ct, tl
 
 __clone:
-clone:
 	andi    r6, r6, -16
 	addi    r6, r6, -16
 	swi     r5, r6, 0
@@ -23,7 +20,7 @@ clone:
 	beqi	r3, 1f
 	rtsd    r15, 8
 	nop
-	
+
 1:	lwi     r3, r1, 0
 	lwi     r5, r1, 4
 	brald   r15, r3
diff --git a/src/thread/x86_64/clone.s b/src/thread/x86_64/clone.s
index 4db081c..ee59903 100644
--- a/src/thread/x86_64/clone.s
+++ b/src/thread/x86_64/clone.s
@@ -1,10 +1,7 @@
 .text
 .global __clone
-.weak clone
 .type   __clone,@function
-.type   clone,@function
 __clone:
-clone:
 	xor %eax,%eax
 	mov $56,%al
 	mov %rdi,%r11
diff --git a/src/time/timer_delete.c b/src/time/timer_delete.c
index c81f921..7c97eeb 100644
--- a/src/time/timer_delete.c
+++ b/src/time/timer_delete.c
@@ -10,5 +10,5 @@ int timer_delete(timer_t t)
 		__wake(&td->timer_id, 1, 1);
 		return 0;
 	}
-	return __syscall(SYS_timer_delete, (long)t);
+	return __syscall(SYS_timer_delete, t);
 }
diff --git a/src/time/timer_getoverrun.c b/src/time/timer_getoverrun.c
index 5336128..e7f891e 100644
--- a/src/time/timer_getoverrun.c
+++ b/src/time/timer_getoverrun.c
@@ -8,5 +8,5 @@ int timer_getoverrun(timer_t t)
 		pthread_t td = (void *)((uintptr_t)t << 1);
 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
 	}
-	return syscall(SYS_timer_getoverrun, (long)t);
+	return syscall(SYS_timer_getoverrun, t);
 }
diff --git a/src/time/timer_gettime.c b/src/time/timer_gettime.c
index 1d90207..ed6d8d6 100644
--- a/src/time/timer_gettime.c
+++ b/src/time/timer_gettime.c
@@ -8,5 +8,5 @@ int timer_gettime(timer_t t, struct itimerspec *val)
 		pthread_t td = (void *)((uintptr_t)t << 1);
 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
 	}
-	return syscall(SYS_timer_gettime, (long)t, val);
+	return syscall(SYS_timer_gettime, t, val);
 }
diff --git a/src/time/timer_settime.c b/src/time/timer_settime.c
index f5f36fe..62631aa 100644
--- a/src/time/timer_settime.c
+++ b/src/time/timer_settime.c
@@ -8,5 +8,5 @@ int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, s
 		pthread_t td = (void *)((uintptr_t)t << 1);
 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX);
 	}
-	return syscall(SYS_timer_settime, (long)t, flags, val, old);
+	return syscall(SYS_timer_settime, t, flags, val, old);
 }
diff --git a/tools/install.sh b/tools/install.sh
index 4e5a8b9..d913b60 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -51,6 +51,7 @@ if test "$symlink" ; then
 ln -s "$1" "$tmp"
 else
 cat < "$1" > "$tmp"
+chmod "$mode" "$tmp"
 fi
 
 mv -f "$tmp" "$2"
@@ -60,6 +61,4 @@ printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
 exit 1
 }
 
-test "$symlink" || chmod "$mode" "$2"
-
 exit 0