Welcome to mirror list, hosted at ThFree Co, Russian Federation.

symlink01.c « ltp « winsup.api « testsuite « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 660a6d2e6357b9415af3324a70f7499870b005f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
/*
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like.  Any license provided herein, whether implied or
 * otherwise, applies only to this software file.  Patent licenses, if
 * any, provided herein do not apply to combinations of this program with
 * other software, or any other product whatsoever.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write the Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
 * 
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 * Mountain View, CA  94043, or:
 * 
 * http://www.sgi.com 
 * 
 * For further information regarding this notice, see: 
 * 
 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
 */
/* $Id$ */
/**********************************************************
* 
*    OS Test - Silicon Graphics, Inc.
* 
*    TEST IDENTIFIER	: symlink01 (symlink)
* 
*    TEST TITLE		: Make a Symbolic Link to a File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 5
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: readlink01 (readlink)
* 
*    TEST TITLE		: Reads Value of a Symbolic Link
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 4
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: stat04  (stat)
* 
*    TEST TITLE		: Gets File Status Indirectly From a Symbolic Link 
*                         File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: lstat01 (lstat)
* 
*    TEST TITLE		: Get file Status About a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: mkdir05 (mkdir)
* 
*    TEST TITLE		: Fail When Making a Directory File Indirectly From
*                         a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 1
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: rmdir03 (rmdir)
* 
*    TEST TITLE		: Fail When Removing a Directory File Indirectly 
*                         From a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 1
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: chdir01 (chdir)
* 
*    TEST TITLE		: Changes Current Working DIrectory Location 
*                         Indirectly From a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: link01 (link)
* 
*    TEST TITLE		: Creates a Link To a File Indirectly From a 
*                         Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: unlink01 (unlink)
* 
*    TEST TITLE		: Removes a Link To a File And Not Any Object File
*                         Which Maybe Pointed At
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 1
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: chmod01 (chmod)
* 
*    TEST TITLE		: Change Object File Permissions Indirectly From a
*                         Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: utime01 (utime)
* 
*    TEST TITLE		: Set File Access And Modify Object File Times
*                         Indirectly From a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: rename01 (rename)
* 
*    TEST TITLE		: Rename a Symbolic Link File And Not Any Object
*                         File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 3
* 
*    WALL CLOCK TIME	: 3
*
*    TEST IDENTIFIER	: open01 (open)
* 
*    TEST TITLE		: Create/Open a File For Reading Or Writing
*                         Indirectly From a Symbolic Link File
* 
*    PARENT DOCUMENT	: symtds01
* 
*    TEST CASE TOTAL	: 5
* 
*    WALL CLOCK TIME	: 3
*
*    EXECUTED BY	: whom ever
* 
*    CPU TYPES		: ALL
* 
*    AUTHOR		: David Fenner
* 
*    CO-PILOT		: Jon Hendrickson
* 
*    DATE STARTED	: 07/25/90
* 
*    INITIAL RELEASE	: UNICOS 6.0
* 
*    TEST CASES
* 
*       For symlink
*
*         1. Create symbolic link with abnormal object name path
*         2. Create symbolic link with normal object name path
*         3. Create symbolic link with path to an existing object file
*         4. Receive EEXIST error when creating an already existing symbolic link file.
*         5. Receive ENAMETOOLONG error when creating symbolic link which exceeds PATH_MAX in length
* 
*       For readlink
*
*         1. Read a symbolic link file which points at no object file
*         2. Read a symbolic link file which points at an object file
*         3. Receive ENAMETOOLONG error when reading symbolic link which exceeds PATH_MAX in length
*         4. Receive an EINVAL error when reading a file which is not a symbolic
*            link file.
* 
*       For stat
* 
*         1. Get object file status through symbolic link file
*         2. Receive ENOENT error when accessing non-existent object file through symbolic link file
*         3. Receive ELOOP error when nesting of symbolic links exceed maximum
*
*       For lstat
* 
*         1. Get symbolic link file status when pointing at no object file
*         2. Get symbolic link file status when pointing at an object file
*         3. Get object file status when argument is not a symbolic link
*            file.
*
*       For mkdir
*
*         1. Receive EEXIST error when creating a directory through a symbolic link file
* 
*       For rmdir
*
*         1. Receive ENOTDIR error when removing an existing directory through a symbolic link file
* 
*       For chdir
*
*         1. Change current working directory through a symbolic link file
*         2. Receive ENOENT error when accessing non-existent directory through symbolic link file
*         3. Receive ELOOP error when nesting of symbolic links exceed maximum
* 
*       For link
* 
*         1. Link an object file to a new file through symbolic link file
*         2. Receive ENOENT error when accessing non-existent object file through symbolic link file
*         3. Receive ELOOP error when nesting of symbolic links exceed maximum
*
*       For unlink
*
*         1. Delete a symbolic link file and not the object file which it points at
* 
*       For chmod
* 
*         1. Change file permissions of object file through a symbolic link file
*         2. Receive ENOENT error when accessing non-existent directory through symbolic link file
*         3. Receive ELOOP error when nesting of symbolic links exceed maximum
* 
*       For utime
*
*         1. Change inode times of object file through a symbolic link file
*         2. Receive ENOENT error when accessing non-existent directory through symbolic link file
*         3. Receive ELOOP error when nesting of symbolic links exceed maximum
* 
*       For rename
*
*         1. Rename a symbolic link file which points at no object file
*         2. Rename a symbolic link file which points at an object file without any object file alterations.
*         3. Receive EXDEV when trying to rename a symbolic link file to an address outside of current file system
*
*       For open
*
*         1. Create an object file through a symbolic link file
*         2. Open an object file through a symbolic link file
*         3. Receive EEXIST error when exclusively creating an object file through a symbolic link file
*         4. Receive ENOENT error when accessing non-existent object file through symbolic link file
*         5. Receive ELOOP error when nesting of symbolic links exceed maximum
*
*    ENVIRONMENTAL NEEDS
*	None
* 
*    DETAILED DESCRIPTION
*
*       Self-documenting code so see below
*
*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/

#include <signal.h>
#include <string.h>
#include <fcntl.h>             /* open(2) system call */
#include <errno.h>
#include <sys/types.h>
#include <utime.h>             /* utime(2) system call */
#include <sys/param.h>
#include <sys/stat.h>          /* stat(2) and lstat(2) system calls */

#include "test.h"
#include "usctest.h"

void setup();
void cleanup(void) __attribute__((noreturn));
void help();
void delete_files();
void do_EEXIST();
void do_ENOENT();
void do_ELOOP();
void do_ENOTDIR();
void do_EXDEV();
void do_ENAMETOOLONG();
void do_EINVAL();
void do_readlink();
void do_stat();
void do_chdir();
void do_link();
void do_unlink();
void do_chmod();
void do_utime();
void do_rename();
void do_open();

#define S_FILE "symbolic"    /* Name of symbolic link file */
#define O_FILE "object"      /* Name of object file */
#define A_S_FILE "asymbolic" /* Another name for a symbolic link file */
#define Y_A_S_FILE "/NiCkEr" /* Yet another symbolic link file */
#define BIG_STRING "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"

