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

@chapter Files and Directories Manager

@section Introduction

The files and directories manager is ...

The directives provided by the files and directories manager are:

@itemize @bullet
@item @code{opendir} - Open a Directory
@item @code{readdir} - Reads a directory
@item @code{rewinddir} - Resets the @code{readdir()} pointer
@item @code{scandir} - Scan a directory for matching entries
@item @code{telldir} - Return current location in directory stream
@item @code{closedir} - Ends directory read operation
@item @code{getdents} - Get directory entries
@item @code{chdir} - Changes the current working directory
@item @code{getcwd} - Gets current working directory
@item @code{open} - Opens a file
@item @code{creat} - Create a new file or rewrite an existing one
@item @code{umask} - Sets a file creation mask
@item @code{link} - Creates a link to a file
@item @code{symlink} - Creates a symbolic link to a file
@item @code{readlink} - Obtain the name of the link destination
@item @code{mkdir} - Makes a directory
@item @code{mkfifo} - Makes a FIFO special file
@item @code{unlink} - Removes a directory entry
@item @code{rmdir} - Delete a directory
@item @code{rename} - Renames a file
@item @code{stat} - Gets information about a file.
@item @code{fstat} - Gets file status
@item @code{lstat} - Gets file status
@item @code{access} - Check permissions for a file.
@item @code{chmod} - Changes file mode
@item @code{fchmod} - Changes permissions of a file
@item @code{chown} - Changes the owner and/ or group of a file
@item @code{utime} - Change access and/or modification times of an inode
@item @code{ftruncate} - Truncate a file to a specified length
@item @code{truncate} - Truncate a file to a specified length
@item @code{pathconf} - Gets configuration values for files
@item @code{fpathconf} - Get configuration values for files
@item @code{mknod} - Create a directory
@end itemize

@section Background

@subsection Path Name Evaluation

A pathname is a string that consists of no more than @code{PATH_MAX}
bytes, including the terminating null character. A pathname has an optional
beginning slash, followed by zero or more filenames separated by slashes.
If the pathname refers to a directory, it may also have one or more trailing
slashes. Multiple successive slahes are considered to be the same as
one slash.

POSIX allows a pathname that begins with precisely two successive slashes to be
interpreted in an implementation-defined manner. RTEMS does not currently
recognize this as a special condition. Any number of successive
slashes is treated the same as a single slash. POSIX requires that
an implementation treat more than two leading slashes as a single slash.

@section Operations

There is currently no text in this section.

@section Directives

This section details the files and directories manager's directives.
A subsection is dedicated to each of this manager's directives
and describes the calling sequence, related constants, usage,
and status codes.

@c
@c
@c
@page
@subsection opendir - Open a Directory

@findex opendir
@cindex  open a directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <dirent.h>

