Lines Matching +full:write +full:- +full:to +full:- +full:read

1 .\" Copyright (C) Caldera International Inc. 2001-2002.  All rights reserved.
20 .\" nor the names of other contributors may be used to endorse or promote
26 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 LOW-LEVEL I/O
69 it is necessary to inform the system
70 of your intent to do so,
73 If you are going to write on a file,
74 it may also be necessary to create it.
75 The system checks your right to do so
77 Do you have permission to access it?),
83 Whenever I/O is to be done on the file,
84 the file descriptor is used instead of the name to identify the file.
85 (This is roughly analogous to the use of
86 .UC READ(5,...)
88 .UC WRITE(6,...)
92 the user program refers to the file
97 are similar in spirit to file descriptors,
99 A file pointer is a pointer to a structure that contains,
104 special arrangements exist to make this convenient.
112 All of these are normally connected to the terminal,
129 from the terminal to the named files.
131 Normally file descriptor 2 remains attached to the terminal,
136 The program does not need to know where its input
140 Read and Write
144 .UL read
146 .UL write .
148 The second argument is a buffer in your program where the data is to
149 come from or go to.
150 The third argument is the number of bytes to be transferred.
153 n_read = read(fd, buf, n);
155 n_written = write(fd, buf, n);
164 bytes remained to be read.
166 .UL read
167 normally reads only up to the next newline,
171 .UL -1
176 to the number supposed to be written.
178 The number of bytes to be read or written is quite arbitrary.
185 which corresponds to a physical blocksize on many peripheral devices.
191 we can write a simple program to copy
192 its input to its output.
193 This program will copy anything to anything,
194 since the input and output can be redirected to any file or device.
196 #define BUFSIZE 512 /* best size for PDP-11 UNIX */
198 main() /* copy input to output */
203 while ((n = read(0, buf, BUFSIZE)) > 0)
204 write(1, buf, n);
211 .UL read
214 .UL write ;
215 the next call to
216 .UL read
220 It is instructive to see how
221 .UL read
223 .UL write
224 can be used to construct
240 return((read(0, &c, 1) > 0) ? c & CMASK : EOF);
249 .UL read
258 .UC PDP -11
276 n = read(0, buf, BUFSIZE);
279 return((--n >= 0) ? *bufp++ & CMASK : EOF);
287 you must explicitly open files in order to
288 read or write them.
313 is a character string corresponding to the external file name.
317 is 0 for read, 1 for write, and 2 for read and write access.
320 .UL -1
324 It is an error to
325 try to
330 is provided to create new files,
331 or to re-write old ones.
336 if it was able to create the file
340 .UL -1
345 will truncate it to zero length;
346 it is not an error to
364 controlling read, write and execute permission for
368 Thus a three-digit octal number
372 specifies read, write and execute permission for the owner,
373 and read and execute permission for the group and everyone else.
381 a program which copies one file to another.
391 main(argc, argv) /* cp: copy f1 to f2 */
399 error("Usage: cp from to", NULL);
400 if ((f1 = open(argv[1], 0)) == -1)
402 if ((f2 = creat(argv[2], PMODE)) == -1)
405 while ((n = read(f1, buf, BUFSIZE)) > 0)
406 if (write(f2, buf, n) != n)
407 error("cp: write error", NULL);
422 there is a limit (typically 15-25)
425 Accordingly, any program which intends to process
426 many files must be prepared to re-use
449 .UL read
451 .UL write
455 a file can be read or written in any arbitrary order.
459 provides a way to move around in
468 to move to position
470 which is taken relative to the location
484 can be 0, 1, or 2 to specify that
486 is to be
491 to append to a file,
492 seek to the end before writing:
496 To get back to the beginning (``rewind''),
508 it is possible to treat files more or less like large arrays,
513 get(fd, pos, buf, n) /* read n bytes from position pos */
518 lseek(fd, pos, 0); /* get to pos */
519 return(read(fd, buf, n));
523 In pre-version 7
525 the basic entry point to the I/O system
529 is identical to
539 .UC PDP -11
546 is limited to 65,535;
556 Thus to get to an arbitrary place in a large file
561 equal to 1 and moves to the desired byte within the block.
568 Usually they indicate an error by returning a value of \-1.
569 Sometimes it is nice to know what sort of error occurred;
575 in the introduction to Section II
582 an attempt to open a file failed because it did not exist
583 or because the user lacked permission to read it.
585 you may want to print out the