#define DEFAULT_TCID  "symlink01"
#define ALL 1

#define SYMLINK "symlink01"
#define READLINK "readlink01"
#define STAT "stat04"
#define LSTAT "lstat01"
#define MKDIR "mkdir05"
#define RMDIR "rmdir03"
#define CHDIR "chdir01"
#define LINK "link01"
#define UNLINK "unlink01"
#define CHMOD "chmod01"
#define UTIME "utime01"
#define RENAME "rename01"
#define OPEN "open01"

#define cktcsid(s1,s2) (!strcmp(s1,s2))
#define BUFMAX 512
#define MODE 0700
#define MASK 0100777           /* A regular file with r,w,x for all mask */

/*
 * Lets be optimistic and only define messages for passing test cases
 */
const char *msgs[] = {
 "Creation of symbolic link file to no object file is ok",
 "Creation of symbolic link file and object file via symbolic link is ok", 
 "Creating an existing symbolic link file error is caught", 
 "Creating a symbolic link which exceeds maximum pathname error is caught",
 "Reading of symbolic link file contents checks out ok",
 "Reading a symbolic link which exceeds maximum pathname error is caught",
 "Getting stat info about object file through symbolic link file is ok",
 "Stat(2) error when accessing non-existent object through symbolic link is caught",
 "lstat(2) of symbolic link file which points to no object file is ok",
 "lstat(2) of symbolic link file which points at an object file is ok",
 "mkdir(2) of object file through symbolic link file failed as expected", 
 "rmdir(2) of object file through symbolic link file failed as expected", 
 "chdir(2) to object file location through symbolic link file is ok", 
 "chdir(2) to non-existent object file location through symbolic link file failed as expected", 
 "link(2) to a symbolic link, which is pointing to an existing object file worked - file created and link count adjusted",
 "link(2) to a symbolic link, which is pointing to a non-existing object file worked ok - file created and link count adjusted.",
 "unlink(2) of symbolic link file with no object file removal is ok",
 "chmod(2) of object file permissions through symbolic link file is ok",
 "chmod(2) error when accessing non-existent object through symbolic link is caught",
 "utime(2) change of object file access and modify times through symbolic link file is ok",
 "utime(2) error when accessing non-existent object through symbolic link is caught",
 "rename(3) of symbolic link file name which points at no object file is ok",
 "rename(3) of symbolic link file name which points at object file is ok",
 "rename(3) error of symbolic link file name across file systems is caught",
 "open(2) with (O_CREAT | O_RDWR) to create object file through symbolic link file and all writes, reads, and lseeks are ok",
 "open(2) with O_RDWR of existing  object file through symbolic link file and all writes, reads, and lseeks are ok",
 "open(2) with (O_CREAT | O_EXCL) error  is caught when creating object file through symbolic link file",
 "open(2) error with O_RDWR is caught when processing symbolic link file which points at no object file",
 "Nested symbolic link access condition caught.  ELOOP is returned",
 "Reading a nonsymbolic link file error condition is caught.  EINVAL is returned",
 "lstat(2) of object file returns object file inode information",
 "NULL"
};

/*
 * Define test object setup and validation functions
 */
int creat_both(), creat_symlink(), creat_path_max(), ck_symlink(),
    creat_object(), ck_object(), ck_both(), ck_path_max();


/*
 *  Define test cases
 */
