Definition | #include <stdio.h> int read(int fd, char *puf, int n);
In text files, |
Parameters
int fd
File descriptor for the input file. char *buf Pointer to the area into which the read data is to be written. The area should be at least int n Maximum number of bytes to be read. If the end of the line is reached first, fewer than | ||
Return val. | The number of bytes actually read | |
if successful. | ||
0 -1 | for end of file. if nothing was
|
Notes | The number of bytes actually read may be less than the specification in n if the end of the You should use The following applies in the case of text files with SAM access mode and variable record In the case of files with record-oriented input/output (record I/O), i.e. when the specification |
Example | The following program copies the standard input (file descriptor 0) to the standard output #include <stdio.h> int main(void) { char buf[BUFSIZ]; int n; while((n = read(0, buf, sizeof(buf))) > 0) write(1, buf, n); return 0; } |
See also | write, open, open64, creat, creat64 |