You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7e4ca48
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/c-runtime-library/reference/read.md
+30-25Lines changed: 30 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,57 +55,61 @@ translation.priority.ht:
55
55
- "zh-tw"
56
56
---
57
57
# _read
58
+
58
59
Reads data from a file.
59
60
60
61
## Syntax
61
62
62
63
```
63
-
64
-
int _read(
64
+
int _read(
65
65
int fd,
66
66
void *buffer,
67
67
unsigned int count
68
68
);
69
69
```
70
70
71
-
#### Parameters
72
-
`fd`
73
-
File descriptor referring to the open file.
71
+
### Parameters
72
+
73
+
*fd*
74
+
File descriptor referring to the open file.
74
75
75
-
*buffer*
76
-
Storage location for data.
76
+
*buffer*
77
+
Storage location for data.
77
78
78
-
*count*
79
-
Maximum number of bytes.
79
+
*count*
80
+
Maximum number of bytes.
80
81
81
82
## Return Value
82
-
_**read** returns the number of bytes read, which might be less than *count* if there are fewer than *count* bytes left in the file or if the file was opened in text mode, in which case each carriage return-line feed (CR-LF) pair is replaced with a single linefeed character. Only the single linefeed character is counted in the return value. The replacement does not affect the file pointer.
83
+
84
+
`_read` returns the number of bytes read, which might be less than *count* if there are fewer than *count* bytes left in the file or if the file was opened in text mode, in which case each carriage return-line feed pair `\r\n` is replaced with a single linefeed character `\n`. Only the single linefeed character is counted in the return value. The replacement does not affect the file pointer.
83
85
84
-
If the function tries to read at end of file, it returns 0. If `fd` is invalid, the file is not open for reading, or the file is locked, the invalid parameter handler is invoked, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, the function returns -1 and sets `errno` to `EBADF`.
86
+
If the function tries to read at end of file, it returns 0. If *fd* is not valid, the file is not open for reading, or the file is locked, the invalid parameter handler is invoked, as described in [Parameter Validation](../../c-runtime-library/parameter-validation.md). If execution is allowed to continue, the function returns -1 and sets `errno` to `EBADF`.
85
87
86
-
If *buffer* is **NULL**, the invalid parameter handler is invoked. If execution is allowed to continue, the function returns -1 and `errno` is set to `EINVAL`.
88
+
If *buffer* is **NULL**, the invalid parameter handler is invoked. If execution is allowed to continue, the function returns -1 and `errno` is set to `EINVAL`.
87
89
88
-
For more information about this and other return codes, see [_doserrno, errno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
90
+
For more information about this and other return codes, see [_doserrno, errno, _sys_errlist, and _sys_nerr](../../c-runtime-library/errno-doserrno-sys-errlist-and-sys-nerr.md).
89
91
90
92
## Remarks
91
-
The `_read` function reads a maximum of *count* bytes into *buffer* from the file associated with `fd`. The read operation begins at the current position of the file pointer associated with the given file. After the read operation, the file pointer points to the next unread character.
93
+
94
+
The `_read` function reads a maximum of *count* bytes into *buffer* from the file associated with *fd*. The read operation begins at the current position of the file pointer associated with the given file. After the read operation, the file pointer points to the next unread character.
92
95
93
-
If the file was opened in text mode, the read terminates when `_read` encounters a CTRL+Z character, which is treated as an end-of-file indicator. Use [_lseek](../../c-runtime-library/reference/lseek-lseeki64.md) to clear the end-of-file indicator.
96
+
If the file was opened in text mode, the read terminates when `_read` encounters a CTRL+Z character, which is treated as an end-of-file indicator. Use [_lseek](../../c-runtime-library/reference/lseek-lseeki64.md) to clear the end-of-file indicator.
94
97
95
98
## Requirements
96
99
97
100
|Routine|Required header|
98
101
|-------------|---------------------|
99
102
|`_read`|\<io.h>|
100
103
101
-
For more compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md) in the Introduction.
104
+
For more compatibility information, see [Compatibility](../../c-runtime-library/compatibility.md).
102
105
103
106
## Libraries
104
-
All versions of the [C run-time libraries](../../c-runtime-library/crt-library-features.md).
107
+
108
+
All versions of the [C run-time libraries](../../c-runtime-library/crt-library-features.md).
0 commit comments