struct all_test_cases
{
    const char *tcid;
    int test_fail;
    int errno_val;
    int pass_msg;
    int (*test_setup)();
    int (*ck_test)();
    const char *fn_arg[3];
    
} test_objects[] = {
    {SYMLINK, 0, 0, 0, creat_symlink, ck_symlink, {"%bc+eFhi!k", S_FILE, NULL}},
    {SYMLINK, 0, 0, 0, creat_symlink, ck_symlink,  {O_FILE, S_FILE, NULL}},
    {SYMLINK, 0, 0, 1, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {SYMLINK, 1, EEXIST, 2, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {SYMLINK, 1, ENAMETOOLONG, 3, creat_path_max, ck_path_max, {O_FILE, S_FILE, NULL}},
    {READLINK, 0, 0, 4, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {READLINK, 0, 0, 4, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {READLINK, 1, ENAMETOOLONG, 5, creat_path_max, ck_path_max, {O_FILE, S_FILE, NULL}},
    {READLINK, 1, EINVAL, 29, creat_object, ck_object, {O_FILE, NULL, NULL}},
    {STAT, 0, 0, 6, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {STAT, 1, ENOENT, 7, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {STAT, 1, ELOOP, 28, creat_symlink, ck_symlink, {S_FILE, S_FILE, NULL}},
    {LSTAT, 0, 0, 8, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {LSTAT, 0, 0, 9, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {LSTAT, 0, 0, 30, creat_object, ck_object, {O_FILE, NULL, NULL}},
    {MKDIR, 1, EEXIST, 10, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {RMDIR, 1, ENOTDIR, 11, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {CHDIR, 0, 0, 12, creat_symlink, ck_symlink, {O_FILE, S_FILE, O_FILE}},
    {CHDIR, 1, ENOENT, 13, creat_symlink, ck_symlink, {"%bc+eFhi!k", S_FILE, NULL}},
    {CHDIR, 1, ELOOP, 28, creat_symlink, ck_symlink, {S_FILE, S_FILE, NULL}},
    {LINK, 0, 0, 14, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {LINK, 0, 0, 15, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    /* The following link test case is invalid - leaving it defined so */
    /* I don't have to change all the entries in the all_tcses array after link */
    {LINK, -1, -1, -1, creat_symlink, ck_symlink, {NULL, NULL, NULL}},
    {UNLINK, 0, 0, 16, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {CHMOD, 0, 0, 17, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {CHMOD, 1, ENOENT, 18, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {CHMOD, 1, ELOOP, 28, creat_symlink, ck_symlink, {S_FILE, S_FILE, NULL}},
    {UTIME, 0, 0, 19, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {UTIME, 1, ENOENT, 20, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {UTIME, 1, ELOOP, 28, creat_symlink, ck_symlink, {S_FILE, S_FILE, NULL}},
    {RENAME, 0, 0, 21, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {RENAME, 0, 0, 22, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {RENAME, -1, EXDEV, 23, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {OPEN, 0, 0, 24, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {OPEN, 0, 0, 25, creat_both, ck_both, {O_FILE, S_FILE, O_FILE}},
    {OPEN, -1, EEXIST, 26, creat_symlink, ck_symlink, {O_FILE, S_FILE, O_FILE}},
    {OPEN, 1, ENOENT, 27, creat_symlink, ck_symlink, {O_FILE, S_FILE, NULL}},
    {OPEN, 1, ELOOP, 28, creat_symlink, ck_symlink, {S_FILE, S_FILE, NULL}}
};

/*
 * Define tcses
 */
struct tcses
{
    const char *tcid;
    const char *syscall;
    int test_cases;		/* number of entries in test_objects array */
    struct all_test_cases *tc_ptr;
    const char *desc;
} all_tcses[] = {

   { SYMLINK,  "symlink",  5, &test_objects[0],
		"Make a Symbolic Link to a File" },
   { READLINK, "readlink", 4, &test_objects[5],
		"Reads Value of a Symbolic Link" },
   { STAT,     "stat",     3, &test_objects[9],
		"Gets File Status Indirectly From a Symbolic Link file" },
   { LSTAT,    "lstat",    3, &test_objects[12],
		"Get file Status About a Symbolic Link File" },
   { MKDIR,    "mkdir",    1, &test_objects[15],
		"Fail When Making a Directory File Indirectly from a symlink" },
   { RMDIR,    "rmdir",    1, &test_objects[16],
		"Fail When Removing a Directory File Indirectly from a symlink" },
   { CHDIR,    "chdir",    3, &test_objects[17],
		"Changes CWD Location Indirectly from a symlink" },
   { LINK,     "link",     2, &test_objects[20],
		"Creates a Link To a File Indirectly From a Symbolic" },
   { UNLINK,   "unlink",   1, &test_objects[23],
		"Removes a Link To a File but not the Object File" },
   { CHMOD,    "chmod",    3, &test_objects[24],
		"Change Object File Permissions Indirectly From a Symbolic" },
   { UTIME,    "utime",    3, &test_objects[27],
		"Set File Access And Modify Object File Times via symlink" },
   { RENAME,   "rename",   3, &test_objects[30],
		"Rename a Symbolic Link File And Not Any Object file" },
   { OPEN,     "open",     5, &test_objects[33],
		"Create/Open a File For Reading Or Writing via symlink" },
};

/*
 * Define GLOBAL variables
 */

int TST_TOTAL;
int TEST_RESULT;
time_t a_time_value = 100;
const char  *TCID = NULL;
char  *Selectedtests = NULL;		/* Name (tcid) of selected test cases */
char test_msg[BUFMAX];
char full_path[PATH_MAX+1];
extern int Tst_count;
extern char *TESTDIR;
extern char *strrchr();
extern int errno;

struct stat asymlink, statter;
char Buffer[1024];
char Buf[1024];

char *Tcid = NULL;

option_t Options[] = {
    { "T:",  NULL, &Tcid },	    /* -T tcid option */
    { NULL, NULL, NULL }
};

/***********************************************************************
 * MAIN
 ***********************************************************************/
int
main(int argc, char *argv[])
{
    struct tcses *tcs_ptr, *get_tcs_info();
    int do_syscalltests();
    void cleanup();
    int lc;             /* loop counter */
    const char *msg;          /* message returned from parse_opts */


   /***************************************************************
    * parse standard options, and exit if there is an error
    ***************************************************************/
   if ( (msg=parse_opts(argc, argv, Options, &help)) != (char *) NULL ) {
        tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
        tst_exit();
   }

   /*
    * If the -T option was used, use that TCID or use the default
    */
   if ( Tcid != NULL ) {
       TCID = Tcid;
       Selectedtests=Tcid;

   }
   else {
       TCID = DEFAULT_TCID;
#ifndef ALL
       Selectedtests = DEFAULT_TCID;
#else
       Selectedtests = NULL;
#endif
    }

   /*
    * Get test case specification information and assign TST_TOTAL
    */
   if ((tcs_ptr=get_tcs_info(Selectedtests)) == NULL) {
      TST_TOTAL=1;
      tst_brkm(TBROK, cleanup,
	"Unknown symbolic link test case specification executed");
   }

   /***************************************************************
    * perform global setup for test
    ***************************************************************/

   setup();

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
    for (lc=0; TEST_LOOPING(lc); lc++) {

        /* reset Tst_count in case we are looping. */
        Tst_count=0;

        /*
         * Execute tcs testing function and all defined test cases
         */
        do_syscalltests(tcs_ptr);

    }   /* End for TEST_LOOPING */

    /*
     * End appropriately
     */
    cleanup();

    return 0;
}

/***********************************************************************
 *  This function maps the name of the process to a test case specification
 *  defined in the all_tcses array of tcses structures.  Either a pointer
 *  to the mapped test case specification information is returned or a
 *  null pointer.
 *
 *      Argument is path to program name.
 ***********************************************************************/
struct tcses *get_tcs_info(ptr)
char *ptr;
{
    unsigned ctr;
    struct tcses *tcs_ptr;

#if ALL
    if ( ptr == NULL ) {

	TST_TOTAL=0;
	for (ctr=1; ctr < sizeof(all_tcses)/sizeof(struct tcses); ctr++)
	TST_TOTAL += all_tcses[ctr].test_cases;
	return all_tcses;
    }
#endif

    
    for(ctr=0; ctr < (sizeof(all_tcses)/sizeof(struct tcses)); ctr++) {
       if ( strcmp(ptr, all_tcses[ctr].tcid) == 0 || 
	    strcmp(ptr, all_tcses[ctr].syscall) == 0 ) {
          tcs_ptr = &all_tcses[ctr];
	  TCID = all_tcses[ctr].tcid;
          TST_TOTAL=tcs_ptr->test_cases;
          return(tcs_ptr);
       }
       
    }
    return(NULL);
}

/***********************************************************************
 *  Determines if what path points at is a symbolic link file
 *
 *      Argument is path to symbolic link file.
 *
 *  Return status is one if a symbolic link file.  Zero if not a symbolic
 *  link file and a minus one if the path doesn't point at a file.
 ***********************************************************************/
int
see_if_a_symlink(path)
char *path;
{
   if (lstat(path, &asymlink) < 0)
      return(-1);

   if ((asymlink.st_mode & S_IFMT) == S_IFLNK)
      return(1);
   else
      return(0);
}

/***********************************************************************
 * This function performs without any hesitation, file(s) deletions
 ***********************************************************************/
void
delete_files(path1, path2)
char *path1, *path2;
{
   unlink(path1);
   unlink(path2);
}

/***********************************************************************
 *
 * This routine creates a symbolic link file.
 *
 *      Argument one is symbolic link pathname to point at.
 *      Argument two is name of symbolic link file.
 *
 ***********************************************************************/
int
creat_symlink(path1, path2)
char *path1, *path2;
{
   TEST( symlink(path1, path2) );
   errno=TEST_ERRNO;
   if (TEST_RETURN == -1) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"symlink(2) Failure when creating setup %s object file: errno:%d %s",
	path1, errno, strerror(errno));
      return(0);
   } 
   else {
	sprintf(Buf, "symlink(%s, %s) was succesful.\n", path1, path2);
	strcat(Buffer, Buf);
#if DEBUG
	tst_resm(TPASS, "symlink(%s, %s) was succesful.", path1, path2);
#endif
   }
   return(1);
}

/***********************************************************************
 *
 * This routine creates a regular file.
 *
 *      Argument one is a pathname
 *
 ***********************************************************************/
int
creat_object(path1)
char *path1;
{
   int fd;
   if ((fd=creat(path1, MODE)) == -1) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"creat(2) Failure when creating setup %s object file: errno:%d %s",
	path1, errno, strerror(errno));
      return(0);
   } 
   else {
	sprintf(Buf, "creat(%s, %#o) was succesful.\n", path1, MODE);
	strcat(Buffer, Buf);
#if DEBUG
	tst_resm(TPASS, "creat(%s, %#o) was succesful.", path1, MODE);
#endif
   }
   if (close(fd) == -1) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"close(2) Failure when closing setup %s object file: errno:%d %s",
	path1, errno, strerror(errno));
      return(0);
   }
   return(1);
}

/***********************************************************************
 *
 * This routine creates a symbolic link file and a regular file.
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 *
 ***********************************************************************/
int
creat_both(path1, path2, path3)
char *path1, *path2, *path3;
{
   if (creat_symlink(path1, path2) == -1)
      return(0);
   else if (creat_object(path3) == -1)
      return(0);
   return(1);
}

/***********************************************************************
 *
 * This routine checks if symbolic link file is a symbolic link file.
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 *
 ***********************************************************************/
int
ck_symlink(path1, path2, path3)
char *path1, *path2, *path3;
{
   int ret;

   if ((ret=see_if_a_symlink(path2)) == -1) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"lstat(2) Failure when accessing %s symbolic link file which should contain %s path to %s file ",
	path2, path1, path3);
      return(0);
   }
   else if (ret == 0) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"%s is not a symbolic link file which contains %s path to %s file",
	path2, path1, path3);
      return(0);
   }
   return(1);
}

/***********************************************************************
 *
 * This routine checks if symbolic link file points at object file.
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 *
 ***********************************************************************/
int
ck_both(path1, path2, path3)
char *path1, *path2, *path3;
{
   if (ck_symlink(path1, path2, path3) == 0)
      return(0);
   else if ((stat(path3, &statter) == -1) && (errno == ENOENT)) {
      TEST_RESULT=TBROK;
      sprintf(test_msg, "stat(2) Failure when accessing %s object file ", path3);
      return(0);
   }
   else if ((stat(path2, &asymlink) == -1) && (errno == ENOENT)) {
      TEST_RESULT=TBROK;
      sprintf(test_msg, "stat(2) Failure when accessing %s symbolic link file ",
	path2);
      return(0);
   }
   else if (statter.st_ino != asymlink.st_ino) {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"stat(2) Failure when accessing %s object file through %s symbolic link file ",
	path3, path2);
      return(0);
   }
   return(1);
   
}

/***********************************************************************
 * This routine populates full_path with a pathname whose length exceeds
 * the PATH_MAX define value in param.h
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 ***********************************************************************/
int
creat_path_max(path1, path2, path3)
char *path1, *path2, *path3;
{
   int ctr, to_go, size, whole_chunks;
   char buf [PATH_MAX];
   char *cwd;

   if ((cwd = getcwd(buf, sizeof (buf))) == NULL)
   {
      TEST_RESULT=TBROK;
      sprintf(test_msg,
	"getcwd(3) Failure in setup of %s %s %s test case object elements",
	path1, path2, path3);
      return(0);
   }
   size = strlen(cwd);

   to_go = PATH_MAX - size;
   size = strlen(path1);
   whole_chunks = to_go / size;
   strcpy(full_path, cwd);
   for (ctr=0; ctr < whole_chunks; ctr++) {
       strcat(full_path, path1);
   }
   size= strlen(full_path);
   to_go = PATH_MAX - size;
   strcat(full_path, "/");
   for (ctr=0; ctr < to_go; ctr++)
       strcat(full_path, "Z");

   return(1);
}

/***********************************************************************
 * This routine checks that full_path's  length exceeds the PATH_MAX
 * define value in param.h
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 ***********************************************************************/
int
ck_path_max(path1, path2, path3)
char *path1, *path2, *path3;
{
   if (strlen(full_path) == (PATH_MAX+1))
      return(1);
   else
   {
      TEST_RESULT=TBROK;
      sprintf(test_msg, "%s %d %s %s %s %s",
	"full_path character array length was not", (PATH_MAX+1),
	"characters long for test case object elements",
	path1, path2, path3);
      return(0);
   }
}

/***********************************************************************
 * This routine checks if the stat(2) and lstat(2) calls return the same
 * information when the path is not a symbolic link file
 *
 *      Argument one is a pathname of object file
 *      Argument two is symbolic link file name
 *      Argument three is regular file name
 *
 ***********************************************************************/
int
ck_object(path1, path2, path3)
char *path1, *path2, *path3;
{
    int ret;

    if ((ret=see_if_a_symlink(path1)) < 0) {
       TEST_RESULT=TFAIL;
       sprintf(test_msg,
	   "lstat(2) failed to return inode information for a regular object file");
       return(0);
    }
    else if (ret == 1) {
       TEST_RESULT=TFAIL;
       sprintf(test_msg, 
	   "lstat(2) detected a regular object file as a symbolic link file");
       return(0);
    }
    else if (stat(path1, &statter) == -1) {
       TEST_RESULT=TBROK;
       sprintf(test_msg,
	   "stat(2) failed to return inode information for a regular object file");
       return(0);
    }
    else if (bcmp((char *)&statter, (char *)&asymlink, sizeof(statter)) != 0) {
       TEST_RESULT=TFAIL;
       sprintf(test_msg,
	   "lstat(2) and stat(2) do not return same inode information for an object file");
       return(0);
        
    }
    return(1);
}

/***********************************************************************
 * Main test case processing function
 *
 *  Argument is a ptr into the all_tcses array of structures of type tcses
 ***********************************************************************/
int
do_syscalltests(tcs)
struct tcses *tcs;
{
   int ctr, ret;
   struct all_test_cases *tc_ptr;

   /*
    * loop through desired number of test cases
    */
   for (ctr=0, tc_ptr=tcs->tc_ptr; ctr < TST_TOTAL; ctr++, tc_ptr++) {

       if (tc_ptr->test_fail < 0) continue;

       Buffer[0]='\0';

       /*
	* If running all test cases for all tcid, set the TCID if needed.
        */
       if ( Selectedtests == NULL ) {
	   if ( !TCID || strcmp(TCID, tc_ptr->tcid) != 0 ) {
               TCID = tc_ptr->tcid;
               Tst_count=0;
	   }
       }
       /*
        * Insure that we are executing the correct tcs test case
        */
       if (strcmp(TCID, tc_ptr->tcid) != 0) {
          tst_resm(TBROK, "%s TCID attempted to execute %s %d %d test case",
	     TCID, tc_ptr->tcid, tc_ptr->test_fail, tc_ptr->errno_val);
          continue;
       }
       TEST_RESULT=TPASS;
       delete_files(S_FILE, O_FILE);
       /* 
        * Perform test case setup
        */
       ret = (tc_ptr->test_setup)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
	   tc_ptr->fn_arg[2], tc_ptr->errno_val);

       /* If an expected error, try it out */

       if (tc_ptr->test_fail) {
          /* 
           * Try to perform test verification function
           */
          if (! (tc_ptr->ck_test)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
			tc_ptr->fn_arg[2], tc_ptr->errno_val))
             tst_resm(TEST_RESULT, test_msg);
          else if (tc_ptr->errno_val == EEXIST)
             do_EEXIST(tc_ptr);
          else if (tc_ptr->errno_val == ENOENT)
             do_ENOENT(tc_ptr);
          else if (tc_ptr->errno_val == ELOOP)
             do_ELOOP(tc_ptr);
          else if (tc_ptr->errno_val == ENOTDIR)
             do_ENOTDIR(tc_ptr);
          else if (tc_ptr->errno_val == EXDEV)
             do_EXDEV(tc_ptr);
          else if (tc_ptr->errno_val == ENAMETOOLONG)
             do_ENAMETOOLONG(tc_ptr);
          else if (tc_ptr->errno_val == EINVAL)
             do_EINVAL(tc_ptr);
          else
             tst_resm(TBROK, "Test Case Declaration Error");
       }
       else if (ret == 1) {  /*  No setup function error */
 
          if (tc_ptr->errno_val != 0)
             tst_resm(TBROK, "Test Case Declaration Error");
          else {
             /* 
              * Perform test verification function
              */
             ret=(tc_ptr->ck_test)(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1],
		tc_ptr->fn_arg[2], tc_ptr->errno_val);

             /* Perform requested symbolic link system call test */

             if ((cktcsid(tc_ptr->tcid, SYMLINK)) ||
				(cktcsid(tc_ptr->tcid, LSTAT))) {
                if (ret == 1)
                   tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);   
                else
                   tst_resm(TEST_RESULT, test_msg);
             }
             else if (ret == 0)
                tst_resm(TEST_RESULT, test_msg);
             else if (cktcsid(tc_ptr->tcid, READLINK))
                do_readlink(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, STAT))
                do_stat(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, CHDIR))
                do_chdir(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, LINK))
                do_link(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, UNLINK))
                do_unlink(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, CHMOD))
                do_chmod(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, UTIME))
                do_utime(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, RENAME))
                do_rename(tc_ptr);
             else if (cktcsid(tc_ptr->tcid, OPEN))
                do_open(tc_ptr);
             else
                tst_resm(TBROK, "Unknown test case processing actions declared");
          }
       }
       else
          tst_resm(TBROK, "Test Case Declaration Error");
   }
   return(0);
}