int opendir(
  const char *dirname
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission was denied on a component of the path
prefix of @code{dirname}, or read permission is denied

@item EMFILE
Too many file descriptors in use by process

@item ENFILE
Too many files are currently open in the system.

@item ENOENT
Directory does not exist, or @code{name} is an empty string.

@item ENOMEM
Insufficient memory to complete the operation.

@item ENOTDIR
@code{name} is not a directory.

@end table

@subheading DESCRIPTION:

This routine opens a directory stream corresponding to the
directory specified by the @code{dirname} argument. The
directory stream is positioned at the first entry.

@subheading NOTES:

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection readdir - Reads a directory

@findex readdir
@cindex  reads a directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <dirent.h>

int readdir(
  DIR *dirp
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EBADF
Invalid file descriptor

@end table

@subheading DESCRIPTION:

The @code{readdir()} function returns a pointer to a structure @code{dirent}
representing the next directory entry from the directory stream pointed to
by @code{dirp}. On end-of-file, NULL is returned.

The @code{readdir()} function may (or may not) return entries for . or .. Your
program should tolerate reading dot and dot-dot but not require them.

The data pointed to be @code{readdir()} may be overwritten by another call to
@code{readdir()} for the same directory stream. It will not be overwritten by
a call for another directory.

@subheading NOTES:

If @code{ptr} is not a pointer returned by @code{malloc()}, @code{calloc()}, or
@code{realloc()} or has been deallocated with @code{free()} or
@code{realloc()}, the results are not portable and are probably disastrous.

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection rewinddir - Resets the readdir() pointer

@findex rewinddir
@cindex  resets the readdir() pointer

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <dirent.h>

void rewinddir(
  DIR *dirp
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

No value is returned.

@subheading DESCRIPTION:

The @code{rewinddir()} function resets the position associated with
the directory stream pointed to by @code{dirp}. It also causes the
directory stream to refer to the current state of the directory.

@subheading NOTES:

NONE

If @code{dirp} is not a pointer by @code{opendir()}, the results are
undefined.

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection scandir - Scan a directory for matching entries

@findex scandir
@cindex  scan a directory for matching entries

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <dirent.h>

int scandir(
  const char *dir,
  struct dirent ***namelist,
  int (*select)(const struct dirent *),
  int (*compar)(const struct dirent **, const struct dirent **)
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item ENOMEM
Insufficient memory to complete the operation.

@end table

@subheading DESCRIPTION:

The @code{scandir()} function scans the directory @code{dir}, calling
@code{select()} on each directory entry. Entries for which @code{select()}
returns non-zero are stored in strings allocated via @code{malloc()},
sorted using @code{qsort()} with the comparison function @code{compar()},
and collected in array @code{namelist} which is allocated via @code{malloc()}.
If @code{select} is NULL, all entries are selected.

@subheading NOTES:

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection telldir - Return current location in directory stream

@findex telldir
@cindex  return current location in directory stream

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <dirent.h>

off_t telldir(
  DIR *dir
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EBADF
Invalid directory stream descriptor @code{dir}.

@end table

@subheading DESCRIPTION:

The @code{telldir()} function returns the current location associated with the
directory stream @code{dir}.

@subheading NOTES:

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection closedir - Ends directory read operation

@findex closedir
@cindex  ends directory read operation

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <dirent.h>

int closedir(
  DIR *dirp
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EBADF
Invalid file descriptor

@end table

@subheading DESCRIPTION:

The directory stream associated with @code{dirp} is closed.
The value in @code{dirp} may not be usable after a call to
@code{closedir()}.

@subheading NOTES:

NONE

The argument to @code{closedir()} must be a pointer returned by
@code{opendir()}. If it is not, the results are not portable and
most likely unpleasant.

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection chdir - Changes the current working directory

@findex chdir
@cindex  changes the current working directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int chdir(
  const char *path
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is
in effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the specified pathname was not a directory when directory
was expected.

@end table

@subheading DESCRIPTION:

The @code{chdir()} function causes the directory named by @code{path} to
become the current working directory; that is, the starting point for
searches of pathnames not beginning with a slash.

If @code{chdir()} detects an error, the current working directory is not
changed.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection getcwd - Gets current working directory

@findex getcwd
@cindex  gets current working directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int getcwd( void );
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EINVAL
Invalid argument

@item ERANGE
Result is too large

@item EACCES
Search permission is denied for a directory in a file's path prefix.

@end table

@subheading DESCRIPTION:

The @code{getcwd()} function copies the absolute pathname of the current
working directory to the character array pointed to by @code{buf}. The
@code{size} argument is the number of bytes available in @code{buf}

@subheading NOTES:

There is no way to determine the maximum string length that @code{fetcwd()}
may need to return. Applications should tolerate getting @code{ERANGE}
and allocate a larger buffer.

It is possible for @code{getcwd()} to return EACCES if, say, @code{login}
puts the process into a directory without read access.

The 1988 standard uses @code{int} instead of @code{size_t} for the second
parameter.

@c
@c
@c
@page
@subsection open - Opens a file

@findex open
@cindex  opens a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int open(
  const char *path,
  int         oflag,
  mode_t      mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b

@item EACCES
Search permission is denied for a directory in a file's path prefix.

@item EEXIST
The named file already exists.

@item EINTR
Function was interrupted by a signal.

@item EISDIR
Attempt to open a directory for writing or to rename a file to be a
directory.

@item EMFILE
Too many file descriptors are in use by this process.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENFILE
Too many files are currently open in the system.

@item ENOENT
A file or directory does not exist.

@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item ENXIO
No such device. This error may also occur when a device is not ready, for
example, a tape drive is off-line.

@item EROFS
Read-only file system.
@end table

@subheading DESCRIPTION:

The @code{open} function establishes a connection between a file and a file
descriptor. The file descriptor is a small integer that is used by I/O
functions to reference the file. The @code{path} argument points to the
pathname for the file.

The @code{oflag} argument is the bitwise inclusive OR of the values of
symbolic constants. The programmer must specify exactly one of the following
three symbols:

@table @b
@item O_RDONLY
Open for reading only.

@item O_WRONLY
Open for writing only.

@item O_RDWR
Open for reading and writing.

@end table

Any combination of the following symbols may also be used.

@table @b
@item O_APPEND
Set the file offset to the end-of-file prior to each write.

@item O_CREAT
If the file does not exist, allow it to be created. This flag indicates
that the @code{mode} argument is present in the call to @code{open}.

@item O_EXCL
This flag may be used only if O_CREAT is also set. It causes the call
to @code{open} to fail if the file already exists.

@item O_NOCTTY
If @code{path} identifies a terminal, this flag prevents that teminal from
becoming the controlling terminal for thi9s process. See Chapter 8 for a
description of terminal I/O.

@item O_NONBLOCK
Do no wait for the device or file to be ready or available. After the file
is open, the @code{read} and @code{write} calls return immediately. If the
process would be delayed in the read or write opermation, -1 is returned and
@code{errno} is set to @code{EAGAIN} instead of blocking the caller.

@item O_TRUNC
This flag should be used only on ordinary files opened for writing. It
causes the file to be tuncated to zero length..

@end table

Upon successful completion, @code{open} returns a non-negative file
descriptor.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection creat - Create a new file or rewrite an existing one

@findex creat
@cindex  create a new file or rewrite an existing one

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int creat(
  const char *path,
  mode_t      mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EEXIST
@code{path} already exists and O_CREAT and O_EXCL were used.

@item EISDIR
@code{path} refers to a directory and the access requested involved
writing

@item ETXTBSY
@code{path} refers to an executable image which is currently being
executed and write access was requested

@item EFAULT
@code{path} points outside your accessible address space

@item EACCES
The requested access to the file is not allowed, or one of the
directories in @code{path} did not allow search (execute) permission.

@item ENAMETOOLONG
@code{path} was too long.

@item ENOENT
A directory component in @code{path} does not exist or is a dangling
symbolic link.

@item ENOTDIR
A component used as a directory in @code{path} is not, in fact, a
directory.

@item EMFILE
The process alreadyh has the maximum number of files open.

@item ENFILE
The limit on the total number of files open on the system has been
reached.

@item ENOMEM
Insufficient kernel memory was available.

@item EROFS
@code{path} refers to a file on a read-only filesystem and write access
was requested

@end table

@subheading DESCRIPTION:

@code{creat} attempts to create a file and return a file descriptor for
use in read, write, etc.

@subheading NOTES:

NONE

The routine is implemented in Cygnus newlib.

@c
@c
@c
@page
@subsection umask - Sets a file creation mask.

@findex umask
@cindex  sets a file creation mask.

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

mode_t umask(
  mode_t cmask
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@subheading DESCRIPTION:

The @code{umask()} function sets the process file creation mask to @code{cmask}.
The file creation mask is used during @code{open()}, @code{creat()}, @code{mkdir()},
@code{mkfifo()} calls to turn off permission bits in the @code{mode} argument.
Bit positions that are set in @code{cmask} are cleared in the mode of the
created file.

@subheading NOTES:

NONE

The @code{cmask} argument should have only permission bits set. All other
bits should be zero.

In a system which supports multiple processes, the file creation mask is inherited
across @code{fork()} and @code{exec()} calls. This makes it possible to alter the
default permission bits of created files. RTEMS does not support multiple processes
so this behavior is not possible.

@c
@c
@c
@page
@subsection link - Creates a link to a file

@findex link
@cindex  creates a link to a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int link(
  const char *existing,
  const char *new
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b

@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EEXIST
The named file already exists.

@item EMLINK
The number of links would exceed @code{LINK_MAX}.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.
@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item EPERM
Operation is not permitted. Process does not have the appropriate priviledges
or permissions to perform the requested operations.

@item EROFS
Read-only file system.

@item EXDEV
Attempt to link a file to another file system.

@end table

@subheading DESCRIPTION:

The @code{link()} function atomically creates a new link for an existing file
and increments the link count for the file.

If the @code{link()} function fails, no directories are modified.

The @code{existing} argument should not be a directory.

The caller may (or may not) need permission to access the existing file.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection symlink - Creates a symbolic link to a file

@findex symlink
@cindex  creates a symbolic link to a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int symlink(
  const char *topath,
  const char *frompath
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b

@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EEXIST
The named file already exists.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item EPERM
Operation is not permitted. Process does not have the appropriate priviledges
or permissions to perform the requested operations.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

The @code{symlink()} function creates a symbolic link from the frombath to the
topath. The symbolic link will be interpreted at run-time.

If the @code{symlink()} function fails, no directories are modified.

The caller may (or may not) need permission to access the existing file.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection readlink - Obtain the name of a symbolic link destination

@findex readlink
@cindex  obtain the name of a symbolic link destination

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int readlink(
  const char *path,
  char       *buf,
  size_t      bufsize
);

@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b

@item EACCES
Search permission is denied for a directory in a file's path prefix

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the prefix pathname was not a directory when a directory
was expected.

@item ELOOP
Too many symbolic links were encountered in the pathname.

@item EINVAL
The pathname does not refer to a symbolic link

@item EFAULT
An invalid pointer was passed into the @code{readlink()} routine.

@end table

@subheading DESCRIPTION:

The @code{readlink()} function places the symbolic link destination into
@code{buf} argument and returns the number of characters copied.

If the symbolic link destination is longer than bufsize characters the
name will be truncated.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection mkdir - Makes a directory

@findex mkdir
@cindex  makes a directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int mkdir(
  const char *path,
  mode_t      mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EEXIST
The name file already exist.

@item EMLINK
The number of links would exceed LINK_MAX

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

The @code{mkdir()} function creates a new diectory named @code{path}. The
permission bits (modified by the file creation mask) are set from @code{mode}.
The owner and group IDs for the directory are set from the effective user ID
and group ID.

The new directory may (or may not) contain entries for.. and .. but is otherwise
empty.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection mkfifo - Makes a FIFO special file

@findex mkfifo
@cindex  makes a fifo special file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>


int mkfifo(
  const char *path,
  mode_t      mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EEXIST
The named file already exists.

@item ENOENT
A file or directory does not exist.

@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified @code{path} was not a directory when a directory
was expected.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

The @code{mkfifo()} function creates a new FIFO special file named @code{path}.
The permission bits (modified by the file creation mask) are set from
@code{mode}. The owner and group IDs for the FIFO are set from the efective
user ID and group ID.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection unlink - Removes a directory entry

@findex unlink
@cindex  removes a directory entry

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int unlink(
  const char path
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EBUSY
The directory is in use.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the specified @code{path} was not a directory when a directory
was expected.

@item EPERM
Operation is not permitted. Process does not have the appropriate priviledges
or permissions to perform the requested operations.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

The @code{unlink} function removes the link named by @code{path} and decrements the
link count of the file referenced by the link. When the link count goes to zero
and no process has the file open, the space occupied by the file is freed and the
file is no longer accessible.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection rmdir - Delete a directory

@findex rmdir
@cindex  delete a directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int rmdir(
  const char *pathname
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EPERM
The filesystem containing @code{pathname} does not support the removal
of directories.

@item EFAULT
@code{pathname} points ouside your accessible address space.

@item EACCES
Write access to the directory containing @code{pathname} was not
allowed for the process's effective uid, or one of the directories in
@code{pathname} did not allow search (execute) permission.

@item EPERM
The directory containing @code{pathname} has the stickybit (S_ISVTX)
set and the process's effective uid is neither the uid of the file to
be delected nor that of the director containing it.

@item ENAMETOOLONG
@code{pathname} was too long.

@item ENOENT
A dirctory component in @code{pathname} does not exist or is a
dangling symbolic link.

@item ENOTDIR
@code{pathname}, or a component used as a directory in @code{pathname},
is not, in fact, a directory.

@item ENOTEMPTY
@code{pathname} contains entries other than . and .. .

@item EBUSY
@code{pathname} is the current working directory or root directory of
some process

@item EBUSY
@code{pathname} is the current directory or root directory of some
process.

@item ENOMEM
Insufficient kernel memory was available

@item EROGS
@code{pathname} refers to a file on a read-only filesystem.

@item ELOOP
@code{pathname} contains a reference to a circular symbolic link

@end table

@subheading DESCRIPTION:

@code{rmdir} deletes a directory, which must be empty


@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection rename - Renames a file

@findex rename
@cindex  renames a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int rename(
  const char *old,
  const char *new
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix.

@item EBUSY
The directory is in use.

@item EEXIST
The named file already exists.

@item EINVAL
Invalid argument.

@item EISDIR
Attempt to open a directory for writing or to rename a file to be a
directory.

@item EMLINK
The number of links would exceed LINK_MAX.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is
in effect.

@item ENOENT
A file or directory does no exist.

@item ENOSPC
No space left on disk.

@item ENOTDIR
A component of the specified pathname was not a directory when a
directory was expected.

@item ENOTEMPTY
Attempt to delete or rename a non-empty directory.

@item EROFS
Read-only file system

@item EXDEV
Attempt to link a file to another file system.
@end table

@subheading DESCRIPTION:

The @code{rename()} function causes the file known bo @code{old} to
now be known as @code{new}.

Ordinary files may be renamed to ordinary files, and directories may be
renamed to directories; however, files cannot be converted using
@code{rename()}. The @code{new} pathname may not contain a path prefix
of @code{old}.

@subheading NOTES:

If a file already exists by the name @code{new}, it is removed. The
@code{rename()} function is atomic. If the @code{rename()} detects an
error, no files are removed. This guarantees that the
@code{rename("x", "x")} does not remove @code{x}.

You may not rename dot or dot-dot.

The routine is implemented in Cygnus newlib using @code{link()} and
@code{unlink()}.

@c
@c
@c
@page
@subsection stat - Gets information about a file

@findex stat
@cindex  gets information about a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int stat(
  const char  *path,
  struct stat *buf
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix.

@item EBADF
Invalid file descriptor.

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is
in effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the specified pathname was not a directory when a
directory was expected.

@end table

@subheading DESCRIPTION:

The @code{path} argument points to a pathname for a file. Read, write, or
execute permission for the file is not required, but all directories listed
in @code{path} must be searchable. The @code{stat()} function obtains
information about the named file and writes it to the area pointed to by
@code{buf}.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection fstat - Gets file status

@findex fstat
@cindex  gets file status

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int fstat(
  int fildes,
  struct stat *buf
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EBADF
Invalid file descriptor

@end table

@subheading DESCRIPTION:

The @code{fstat()} function obtains information about the file
associated with @code{fildes} and writes it to the area pointed
to by the @code{buf} argument.

@subheading NOTES:

If the filesystem object referred to by @code{fildes} is a
link, then the information returned in @code{buf} refers
to the destination of that link.  This is in contrast to
@code{lstat()} which does not follow the link.

@c
@c
@c
@page
@subsection lstat - Gets file status

@findex lstat
@cindex  gets file status

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int lstat(
  int          fildes,
  struct stat *buf
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EBADF
Invalid file descriptor

@end table

@subheading DESCRIPTION:

The @code{lstat()} function obtains information about the file
associated with @code{fildes} and writes it to the area pointed
to by the @code{buf} argument.

@subheading NOTES:

If the filesystem object referred to by @code{fildes} is a
link, then the information returned in @code{buf} refers
to the link itself.  This is in contrast to @code{fstat()}
which follows the link.

The @code{lstat()} routine is defined by BSD 4.3 and SVR4 
and not included in POSIX 1003.1b-1996.

@c
@c
@c
@page
@subsection access - Check permissions for a file

@findex access
@cindex  check permissions for a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int access(
  const char *pathname,
  int         mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
The requested access would be denied, either to the file itself or
one of the directories in @code{pathname}.

@item EFAULT
@code{pathname} points outside your accessible address space.

@item EINVAL
@code{Mode} was incorrectly specified.

@item ENAMETOOLONG
@code{pathname} is too long.

@item ENOENT
A directory component in @code{pathname} would have been accessible but
does not exist or was a dangling symbolic link.

@item ENOTDIR
A component used as a directory in @code{pathname} is not, in fact,
a directory.

@item ENOMEM
Insufficient kernel memory was available.

@end table

@subheading DESCRIPTION:

@code{Access} checks whether the process would be allowed to read, write or
test for existence of the file (or other file system object) whose name is
@code{pathname}. If @code{pathname} is a symbolic link permissions of the
file referred by this symbolic link are tested.

@code{Mode} is a mask consisting of one or more of R_OK, W_OK, X_OK and F_OK.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection chmod - Changes file mode.

@findex chmod
@cindex  changes file mode.

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int chmod(
  const char *path,
  mode_t      mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item EPERM
Operation is not permitted. Process does not have the appropriate priviledges
or permissions to perform the requested operations.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

Set the file permission bits, the set user ID bit, and the set group ID bit
for the file named by @code{path} to @code{mode}. If the effective user ID
does not match the owner of the file and the calling process does not have
the appropriate privileges, @code{chmod()} returns -1 and sets @code{errno} to
@code{EPERM}.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection fchmod - Changes permissions of a file

@findex fchmod
@cindex  changes permissions of a file

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <sys/stat.h>

int fchmod(
  int    fildes,
  mode_t mode
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix.

@item EBADF
The descriptor is not valid.

@item EFAULT
@code{path} points outside your accessible address space.

@item EIO
A low-level I/o error occurred while modifying the inode.

@item ELOOP
@code{path} contains a circular reference

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is
in effect.

@item ENOENT
A file or directory does no exist.

@item ENOMEM
Insufficient kernel memory was avaliable.

@item ENOTDIR
A component of the specified pathname was not a directory when a
directory was expected.

@item EPERM
The effective UID does not match the owner of the file, and is not
zero

@item EROFS
Read-only file system
@end table

@subheading DESCRIPTION:

The mode of the file given by @code{path} or referenced by
@code{filedes} is changed.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection getdents - Get directory entries

@findex getdents
@cindex  get directory entries

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>
#include <linux/dirent.h>
#include <linux/unistd.h>

long getdents(
  int   dd_fd,
  char *dd_buf,
  int   dd_len
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

A successful call to @code{getdents} returns th the number of bytes read.
On end of directory, 0 is returned. When an error occurs, -1 is returned,
and @code{errno} is set appropriately.

@table @b
@item EBADF
Invalid file descriptor @code{fd}.

@item EFAULT
Argument points outside the calling process's address space.

@item EINVAL
Result buffer is too small.

@item ENOENT
No such directory.

@item ENOTDIR
File descriptor does not refer to a directory.

@end table

@subheading DESCRIPTION:

@code{getdents} reads several @code{dirent} structures from the directory
pointed by @code{fd} into the memory area pointed to by @code{dirp}. The
parameter @code{count} is the size of the memory area.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection chown - Changes the owner and/or group of a file.

@findex chown
@cindex  changes the owner and/or group of a file.

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>
#include <unistd.h>

int chown(
  const char *path,
  uid_t       owner,
  gid_t       group
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Search permission is denied for a directory in a file's path prefix

@item EINVAL
Invalid argument

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC is in
effect.

@item ENOENT
A file or directory does not exist.

@item ENOTDIR
A component of the specified pathname was not a directory when a directory
was expected.

@item EPERM
Operation is not permitted. Process does not have the appropriate priviledges
or permissions to perform the requested operations.

@item EROFS
Read-only file system.

@end table

@subheading DESCRIPTION:

The user ID and group ID of the file named by @code{path} are set to
@code{owner} and @code{path}, respectively.

For regular files, the set group ID (S_ISGID) and set user ID (S_ISUID)
bits are cleared.

Some systems consider it a security violation to allow the owner of a file to
be changed, If users are billed for disk space usage, loaning a file to
another user could result in incorrect billing. The @code{chown()} function
may be restricted to privileged users for some or all files. The group ID can
still be changed to one of the supplementary group IDs.

@subheading NOTES:

This function may be restricted for some file. The @code{pathconf} function
can be used to test the @code{_PC_CHOWN_RESTRICTED} flag.



@c
@c
@c
@page
@subsection utime - Change access and/or modification times of an inode

@findex utime
@cindex  change access and/or modification times of an inode

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <sys/types.h>

int utime(
  const char     *filename,
  struct utimbuf *buf
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EACCES
Permission to write the file is denied

@item ENOENT
@code{Filename} does not exist

@end table

@subheading DESCRIPTION:

@code{Utime} changes the access and modification times of the inode
specified by @code{filename} to the @code{actime} and @code{modtime}
fields of @code{buf} respectively. If @code{buf} is NULL, then the
access and modification times of the file are set to the current time.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection ftruncate - truncate a file to a specified length

@findex ftruncate
@cindex  truncate a file to a specified length

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int ftrunctate(
  int    fd,
  size_t length
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item ENOTDIR
A component of the path prefix is not a directory.

@item EINVAL
The pathname contains a character with the high-order bit set.

@item ENAMETOOLONG
A component of a pathname exceeded 255 characters, or an entire
path name exceeded 1023 characters.

@item ENOENT
The named file does not exist.

@item EACCES
The named file is not writable by the user.

@item EACCES
Search permission is denied for a component of the path prefix.

@item ELOOP
Too many symbolic links were encountered in translating the
pathname

@item EISDIR
The named file is a directory.

@item EROFS
The named file resides on a read-only file system

@item ETXTBSY
The file is a pure procedure (shared text) file that is being
executed

@item EIO
An I/O error occurred updating the inode.

@item EFAULT
@code{Path} points outside the process's allocated address space.

@item EBADF
The @code{fd} is not a valid descriptor.

@end table

@subheading DESCRIPTION:

@code{truncate()} causes the file named by @code{path} or referenced by
@code{fd} to be truncated to at most @code{length} bytes in size. If the
file previously was larger than this size, the extra data is lost. With
@code{ftruncate()}, the file must be open for writing.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection truncate - truncate a file to a specified length

@findex truncate
@cindex  truncate a file to a specified length

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int trunctate(
  const char *path,
  size_t      length
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item ENOTDIR
A component of the path prefix is not a directory.

@item EINVAL
The pathname contains a character with the high-order bit set.

@item ENAMETOOLONG
A component of a pathname exceeded 255 characters, or an entire
path name exceeded 1023 characters.

@item ENOENT
The named file does not exist.

@item EACCES
The named file is not writable by the user.

@item EACCES
Search permission is denied for a component of the path prefix.

@item ELOOP
Too many symbolic links were encountered in translating the
pathname

@item EISDIR
The named file is a directory.

@item EROFS
The named file resides on a read-only file system

@item ETXTBSY
The file is a pure procedure (shared text) file that is being
executed

@item EIO
An I/O error occurred updating the inode.

@item EFAULT
@code{Path} points outside the process's allocated address space.

@item EBADF
The @code{fd} is not a valid descriptor.

@end table

@subheading DESCRIPTION:

@code{truncate()} causes the file named by @code{path} or referenced by
@code{fd} to be truncated to at most @code{length} bytes in size. If the
file previously was larger than this size, the extra data is lost. With
@code{ftruncate()}, the file must be open for writing.

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection pathconf - Gets configuration values for files

@findex pathconf
@cindex  gets configuration values for files

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int pathconf(
  const char *path,
  int         name
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EINVAL
Invalid argument

@item EACCES
Permission to write the file is denied

@item ENAMETOOLONG
Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC
is in effect.

@item ENOENT
A file or directory does not exist

@item ENOTDIR
A component of the specified @code{path} was not a directory whan a
directory was expected.

@end table

@subheading DESCRIPTION:

@code{pathconf()} gets a value for the configuration option @code{name}
for the open file descriptor @code{filedes}.

The possible values for @code{name} are:

@table @b
@item _PC_LINK_MAX
returns the maximum number of links to the file. If @code{filedes} or
@code{path} refer to a directory, then the value applies to the whole
directory. The corresponding macro is @code{_POSIX_LINK_MAX}.

@item _PC_MAX_CANON
returns the maximum length of a formatted input line, where @code{filedes}
or @code{path} must refer to a terminal. The corresponding macro is
@code{_POSIX_MAX_CANON}.

@item _PC_MAX_INPUT
returns the maximum length of an input line, where @code{filedes} or
@code{path} must refer to a terminal. The corresponding macro is
@code{_POSIX_MAX_INPUT}.

@item _PC_NAME_MAX
returns the maximum length of a filename in the directory @code{path} or
@code{filedes}. The process is allowed to create. The corresponding macro
is @code{_POSIX_NAME_MAX}.

@item _PC_PATH_MAX
returns the maximum length of a relative pathname when @code{path} or
@code{filedes} is the current working directory. The corresponding macro
is @code{_POSIX_PATH_MAX}.

@item _PC_PIPE_BUF
returns the size of the pipe buffer, where @code{filedes} must refer to a
pipe or FIFO and @code{path} must refer to a FIFO. The corresponding macro
is @code{_POSIX_PIPE_BUF}.

@item _PC_CHOWN_RESTRICTED
returns nonzero if the chown(2) call may not be used on this file. If
@code{filedes} or @code{path} refer to a directory, then this applies to all
files in that directory. The corresponding macro is
@code{_POSIX_CHOWN_RESTRICTED}.

@end table

@subheading NOTES:

Files with name lengths longer than the value returned for @code{name} equal
@code{_PC_NAME_MAX} may exist in the given directory.

@c
@c
@c
@page
@subsection fpathconf - Gets configuration values for files

@findex fpathconf
@cindex  gets configuration values for files

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>

int fpathconf(
  int filedes,
  int name
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@table @b
@item EINVAL
Invalid argument

@item EACCES
Permission to write the file is denied
@item ENAMETOOLONG

Length of a filename string exceeds PATH_MAX and _POSIX_NO_TRUNC
is in effect.

@item ENOENT
A file or directory does not exist

@item ENOTDIR
A component of the specified @code{path} was not a directory whan a
directory was expected.

@end table


@subheading DESCRIPTION:

@code{pathconf()} gets a value for the configuration option @code{name}
for the open file descriptor @code{filedes}.

The possible values for name are:

@table @b
@item _PC_LINK_MAX
returns the maximum number of links to the file. If @code{filedes} or
@code{path} refer to a directory, then the value applies to the whole
directory. The corresponding macro is _POSIX_LINK_MAX.

@item _PC_MAX_CANON
returns the maximum length of a formatted input line, where @code{filedes}
or @code{path} must refer to a terminal. The corresponding macro is
@code{_POSIX_MAX_CANON}.

@item _PC_MAX_INPUT
returns the maximum length of an input line, where @code{filedes} or
@code{path} must refer to a terminal. The corresponding macro is
@code{_POSIX_MAX_INPUT}.

@item _PC_NAME_MAX
returns the maximum length of a filename in the directory @code{path} or
@code{filedes}. The process is allowed to create. The corresponding macro
is @code{_POSIX_NAME_MAX}.

@item _PC_PATH_MAX
returns the maximum length of a relative pathname when @code{path} or
@code{filedes} is the current working directory. The corresponding macro
is @code{_POSIX_PATH_MAX}.

@item _PC_PIPE_BUF
returns the size of the pipe buffer, where @code{filedes} must refer to a
pipe or FIFO and @code{path} must refer to a FIFO. The corresponding macro
is @code{_POSIX_PIPE_BUF}.

@item _PC_CHOWN_RESTRICTED
returns nonzero if the @code{chown()} call may not be used on this file. If
@code{filedes} or @code{path} refer to a directory, then this applies to all
files in that directory. The corresponding macro is
@code{_POSIX_CHOWN_RESTRICTED}.

@end table

@subheading NOTES:

NONE

@c
@c
@c
@page
@subsection mknod - create a directory

@findex mknod
@cindex  create a directory

@subheading CALLING SEQUENCE:

@ifset is-C
@example
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

long mknod(
  const char *pathname,
  mode_t      mode,
  dev_t       dev
);
@end example
@end ifset

@ifset is-Ada
@end ifset

@subheading STATUS CODES:

@code{mknod} returns zero on success, or -1 if an error occurred (in which case,
errno is set appropriately).

@table @b
@item ENAMETOOLONG
@code{pathname} was too long.

@item ENOENT
A directory component in @code{pathname} does not exist or is a dangling symbolic
link.

@item ENOTDIR
A component used in the directory @code{pathname} is not, in fact, a directory.

@item ENOMEM
Insufficient kernel memory was available

@item EROFS
@code{pathname} refers to a file on a read-only filesystem.

@item ELOOP
@code{pathname} contains a reference to a circular symbolic link, ie a symbolic
link whose expansion contains a reference to itself.

@item ENOSPC
The device containing @code{pathname} has no room for the new node.

@end table

@subheading DESCRIPTION:

@code{mknod} attempts to create a filesystem node (file, device special file or
named pipe) named @code{pathname}, specified by @code{mode} and @code{dev}.

@code{mode} specifies both the permissions to use and the type of node to be created.

It should be a combination (using bitwise OR) of one of the file types listed
below and the permissions for the new node.

The permissions are modified by the process's @code{umask} in the usual way: the
permissions of the created node are @code{(mode & ~umask)}.

The file type should be one of @code{S_IFREG}, @code{S_IFCHR}, @code{S_IFBLK} and
@code{S_IFIFO} to specify a normal file (which will be created empty), character
special file, block special file or FIFO (named pipe), respectively, or zero, which
will create a normal file.

If the file type is @code{S_IFCHR} or @code{S_IFBLK} then @code{dev} specifies the major
and minor numbers of the newly created device special file; otherwise it is ignored.

The newly created node will be owned by the effective uid of the process. If the
directory containing the node has the set group id bit set, or if the filesystem
is mounted with BSD group semantics, the new node will inherit the group ownership
from its parent directory; otherwise it will be owned by the effective gid of the
process.


@subheading NOTES:

NONE