Header File
io.h
Category
Input/output Routines
Prototype
int _rtl_read(int handle, void *buf, unsigned len);
Description
Reads from file.
The argument handle is a file handle obtained from a creat, open, dup, or dup2 call.
On disk files, _rtl_read begins reading at the current file pointer. When the reading is complete, it increments the file pointer by the number of bytes read. On devices, the bytes are read directly from the device.
The maximum number of bytes it can read is UINT_MAX -1 (because UINT_MAX is the same as -1, the error return indicator). UINT_MAX is defined in limits.h.
Return Value
On success, _rtl_read returns either
EACCES |
Permission denied |
EBADF |
Bad file number |
Example
#include <stdio.h> #include <io.h> #include <alloc.h> #include <fcntl.h> #include <process.h> #include <sys\stat.h> int main(void) { void *buf; int handle, bytes; buf = malloc(10); /* Looks for a file in the current directory named TEST.$$$ and attempts to read 10 bytes from it. To use this example you should create the file TEST.$$$ */ if ((handle = open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1) { printf("Error Opening File\n"); exit(1); } if ((bytes = _rtl_read(handle, buf, 10)) == -1) { printf("Read Failed.\n"); exit(1); } else { printf("_rtl_read: %d bytes read.\n", bytes); } return 0; }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
|
+ |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|