/***********************************************************************
 * This routine checks for the return of EEXIST errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_EEXIST(tc_ptr)
struct all_test_cases *tc_ptr;
{
    if (cktcsid(tc_ptr->tcid, SYMLINK)) {

       TEST( symlink(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1]) );
	errno=TEST_ERRNO;
       if ((TEST_RETURN == -1) && (errno == EEXIST))
	   if ( STD_FUNCTIONAL_TEST )
               tst_resm(TPASS, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
       else
           tst_resm(TFAIL, "%s %s",
		"Expected EEXIST error when creating a symbolic link file",
		"which already existed");
     }
     else if (cktcsid(tc_ptr->tcid, MKDIR)) {

	TEST ( mkdir(tc_ptr->fn_arg[1],MODE) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == EEXIST))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else {

           tst_resm(TFAIL, "%s %s",
		"Expected EEXIST error when creating a directory by a symbolic",
		"link file which pointed at no object file");
           rmdir(tc_ptr->fn_arg[1]);
        }
     }
     else if (cktcsid(tc_ptr->tcid, OPEN)) {

        TEST( open(tc_ptr->fn_arg[1], (O_EXCL | O_CREAT)) )
 	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == EEXIST))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
	        "Expected EEXIST error for exclusively opening an object file",
		"through a symbolic link file was not received:",
		errno, strerror(errno));
        close (TEST_RETURN);
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of ENOENT errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_ENOENT(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (cktcsid(tc_ptr->tcid, STAT)) {

        if ((stat(tc_ptr->fn_arg[1], &asymlink) == -1) && (errno == ENOENT))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error for stating a non-existent directory",
		"through a symbolic link file was not received:",
	  	errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, CHDIR)) {
        if ((chdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOENT))
	    if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else {
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error for changing to a non-existent",
		"directory through a symbolic link file was not received:",
		errno, strerror(errno));
           chdir(TESTDIR);
        }
     }
     else if (cktcsid(tc_ptr->tcid, LINK)) {

        if ((link(tc_ptr->fn_arg[1], "nick") == -1) && (errno == ENOENT))
	  if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
             tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
        {
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error condition when link(2) a symbolic",
		"link which pointed at no object:", errno, strerror(errno));
           delete_files("nick", NULL);
        }
     }
     else if (cktcsid(tc_ptr->tcid, CHMOD)) {

        if ((chmod(tc_ptr->fn_arg[1], MODE) == -1) && (errno == ENOENT))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error condition when chmod(2) a symbolic",
		"link which pointed at no object,", errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, UTIME)) {

        if ((utime(tc_ptr->fn_arg[1], NULL) == -1) && (errno == ENOENT))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error condition when utime(2) a symbolic",
		"link which pointed at no object:", errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, OPEN)) {

        if ((open(tc_ptr->fn_arg[1], O_RDWR) == -1) && (errno == ENOENT))
	    if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOENT error for opening a non-existent object",
		" file through a symbolic link file was not received,",
		errno, strerror(errno));
        close (TEST_RETURN);
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of ELOOP errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_ELOOP(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (cktcsid(tc_ptr->tcid, STAT)) {

	TEST( stat(tc_ptr->fn_arg[1], &asymlink) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == ELOOP))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
              tst_resm(TEST_RESULT, "%s errno:%d %s",
	  	"Expected ELOOP errno from stat(2) (nested symb link),",
		 errno, strerror(errno));
	   else
		Tst_count++;
     }
     else if (cktcsid(tc_ptr->tcid, CHDIR)) {

	TEST( chdir(tc_ptr->fn_arg[1]) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == ELOOP))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
              tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else {

           tst_resm(TFAIL, "%s errno:%d %s",
		"Expected ELOOP error condition when chdir(2) a nested symbolic link:",
		errno, strerror(errno));
           chdir(TESTDIR);
        }
     }
     else if (cktcsid(tc_ptr->tcid, LINK)) {

	TEST ( link(tc_ptr->fn_arg[1], O_FILE) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == ELOOP))
	    if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s errno:%d %s",
		"Expected ELOOP error condition when link(2) a nested symbolic link:",
		errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, CHMOD)) {

	TEST ( chmod(tc_ptr->fn_arg[1], MODE) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == ELOOP))
	    if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	    else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s errno:%d %s",
		"Expected ELOOP error condition when chmod(2) a nested symbolic link:",
		errno, strerror(errno));
        return;
     }
     else if (cktcsid(tc_ptr->tcid, UTIME)) {

	TEST( utime(tc_ptr->fn_arg[1], NULL) );
	errno=TEST_ERRNO;

        if ((TEST_RETURN == -1) && (errno == ELOOP))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s errno:%d %s",
		"Expected ELOOP error condition when utime(2) a nested symbolic link:",
		errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, OPEN)) {

        int fd;
        TEST( open(tc_ptr->fn_arg[1], O_CREAT) );
	fd=TEST_RETURN;
	errno=TEST_ERRNO;
        if ((fd == -1) && (errno == ELOOP))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, "%s errno:%d %s",
		"Expected ELOOP error condition when open(2) a nested symbolic link:",
		errno, strerror(errno));
	close (fd);
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of ENOTDIR errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_ENOTDIR(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (cktcsid(tc_ptr->tcid, RMDIR)) {

	TEST( mkdir(tc_ptr->fn_arg[0], MODE) );
	errno=TEST_ERRNO;
        if (TEST_RETURN == -1)
            tst_resm(TBROK, "mkdir(2) Failure when creating %s",
		tc_ptr->fn_arg[0]);
        else if ((rmdir(tc_ptr->fn_arg[1]) == -1) && (errno == ENOTDIR)) {

	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
           rmdir(tc_ptr->fn_arg[0]);
        }
        else
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected ENOTDIR error for removing a non-existent",
		"directory through a symbolic link file was not received,",
		errno, strerror(errno));
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of EXDEV errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_EXDEV(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (cktcsid(tc_ptr->tcid, RENAME)) {

	TEST( rename(tc_ptr->fn_arg[1], Y_A_S_FILE) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == EXDEV)) {
           if (see_if_a_symlink(Y_A_S_FILE) == -1)
	      if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                  tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	      else
		  Tst_count++;
           else
              tst_resm(TFAIL, "%s %s %s file outside of current file system",
		"rename(3) returned -1 when trying to move symbolic link file",
		"outside of current file system, but created", Y_A_S_FILE);
        }
        else {
           tst_resm(TFAIL, "%s %s errno:%d %s",
		"Expected EXDEV error for renaming an existing symbolic",
		"link file to a location outside of existing file system,",
		errno, strerror(errno));
           delete_files("/NiCkEr", NULL);
        }
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of ENAMETOOLONG errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_ENAMETOOLONG(tc_ptr)
struct all_test_cases *tc_ptr;
{
     int ret;

     if (cktcsid(tc_ptr->tcid, SYMLINK)) {

	TEST( symlink(tc_ptr->fn_arg[0], full_path) );
	errno=TEST_ERRNO;
        if ((TEST_RETURN == -1) && (errno == ENAMETOOLONG))
           if (see_if_a_symlink(full_path) == -1)
	      if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                  tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	      else
		  Tst_count++;
           else
              tst_resm(TFAIL, "%s %s %d %s",
		"symlink(2) returned -1 when trying to create a symbolic",
		"link file whose name exceeded", (PATH_MAX+1),
		"characters, but it created the symbolic link file");
        else
           tst_resm(TFAIL,
		"Expected ENAMETOOLONG error when creating %s symbolic link file with a path exceeding %d characters: errno:%d %s",
		tc_ptr->fn_arg[1], (PATH_MAX+1), errno, strerror(errno));
     }
     else if (cktcsid(tc_ptr->tcid, READLINK)) {

        char scratch[PATH_MAX+1];

	ret=readlink(full_path, scratch, strlen(full_path));
        if (( ret == -1) && (errno == ENAMETOOLONG))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  ) 
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL,
	       "Expected ENAMETOOLONG error when reading %s symbolic link file with a path exceeding %d characters: errno:%d %s",
		tc_ptr->fn_arg[1], (PATH_MAX+1), errno, strerror(errno));
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks for the return of EINVAL errno from requested
 * system call
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_EINVAL(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (cktcsid(tc_ptr->tcid, READLINK)) {
	TEST( readlink(tc_ptr->fn_arg[0], test_msg, BUFMAX) );
	errno=TEST_ERRNO;
        if (TEST_RETURN == -1) {
           if (errno == EINVAL) {
	      if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                  tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	      else
		Tst_count++;
           } else
              tst_resm(TFAIL, "readlink(2) ret:-1, errno:%d, : Exp errno:%d",
		errno, EINVAL);
        }
        else {
           tst_resm(TFAIL, "readlink(2) did not returned -1 when reading %s",
		"a file which is not a symbolic link file");
	}
     }
     else
        tst_resm(TBROK, "Unknown test case processing actions declared");
}

/***********************************************************************
 * This routine checks out the readlink(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_readlink(tc_ptr)
struct all_test_cases *tc_ptr;
{
     char scratch[PATH_MAX];
     int ret;

     ret=readlink(tc_ptr->fn_arg[1], scratch, strlen(tc_ptr->fn_arg[0]));

     /*** the TEST macro cannot be used here for some reason ****/

     if (ret == -1) {
        tst_resm(TFAIL,
	    "readlink(2) failure on %s symbolic link file, errno=%d",
	    tc_ptr->fn_arg[1], errno);

     }
     else if (strncmp(tc_ptr->fn_arg[0], scratch,
			strlen(tc_ptr->fn_arg[0])) != 0) {

        /* Must null terminate scratch because readlink(2) doesn't */

        scratch[strlen(tc_ptr->fn_arg[0])] = '\0';
 
        tst_resm(TFAIL,
	   "readlink(2) Error : Expected %s symbolic link file contents but %s actual contents were returned",
	   tc_ptr->fn_arg[0], scratch);
     }
     else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
        tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
     else
	Tst_count++;
}

