Skip to content

Commit 7e4ca48

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#76 from thebirk/patch-1
Fixed indentation
2 parents 508f80f + 430a0b2 commit 7e4ca48

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

  • docs/c-runtime-library/reference

‎docs/c-runtime-library/reference/read.md‎

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,61 @@ translation.priority.ht:
5555
- "zh-tw"
5656
---
5757
# _read
58+
5859
Reads data from a file.
5960

6061
## Syntax
6162

6263
```
63-
64-
int _read(
64+
int _read(
6565
int fd,
6666
void *buffer,
6767
unsigned int count
6868
);
6969
```
7070

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.
7475

75-
*buffer*
76-
Storage location for data.
76+
*buffer*
77+
Storage location for data.
7778

78-
*count*
79-
Maximum number of bytes.
79+
*count*
80+
Maximum number of bytes.
8081

8182
## 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.
8385

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`.
8587

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`.
8789

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).
8991

9092
## 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.
9295

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.
9497

9598
## Requirements
9699

97100
|Routine|Required header|
98101
|-------------|---------------------|
99102
|`_read`|\<io.h>|
100103

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).
102105

103106
## 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).
105109

106110
## Example
107111

108-
```
112+
```C
109113
// crt_read.c
110114
/* This program opens a file named crt_read.txt
111115
* and tries to read 60,000 bytes from
@@ -143,22 +147,23 @@ int main( void )
143147
}
144148
```
145149
146-
## Input: crt_read.txt
150+
### Input: crt_read.txt
147151
148152
```
149153
Line one.
150154
Line two.
151155
```
152156
153-
## Output
157+
### Output
154158
155159
```
156160
Read 19 bytes from file
157161
```
158162
159163
## See Also
160-
[Low-Level I/O](../../c-runtime-library/low-level-i-o.md)
161-
[_creat, _wcreat](../../c-runtime-library/reference/creat-wcreat.md)
162-
[fread](../../c-runtime-library/reference/fread.md)
163-
[_open, _wopen](../../c-runtime-library/reference/open-wopen.md)
164-
[_write](../../c-runtime-library/reference/write.md)
164+
165+
[Low-Level I/O](../../c-runtime-library/low-level-i-o.md)
166+
[_creat, _wcreat](../../c-runtime-library/reference/creat-wcreat.md)
167+
[fread](../../c-runtime-library/reference/fread.md)
168+
[_open, _wopen](../../c-runtime-library/reference/open-wopen.md)
169+
[_write](../../c-runtime-library/reference/write.md)

0 commit comments

Comments
 (0)