don't install make-mac-package.sh
[arla.git] / tests / append-over-page.c
blobf2af882487db19e25045e0e8e3150f24c63f24d3
1 /*
2 * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <errno.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/mman.h>
46 #include <fcntl.h>
47 #include <unistd.h>
48 #include <dirent.h>
50 #include <roken.h>
52 #include <err.h>
54 #ifndef MAP_FAILED
55 #define MAP_FAILED ((void *)-1)
56 #endif
58 RCSID("$Id$");
60 static char long_buf[] =
61 "1000\n"
62 "1001\n"
63 "1002\n"
64 "1003\n"
65 "1004\n"
66 "1005\n"
67 "1006\n"
68 "1007\n"
69 "1008\n"
70 "1009\n"
71 "1010\n"
72 "1011\n"
73 "1012\n"
74 "1013\n"
75 "1014\n"
76 "1015\n"
77 "1016\n"
78 "1017\n"
79 "1018\n"
80 "1019\n"
81 "1020\n"
82 "1021\n"
83 "1022\n"
84 "1023\n"
85 "1024\n"
86 "1025\n"
87 "1026\n"
88 "1027\n"
89 "1028\n"
90 "1029\n"
91 "1030\n"
92 "1031\n"
93 "1032\n"
94 "1033\n"
95 "1034\n"
96 "1035\n"
97 "1036\n"
98 "1037\n"
99 "1038\n"
100 "1039\n"
101 "1040\n"
102 "1041\n"
103 "1042\n"
104 "1043\n"
105 "1044\n"
106 "1045\n"
107 "1046\n"
108 "1047\n"
109 "1048\n"
110 "1049\n"
111 "1050\n"
112 "1051\n"
113 "1052\n"
114 "1053\n"
115 "1054\n"
116 "1055\n"
117 "1056\n"
118 "1057\n"
119 "1058\n"
120 "1059\n"
121 "1060\n"
122 "1061\n"
123 "1062\n"
124 "1063\n"
125 "1064\n"
126 "1065\n"
127 "1066\n"
128 "1067\n"
129 "1068\n"
130 "1069\n"
131 "1070\n"
132 "1071\n"
133 "1072\n"
134 "1073\n"
135 "1074\n"
136 "1075\n"
137 "1076\n"
138 "1077\n"
139 "1078\n"
140 "1079\n"
141 "1080\n"
142 "1081\n"
143 "1082\n"
144 "1083\n"
145 "1084\n"
146 "1085\n"
147 "1086\n"
148 "1087\n"
149 "1088\n"
150 "1089\n"
151 "1090\n"
152 "1091\n"
153 "1092\n"
154 "1093\n"
155 "1094\n"
156 "1095\n"
157 "1096\n"
158 "1097\n"
159 "1098\n"
160 "1099\n"
161 "1100\n"
162 "1101\n"
163 "1102\n"
164 "1103\n"
165 "1104\n"
166 "1105\n"
167 "1106\n"
168 "1107\n"
169 "1108\n"
170 "1109\n"
171 "1110\n"
172 "1111\n"
173 "1112\n"
174 "1113\n"
175 "1114\n"
176 "1115\n"
177 "1116\n"
178 "1117\n"
179 "1118\n"
180 "1119\n"
181 "1120\n"
182 "1121\n"
183 "1122\n"
184 "1123\n"
185 "1124\n"
186 "1125\n"
187 "1126\n"
188 "1127\n"
189 "1128\n"
190 "1129\n"
191 "1130\n"
192 "1131\n"
193 "1132\n"
194 "1133\n"
195 "1134\n"
196 "1135\n"
197 "1136\n"
198 "1137\n"
199 "1138\n"
200 "1139\n"
201 "1140\n"
202 "1141\n"
203 "1142\n"
204 "1143\n"
205 "1144\n"
206 "1145\n"
207 "1146\n"
208 "1147\n"
209 "1148\n"
210 "1149\n"
211 "1150\n"
212 "1151\n"
213 "1152\n"
214 "1153\n"
215 "1154\n"
216 "1155\n"
217 "1156\n"
218 "1157\n"
219 "1158\n"
220 "1159\n"
221 "1160\n"
222 "1161\n"
223 "1162\n"
224 "1163\n"
225 "1164\n"
226 "1165\n"
227 "1166\n"
228 "1167\n"
229 "1168\n"
230 "1169\n"
231 "1170\n"
232 "1171\n"
233 "1172\n"
234 "1173\n"
235 "1174\n"
236 "1175\n"
237 "1176\n"
238 "1177\n"
239 "1178\n"
240 "1179\n"
241 "1180\n"
242 "1181\n"
243 "1182\n"
244 "1183\n"
245 "1184\n"
246 "1185\n"
247 "1186\n"
248 "1187\n"
249 "1188\n"
250 "1189\n"
251 "1190\n"
252 "1191\n"
253 "1192\n"
254 "1193\n"
255 "1194\n"
256 "1195\n"
257 "1196\n"
258 "1197\n"
259 "1198\n"
260 "1199\n"
261 "1200\n"
262 "1201\n"
263 "1202\n"
264 "1203\n"
265 "1204\n"
266 "1205\n"
267 "1206\n"
268 "1207\n"
269 "1208\n"
270 "1209\n"
271 "1210\n"
272 "1211\n"
273 "1212\n"
274 "1213\n"
275 "1214\n"
276 "1215\n"
277 "1216\n"
278 "1217\n"
279 "1218\n"
280 "1219\n"
281 "1220\n"
282 "1221\n"
283 "1222\n"
284 "1223\n"
285 "1224\n"
286 "1225\n"
287 "1226\n"
288 "1227\n"
289 "1228\n"
290 "1229\n"
291 "1230\n"
292 "1231\n"
293 "1232\n"
294 "1233\n"
295 "1234\n"
296 "1235\n"
297 "1236\n"
298 "1237\n"
299 "1238\n"
300 "1239\n"
301 "1240\n"
302 "1241\n"
303 "1242\n"
304 "1243\n"
305 "1244\n"
306 "1245\n"
307 "1246\n"
308 "1247\n"
309 "1248\n"
310 "1249\n"
311 "1250\n"
312 "1251\n"
313 "1252\n"
314 "1253\n"
315 "1254\n"
316 "1255\n"
317 "1256\n"
318 "1257\n"
319 "1258\n"
320 "1259\n"
321 "1260\n"
322 "1261\n"
323 "1262\n"
324 "1263\n"
325 "1264\n"
326 "1265\n"
327 "1266\n"
328 "1267\n"
329 "1268\n"
330 "1269\n"
331 "1270\n"
332 "1271\n"
333 "1272\n"
334 "1273\n"
335 "1274\n"
336 "1275\n"
337 "1276\n"
338 "1277\n"
339 "1278\n"
340 "1279\n"
341 "1280\n"
342 "1281\n"
343 "1282\n"
344 "1283\n"
345 "1284\n"
346 "1285\n"
347 "1286\n"
348 "1287\n"
349 "1288\n"
350 "1289\n"
351 "1290\n"
352 "1291\n"
353 "1292\n"
354 "1293\n"
355 "1294\n"
356 "1295\n"
357 "1296\n"
358 "1297\n"
359 "1298\n"
360 "1299\n"
361 "1300\n"
362 "1301\n"
363 "1302\n"
364 "1303\n"
365 "1304\n"
366 "1305\n"
367 "1306\n"
368 "1307\n"
369 "1308\n"
370 "1309\n"
371 "1310\n"
372 "1311\n"
373 "1312\n"
374 "1313\n"
375 "1314\n"
376 "1315\n"
377 "1316\n"
378 "1317\n"
379 "1318\n"
380 "1319\n"
381 "1320\n"
382 "1321\n"
383 "1322\n"
384 "1323\n"
385 "1324\n"
386 "1325\n"
387 "1326\n"
388 "1327\n"
389 "1328\n"
390 "1329\n"
391 "1330\n"
392 "1331\n"
393 "1332\n"
394 "1333\n"
395 "1334\n"
396 "1335\n"
397 "1336\n"
398 "1337\n"
399 "1338\n"
400 "1339\n"
401 "1340\n"
402 "1341\n"
403 "1342\n"
404 "1343\n"
405 "1344\n"
406 "1345\n"
407 "1346\n"
408 "1347\n"
409 "1348\n"
410 "1349\n"
411 "1350\n"
412 "1351\n"
413 "1352\n"
414 "1353\n"
415 "1354\n"
416 "1355\n"
417 "1356\n"
418 "1357\n"
419 "1358\n"
420 "1359\n"
421 "1360\n"
422 "1361\n"
423 "1362\n"
424 "1363\n"
425 "1364\n"
426 "1365\n"
427 "1366\n"
428 "1367\n"
429 "1368\n"
430 "1369\n"
431 "1370\n"
432 "1371\n"
433 "1372\n"
434 "1373\n"
435 "1374\n"
436 "1375\n"
437 "1376\n"
438 "1377\n"
439 "1378\n"
440 "1379\n"
441 "1380\n"
442 "1381\n"
443 "1382\n"
444 "1383\n"
445 "1384\n"
446 "1385\n"
447 "1386\n"
448 "1387\n"
449 "1388\n"
450 "1389\n"
451 "1390\n"
452 "1391\n"
453 "1392\n"
454 "1393\n"
455 "1394\n"
456 "1395\n"
457 "1396\n"
458 "1397\n"
459 "1398\n"
460 "1399\n"
461 "1400\n"
462 "1401\n"
463 "1402\n"
464 "1403\n"
465 "1404\n"
466 "1405\n"
467 "1406\n"
468 "1407\n"
469 "1408\n"
470 "1409\n"
471 "1410\n"
472 "1411\n"
473 "1412\n"
474 "1413\n"
475 "1414\n"
476 "1415\n"
477 "1416\n"
478 "1417\n"
479 "1418\n"
480 "1419\n"
481 "1420\n"
482 "1421\n"
483 "1422\n"
484 "1423\n"
485 "1424\n"
486 "1425\n"
487 "1426\n"
488 "1427\n"
489 "1428\n"
490 "1429\n"
491 "1430\n"
492 "1431\n"
493 "1432\n"
494 "1433\n"
495 "1434\n"
496 "1435\n"
497 "1436\n"
498 "1437\n"
499 "1438\n"
500 "1439\n"
501 "1440\n"
502 "1441\n"
503 "1442\n"
504 "1443\n"
505 "1444\n"
506 "1445\n"
507 "1446\n"
508 "1447\n"
509 "1448\n"
510 "1449\n"
511 "1450\n"
512 "1451\n"
513 "1452\n"
514 "1453\n"
515 "1454\n"
516 "1455\n"
517 "1456\n"
518 "1457\n"
519 "1458\n"
520 "1459\n"
521 "1460\n"
522 "1461\n"
523 "1462\n"
524 "1463\n"
525 "1464\n"
526 "1465\n"
527 "1466\n"
528 "1467\n"
529 "1468\n"
530 "1469\n"
531 "1470\n"
532 "1471\n"
533 "1472\n"
534 "1473\n"
535 "1474\n"
536 "1475\n"
537 "1476\n"
538 "1477\n"
539 "1478\n"
540 "1479\n"
541 "1480\n"
542 "1481\n"
543 "1482\n"
544 "1483\n"
545 "1484\n"
546 "1485\n"
547 "1486\n"
548 "1487\n"
549 "1488\n"
550 "1489\n"
551 "1490\n"
552 "1491\n"
553 "1492\n"
554 "1493\n"
555 "1494\n"
556 "1495\n"
557 "1496\n"
558 "1497\n"
559 "1498\n"
560 "1499\n"
561 "1500\n"
562 "1501\n"
563 "1502\n"
564 "1503\n"
565 "1504\n"
566 "1505\n"
567 "1506\n"
568 "1507\n"
569 "1508\n"
570 "1509\n"
571 "1510\n"
572 "1511\n"
573 "1512\n"
574 "1513\n"
575 "1514\n"
576 "1515\n"
577 "1516\n"
578 "1517\n"
579 "1518\n"
580 "1519\n"
581 "1520\n"
582 "1521\n"
583 "1522\n"
584 "1523\n"
585 "1524\n"
586 "1525\n"
587 "1526\n"
588 "1527\n"
589 "1528\n"
590 "1529\n"
591 "1530\n"
592 "1531\n"
593 "1532\n"
594 "1533\n"
595 "1534\n"
596 "1535\n"
597 "1536\n"
598 "1537\n"
599 "1538\n"
600 "1539\n"
601 "1540\n"
602 "1541\n"
603 "1542\n"
604 "1543\n"
605 "1544\n"
606 "1545\n"
607 "1546\n"
608 "1547\n"
609 "1548\n"
610 "1549\n"
611 "1550\n"
612 "1551\n"
613 "1552\n"
614 "1553\n"
615 "1554\n"
616 "1555\n"
617 "1556\n"
618 "1557\n"
619 "1558\n"
620 "1559\n"
621 "1560\n"
622 "1561\n"
623 "1562\n"
624 "1563\n"
625 "1564\n"
626 "1565\n"
627 "1566\n"
628 "1567\n"
629 "1568\n"
630 "1569\n"
631 "1570\n"
632 "1571\n"
633 "1572\n"
634 "1573\n"
635 "1574\n"
636 "1575\n"
637 "1576\n"
638 "1577\n"
639 "1578\n"
640 "1579\n"
641 "1580\n"
642 "1581\n"
643 "1582\n"
644 "1583\n"
645 "1584\n"
646 "1585\n"
647 "1586\n"
648 "1587\n"
649 "1588\n"
650 "1589\n"
651 "1590\n"
652 "1591\n"
653 "1592\n"
654 "1593\n"
655 "1594\n"
656 "1595\n"
657 "1596\n"
658 "1597\n"
659 "1598\n"
660 "1599\n"
661 "1600\n"
662 "1601\n"
663 "1602\n"
664 "1603\n"
665 "1604\n"
666 "1605\n"
667 "1606\n"
668 "1607\n"
669 "1608\n"
670 "1609\n"
671 "1610\n"
672 "1611\n"
673 "1612\n"
674 "1613\n"
675 "1614\n"
676 "1615\n"
677 "1616\n"
678 "1617\n"
679 "1618\n"
680 "1619\n"
681 "1620\n"
682 "1621\n"
683 "1622\n"
684 "1623\n"
685 "1624\n"
686 "1625\n"
687 "1626\n"
688 "1627\n"
689 "1628\n"
690 "1629\n"
691 "1630\n"
692 "1631\n"
693 "1632\n"
694 "1633\n"
695 "1634\n"
696 "1635\n"
697 "1636\n"
698 "1637\n"
699 "1638\n"
700 "1639\n"
701 "1640\n"
702 "1641\n"
703 "1642\n"
704 "1643\n"
705 "1644\n"
706 "1645\n"
707 "1646\n"
708 "1647\n"
709 "1648\n"
710 "1649\n"
711 "1650\n"
712 "1651\n"
713 "1652\n"
714 "1653\n"
715 "1654\n"
716 "1655\n"
717 "1656\n"
718 "1657\n"
719 "1658\n"
720 "1659\n"
721 "1660\n"
722 "1661\n"
723 "1662\n"
724 "1663\n"
725 "1664\n"
726 "1665\n"
727 "1666\n"
728 "1667\n"
729 "1668\n"
730 "1669\n"
731 "1670\n"
732 "1671\n"
733 "1672\n"
734 "1673\n"
735 "1674\n"
736 "1675\n"
737 "1676\n"
738 "1677\n"
739 "1678\n"
740 "1679\n"
741 "1680\n"
742 "1681\n"
743 "1682\n"
744 "1683\n"
745 "1684\n"
746 "1685\n"
747 "1686\n"
748 "1687\n"
749 "1688\n"
750 "1689\n"
751 "1690\n"
752 "1691\n"
753 "1692\n"
754 "1693\n"
755 "1694\n"
756 "1695\n"
757 "1696\n"
758 "1697\n"
759 "1698\n"
760 "1699\n"
761 "1700\n"
762 "1701\n"
763 "1702\n"
764 "1703\n"
765 "1704\n"
766 "1705\n"
767 "1706\n"
768 "1707\n"
769 "1708\n"
770 "1709\n"
771 "1710\n"
772 "1711\n"
773 "1712\n"
774 "1713\n"
775 "1714\n"
776 "1715\n"
777 "1716\n"
778 "1717\n"
779 "1718\n"
780 "1719\n"
781 "1720\n"
782 "1721\n"
783 "1722\n"
784 "1723\n"
785 "1724\n"
786 "1725\n"
787 "1726\n"
788 "1727\n"
789 "1728\n"
790 "1729\n"
791 "1730\n"
792 "1731\n"
793 "1732\n"
794 "1733\n"
795 "1734\n"
796 "1735\n"
797 "1736\n"
798 "1737\n"
799 "1738\n"
800 "1739\n"
801 "1740\n"
802 "1741\n"
803 "1742\n"
804 "1743\n"
805 "1744\n"
806 "1745\n"
807 "1746\n"
808 "1747\n"
809 "1748\n"
810 "1749\n"
811 "1750\n"
812 "1751\n"
813 "1752\n"
814 "1753\n"
815 "1754\n"
816 "1755\n"
817 "1756\n"
818 "1757\n"
819 "1758\n"
820 "1759\n"
821 "1760\n"
822 "1761\n"
823 "1762\n"
824 "1763\n"
825 "1764\n"
826 "1765\n"
827 "1766\n"
828 "1767\n"
829 "1768\n"
830 "1769\n"
831 "1770\n"
832 "1771\n"
833 "1772\n"
834 "1773\n"
835 "1774\n"
836 "1775\n"
837 "1776\n"
838 "1777\n"
839 "1778\n"
840 "1779\n"
841 "1780\n"
842 "1781\n"
843 "1782\n"
844 "1783\n"
845 "1784\n"
846 "1785\n"
847 "1786\n"
848 "1787\n"
849 "1788\n"
850 "1789\n"
851 "1790\n"
852 "1791\n"
853 "1792\n"
854 "1793\n"
855 "1794\n"
856 "1795\n"
857 "1796\n"
858 "1797\n"
859 "1798\n"
860 "1799\n"
861 "1800\n"
862 "1801\n"
863 "1802\n"
864 "1803\n"
865 "1804\n"
866 "1805\n"
867 "1806\n"
868 "1807\n"
869 "1808\n"
870 "1809\n"
871 "1810\n"
872 "1811\n"
873 "1812\n"
874 "1813\n"
875 "1814\n"
876 "1815\n"
877 "1816\n"
878 "1817\n"
879 "1818\n"
880 "1819\n"
881 "1820\n"
882 "1821\n"
883 "1822\n"
884 "1823\n"
885 "1824\n"
886 "1825\n"
887 "1826\n";
890 * compare this file with read and mmap.
891 * return 0 iff identical.
894 static int
895 compare_file (const char *filename)
897 struct stat sb;
898 int fd;
899 int ret;
900 void *read_buf;
901 void *mmap_buf;
903 fd = open (filename, O_RDONLY);
904 if (fd < 0)
905 err(1, "open %s", filename);
906 ret = fstat (fd, &sb);
907 if (ret < 0)
908 err (1, "stat %s", filename);
909 read_buf = malloc (sb.st_size);
910 if (read_buf == NULL)
911 err (1, "malloc %u", (unsigned)sb.st_size);
912 ret = read (fd, read_buf, sb.st_size);
913 if (ret < 0)
914 err (1, "read %s", filename);
915 if (ret != sb.st_size)
916 errx (1, "short read from %s", filename);
917 mmap_buf = mmap (NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
918 if (mmap_buf == (void *)MAP_FAILED)
919 err (1, "mmap %s", filename);
920 ret = memcmp (read_buf, mmap_buf, sb.st_size);
921 close (fd);
922 free (read_buf);
923 return ret;
926 static void
927 doit (const char *filename)
929 int fd;
930 int ret;
932 fd = open (filename, O_WRONLY | O_APPEND | O_CREAT | O_TRUNC, 0600);
933 if (fd < 0)
934 err (1, "open %s", filename);
935 ret = close (fd);
936 if (ret < 0)
937 err (1, "close %s", filename);
938 fd = open (filename, O_WRONLY | O_APPEND);
939 if (fd < 0)
940 err (1, "open %s", filename);
941 ret = write (fd, "foobar\n", 7);
942 if (ret < 0)
943 err (1, "write %s", filename);
944 if (ret != 7)
945 errx (1, "short write to %s", filename);
946 ret = close (fd);
947 if (ret < 0)
948 err(1, "close %s", filename);
950 if(compare_file (filename))
951 errx (1, "compare 1 failed");
953 fd = open (filename, O_WRONLY | O_APPEND);
954 if (fd < 0)
955 err (1, "open %s", filename);
956 ret = write (fd, long_buf, strlen(long_buf));
957 if (ret < 0)
958 err (1, "write %s", filename);
959 if (ret != strlen(long_buf))
960 errx (1, "short write to %s", filename);
961 ret = close (fd);
962 if (ret < 0)
963 err(1, "close %s", filename);
965 if(compare_file (filename))
966 errx (1, "compare 2 failed");
970 main(int argc, char **argv)
972 const char *file = "blaha";
974 setprogname (argv[0]);
975 if (argc != 1 && argc != 2)
976 errx (1, "usage: %s [file]", argv[0]);
977 if (argc == 2)
978 file = argv[1];
979 doit (file);
980 return 0;