/***********************************************************************
 * This routine checks out the stat(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_stat(tc_ptr)
struct all_test_cases *tc_ptr;
{
    if (statter.st_dev != asymlink.st_dev)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object device info %ld != stat of object file device info %ld",
	    statter.st_dev, asymlink.st_dev);

    else if (statter.st_mode != asymlink.st_mode)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object file permissions %ld != stat of object file permissions %ld",
	    statter.st_mode, asymlink.st_mode);

    else if (statter.st_nlink != asymlink.st_nlink)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object file link count %ld != stat of object file link count %ld",
	    statter.st_nlink, asymlink.st_nlink);

    else if (statter.st_uid != asymlink.st_uid)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object file uid %ld != stat of object file uid %ld",
	    statter.st_uid, asymlink.st_uid);

    else if (statter.st_gid != asymlink.st_gid)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object file gid %ld != stat of object file gid %ld",
	    statter.st_gid, asymlink.st_gid);

    else if (statter.st_size != asymlink.st_size)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object file size %ld != stat of object file size %ld",
	    statter.st_size, asymlink.st_size);

    else if (statter.st_atime != asymlink.st_atime)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object access time %ld != stat of object file access time %ld",
	    statter.st_atime, asymlink.st_atime);

    else if (statter.st_mtime != asymlink.st_mtime)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object modify time %ld != stat of object file modify time %ld",
	    statter.st_atime, asymlink.st_atime);

    else if (statter.st_ctime != asymlink.st_ctime)
        tst_resm(TFAIL,
	    "stat of symbolic link reference to object change time %ld != stat of object file change time %ld",
	    statter.st_atime, asymlink.st_atime);
    else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
        tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
     else
	Tst_count++;
}

/***********************************************************************
 * This routine checks out the chdir(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_chdir(tc_ptr)
struct all_test_cases *tc_ptr;
{
     if (mkdir(tc_ptr->fn_arg[2],MODE) == -1)
        tst_resm(TFAIL, "Could not create a setup directory file");
     else {

	sprintf(Buf, "mkdir(%s, %#o) was successful\n", tc_ptr->fn_arg[2],MODE);
	strcat(Buffer, Buf);

        if (chdir(tc_ptr->fn_arg[1]) == -1)
           tst_resm(TFAIL, "%sCould not change a directory file through a %s",
		Buffer, "symbolic link which which pointed at object");
        else {

	   char buf [PATH_MAX];
           char *cwd;
           char expected_location[PATH_MAX];
           /*
           *  Build expected current directory position
           */
           strcpy(expected_location, TESTDIR);
           strcat(expected_location, "/");
           strcat(expected_location, tc_ptr->fn_arg[2]);

           if ((cwd = getcwd(buf, sizeof (buf))) == NULL)
              tst_resm(TFAIL, "getcwd(3) FAILURE");
           else if (strcmp(cwd, expected_location) == 0)
	      if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                  tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
     	      else
		  Tst_count++;
           else {
              tst_resm(TFAIL, "%s%s %s %s not equal to expected %s", Buffer,
		"chdir(2) returned successfully, but getcwd(3) indicated",
		"new current working directory location", cwd, expected_location);
           }
           chdir(TESTDIR);
        }
        rmdir(tc_ptr->fn_arg[2]);
     }
}

