BSD 3 development
[unix-history] / usr / man / man2 / vread.2
CommitLineData
d477989c
BJ
1.UC
2.TH VREAD 2
3.SH NAME
4vread \- read virtually
5.SH SYNOPSIS
6\fBvread(fildes, buffer, nbytes)\fR
7.br
8\fBchar *buffer;\fR
9.SH DESCRIPTION
10A file descriptor is a word returned from a successful
11.I open,
12.I creat,
13.I dup
14or
15.I pipe
16call.
17.I Buffer
18is the location of
19.I nbytes
20contiguous bytes into which the input will be placed.
21It is not guaranteed that all
22.I nbytes
23will be read (see
24.I read
25(2)).
26In particular, if the returned value is 0, then end-of-file has been reached.
27.PP
28Unlike
29.I read
30(2),
31.I vread
32does not necessarily or immediately fetch the data requested from
33.I fildes,
34but merely insures that the data will be fetched from the file descriptor
35.I "sometime before"
36the first reference to the data, at the system's discretion.
37Thus
38.I vread
39allows the system, among other possibilities,
40to choose to read data on demand,
41with whatever granularity is allowed by the memory management hardware,
42or to just read it in immediately as with
43.I read.
44A companion
45.I vwrite
46(2) call may be used with
47.I vread
48to provide an efficient mechanism for updating large files.
49The behavior of
50.I vread
51if other processes are writing to
52.I fildes
53is not defined.
54.PP
55Both the address of
56.I buffer
57and the current offset in
58.I fildes
59(as told by
60.I tell
61(2)) must be aligned to a multiple of VALSIZ (defined in ``<valign.h>'').
62The library routine
63.I valloc
64(3) allocates properly aligned blocks from the free list.
65.PP
66Note for non-virtual systems: the
67.I vread
68system call can be simulated (exactly, if less efficiently) by
69.I read.
70If the unit on which a
71.I vread
72is done is not capable of supporting efficient demand initialization
73(e.g. a terminal or a pipe), then the system may choose to treat a call to
74.I vread
75as if it were a call to
76.I read
77at its discretion.
78.SH SEE ALSO
79read(2), write(2), vwrite (2), valloc(3)
80.SH DIAGNOSTICS
81A 0 is returned at end-of-file. If the read was otherwise unsuccessful,
82a -1 is returned. Physical I/O errors, non-aligned or bad buffer addresses,
83preposterous
84.I nbytes,
85file descriptor not that of an input file, and file offset not properly
86aligned can all generate errors.
87.SH BUGS
88You can't
89.I close
90a file descriptor which you have
91.I vread
92from while there are still pages in the file which haven't been fetched by the
93system into your address space. In no case can a file descriptor which had
94such pages at the point of a
95.I vfork
96be closed during the
97.I vfork.
98.PP
99The system refuses to truncate a file to which any process has a pending
100.I vread.
101.PP
102There is no primitive inverting
103.I vread
104to release the binding
105.I vread
106sets up so that the file may be closed.
107This can be only be done, clumsily, by reading another (plain) file onto the
108buffer area, or pulling the break back with
109.IR break (2)
110to completely release the pages.