/***********************************************************************
 * This routine checks out the link(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_link(tc_ptr)
struct all_test_cases *tc_ptr;
{
    struct stat stbuf;

    if (link(tc_ptr->fn_arg[1], "nick") == -1) {
        tst_resm(TFAIL, "%slink(%s, \"nick\") failed, errno: %d\n%s %s",
	    Buffer, tc_ptr->fn_arg[1], errno,
	    "link of new file to object file via symbolic link file failed",
	    "when expected not to");
    }
    else {
	sprintf(Buf, "link(%s, \"nick\") was successful\n", tc_ptr->fn_arg[1]);
	strcat(Buffer, Buf);

	if ( STD_FUNCTIONAL_TEST ) {
	  /*
	   * Check that links counts were properly set
	   */
          if (lstat(tc_ptr->fn_arg[1], &asymlink) == -1) {
            tst_resm(TBROK, "lstat(%s) failed. errno: %d",
		tc_ptr->fn_arg[1], errno);

          } else if (lstat("nick", &statter) == -1) {
           tst_resm(TBROK, "lstat(nick) failed, errno:%d", errno);
          } else {
            if (statter.st_ino == asymlink.st_ino) {
                if ((statter.st_nlink ==2) && (asymlink.st_nlink == 2)) {
		   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                       tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
		   else
			Tst_count++;
                } else {
		   lstat(tc_ptr->fn_arg[2], &stbuf);

                   tst_resm(TFAIL, 
		       "%slink(%s, %s) failed to adjust link count.\n\
		count for nick is %d, count for %s is %d, count for %s is %d.",
		       Buffer, tc_ptr->fn_arg[1], "nick",
		       statter.st_nlink, tc_ptr->fn_arg[1], asymlink.st_nlink,
			tc_ptr->fn_arg[2], stbuf.st_nlink);
		}
	    } else {
		tst_resm(TFAIL, 
		    "%sA lstat of %s (ino:%d) and of\n\t\t\
%s (ino:%d), does not show them being the same ino.", Buffer,
		   tc_ptr->fn_arg[1], asymlink.st_ino, "nick", statter.st_ino);
	    }
          }
	}
        delete_files("nick", NULL);
    }
}

/***********************************************************************
 * This routine checks out the unlink(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_unlink(tc_ptr)
struct all_test_cases *tc_ptr;
{
    if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
        tst_resm(TBROK,
	    "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
    else if (unlink(tc_ptr->fn_arg[1]) == -1)
        tst_resm(TFAIL, "unlink(2) failed when removing symbolic link file");
    else {
	sprintf(Buf, "unlink(%s) was successful\n", tc_ptr->fn_arg[1]);
	strcat(Buffer, Buf);
	if (stat(tc_ptr->fn_arg[2], &statter) == -1)
            tst_resm(TFAIL,"%s %s",
	        "unlink(2) failed because it not only removed symbolic link",
	        "file which pointed at object file, but object file as well");
	
        else
            if ((statter.st_ino == asymlink.st_ino) &&
		(statter.st_dev == asymlink.st_dev) &&
		(statter.st_size == asymlink.st_size))

	       if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                   tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	       else
		    Tst_count++;
            else
               tst_resm(TFAIL, "%s%s %s %s", Buffer,
		    "unlink(2) failed because it not only removed symbolic link",
		    "file which pointed at object file, but it changed object",
		    "file inode information");
    }

}

/***********************************************************************
 * This routine checks out the chmod(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_chmod(tc_ptr)
struct all_test_cases *tc_ptr;
{
    if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
        tst_resm(TBROK,
	    "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
    else if (chmod(tc_ptr->fn_arg[1], (MODE | MASK)) == -1) 
        tst_resm(TFAIL, "%s%s %s", Buffer,
	    "chmod(2) failed when changing file permission",
	    "through symbolic link file");
    else { 
	sprintf(Buf, "chmod(%s, %#o) was successful\n", tc_ptr->fn_arg[1], 
		(MODE | MASK));
	strcat(Buffer, Buf);

	if (stat(tc_ptr->fn_arg[2], &statter) == -1)
            tst_resm(TBROK,
	        "stat(2) Failure when accessing %s object file", tc_ptr->fn_arg[2]);
        else
            if ((statter.st_mode == (MODE | MASK)) &&
			    (statter.st_mode != asymlink.st_mode))
	       if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                   tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	       else
		    Tst_count++;
            else
               tst_resm(TFAIL, "%s%s %o to %o %s", Buffer,
		    "chmod(2) failed to change object file permissions from",
		    asymlink.st_mode, (MODE | MASK),
		    "through symbolic link file");
    }

}

/***********************************************************************
 * This routine checks out the utime(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_utime(tc_ptr)
struct all_test_cases *tc_ptr;
{
     struct utimbuf utimes;

     if (stat(tc_ptr->fn_arg[2], &asymlink) == -1)
        tst_resm(TBROK, "stat(2) Failure when accessing %s object file",
	    tc_ptr->fn_arg[2]);
     else {
        /* Now add a few values to access and modify times */

        utimes.actime = asymlink.st_atime + a_time_value;
        utimes.modtime = asymlink.st_mtime + a_time_value;
       
        /* Now hand off to utime(2) via symbolic link file*/

        if (utime(tc_ptr->fn_arg[1], &utimes) == -1)
            tst_resm(TFAIL, "%s %s",
	        "utime(2) failed to process object file access and modify",
		"time updates through symbolic link");
        else {
           /* Now verify changes were made */

           if (stat(tc_ptr->fn_arg[2], &statter) == -1)
              tst_resm(TBROK,
		"stat(2) Failure when accessing %s object file",
		tc_ptr->fn_arg[2]);
           else {
              time_t temp, diff;

              temp = statter.st_atime - asymlink.st_atime;
              diff = (statter.st_mtime - asymlink.st_mtime) - temp;

              if (! diff) 
		 if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                     tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
		 else
		     Tst_count++;
              else
                 tst_resm(TFAIL, "%s %s %d greater than original times",
		    "utime(2) failed to change object file access and",
		    "modify times through symbolic link to a value",
		    a_time_value);
           }
        }
     }
}

/***********************************************************************
 * This routine checks out the rename(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_rename(tc_ptr)
struct all_test_cases *tc_ptr;
{
     int pts_at_object = 0;

     
     if (stat(tc_ptr->fn_arg[2], &statter) != -1)
        pts_at_object=1;

     TEST (rename(tc_ptr->fn_arg[1], A_S_FILE) );
     errno=TEST_ERRNO;
     if (TEST_RETURN == -1)
        tst_resm(TFAIL, "rename(3) failed to rename %s symbolic link file to %s",
	    tc_ptr->fn_arg[2], A_S_FILE);
     else if (pts_at_object)
        if (ck_both(tc_ptr->fn_arg[0], A_S_FILE, tc_ptr->fn_arg[2]))
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        else
           tst_resm(TFAIL, test_msg);
     else if ( ! ck_symlink(tc_ptr->fn_arg[0], A_S_FILE, NULL)) 
        tst_resm(TFAIL, test_msg);
     else if (stat(tc_ptr->fn_arg[1], &asymlink) != -1)
        tst_resm(TFAIL,
	    "rename(3) did not remove %s when renaming to %s",
	    tc_ptr->fn_arg[1], A_S_FILE);
     else if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
        tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
     else
	Tst_count++;
}

/***********************************************************************
 * This routine checks out the open(2) system call for a successful
 * invocation
 *
 *   Argument is pointer to test_objects array of structures of type
 *   all_test_cases
 ***********************************************************************/
void
do_open(tc_ptr)
struct all_test_cases *tc_ptr;
{
     int fd = -1;
     int ret, pts_at_object = 0;
     char scratch[PATH_MAX];

     
     if (stat(tc_ptr->fn_arg[2], &statter) != -1)
        pts_at_object=1;

     if (pts_at_object) {
	TEST( open(tc_ptr->fn_arg[1], O_RDWR) );
        errno=TEST_ERRNO;
        if ((fd=TEST_RETURN) == -1) {
           tst_resm(TFAIL,
	       "open(2) Failure when opening object file through symbolic link file");
           return;
        }
     }
     else {
	TEST(open(tc_ptr->fn_arg[1], (O_CREAT | O_RDWR), MODE) );
	errno=TEST_ERRNO;
        if ((fd=TEST_RETURN) == -1) {
           tst_resm(TFAIL,
	       "open(2) Failure when creating object file through symbolic link file");
           return;
        }
     }
     if ((ret=write(fd, BIG_STRING, strlen(BIG_STRING))) == -1) {
        tst_resm(TFAIL,
	    "write(2) Failure to object file opened through a symbolic link file: errno:%d",
	    errno);
     }
     else if (ret != strlen(BIG_STRING)) {
        tst_resm(TFAIL,
	    "write(2) Failed to write %d bytes to object file opened through a symbolic link file",
	    strlen(BIG_STRING));
     }
     else if (lseek(fd, 0L, 0) == -1) {
        tst_resm(TFAIL,
	    "lseek(2) Failed to position to beginning of object file opened through a symbolic link file: errno = %d",
	    errno);
     }
     else if ((ret=read(fd, scratch, strlen(BIG_STRING))) == -1) {
        tst_resm(TFAIL,
	    "read(2) Failure of object file opened through a symbolic link file: errno = %d",
	    errno);
     }
     else if (ret != strlen(BIG_STRING)) {
        tst_resm(TFAIL,
	    "read(2) Failed to read %d bytes to object file opened through a symbolic link file",
	    strlen(BIG_STRING));
     }
     else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
        tst_resm(TFAIL,
	    "Content of write(2) and read(2) Failed to object file through symbolic link file was not as expected. Expected %s and read returned %s",
	    BIG_STRING, scratch);
     }
     else {
        /*
         *  Close off symbolic link file to object file access
         */
        if (close(fd) == -1) {
           tst_resm(TFAIL,
	       "close(2) Failure when closing object file accessed symbolic link file");
        }
        /*
         * Now, lets open up and read object file and compare contents
        */
        else if ((fd=open(tc_ptr->fn_arg[0], O_RDONLY)) == -1) {
           tst_resm(TFAIL, "open(2) Failure when opening %s file: errno:%d %s",
	       tc_ptr->fn_arg[0], errno, strerror(errno));
        }
        else if ((ret=read(fd, scratch, strlen(BIG_STRING))) == -1) {
           tst_resm(TFAIL,
	       "read(2) Failure of object file opened through a symbolic link file: errno:%d", errno);
        }
        else if (ret != strlen(BIG_STRING)) {
           tst_resm(TFAIL,
	       "read(2) Failed to read %d bytes to object file opened through a symbolic link file",
		strlen(BIG_STRING));
        }
        else if (strncmp(BIG_STRING, scratch, strlen(BIG_STRING)) != 0) {
           tst_resm(TFAIL,
	       "Content of write(2) and read(2) Failed to object file through symbolic link file was not as expected. Expected %s and read returned %s",
		BIG_STRING, scratch);
        }
        else if (pts_at_object) {
	   if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
               tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	   else
		Tst_count++;
        }
        else { /* Insure newly created object file is pointed at */
           if (ck_both(tc_ptr->fn_arg[0], tc_ptr->fn_arg[1], tc_ptr->fn_arg[0]))
	      if ( TEST_RESULT != TPASS || STD_FUNCTIONAL_TEST  )
                  tst_resm(TEST_RESULT, msgs[tc_ptr->pass_msg]);
	      else
	 	  Tst_count++;
           else
              tst_resm(TFAIL, test_msg);
        }
        close(fd);
     }
}

/***************************************************************
 * setup() - performs all ONE TIME setup for this test.
 ***************************************************************/
void
setup()
{
    /* capture signals */
    tst_sig(FORK, DEF_HANDLER, cleanup);

    /* create a temporary directory and go to it */
    tst_tmpdir();

    /* Pause if that option was specified */
    TEST_PAUSE;

}       /* End setup() */


/***************************************************************
 * cleanup() - performs all ONE TIME cleanup for this test at
 *              completion or premature exit.
 ***************************************************************/
void
cleanup()
{
    /*
     * print timing stats if that option was specified.
     */
    TEST_CLEANUP;

    /* remove temporary directory and all files in it. */
    tst_rmdir();

    /* exit with return code appropriate for results */
    tst_exit();

}       /* End cleanup() */


/*
 *
 */
void help()
{
    unsigned ind;

    printf("   -T id  Determines which tests cases to execute:\n");

    for (ind=0; ind<sizeof(all_tcses)/sizeof(struct tcses ); ind++) {
	printf("  %s/%s - %s\n", all_tcses[ind].tcid, all_tcses[ind].syscall,
	    all_tcses[ind].desc);
    }
}