Skip to content

Commit 49b6690

Browse files
author
Colin Robertson
committed
Fix cpp-docs issue 656, address Acrolinx issues.
1 parent 85115c9 commit 49b6690

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

  • docs/c-runtime-library/reference

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "_read"
3-
ms.date: "11/04/2016"
3+
ms.date: "02/13/2019"
44
apiname: ["_read"]
55
apilocation: ["msvcrt.dll", "msvcr80.dll", "msvcr90.dll", "msvcr100.dll", "msvcr100_clr0400.dll", "msvcr110.dll", "msvcr110_clr0400.dll", "msvcr120.dll", "msvcr120_clr0400.dll", "ucrtbase.dll", "api-ms-win-crt-stdio-l1-1-0.dll"]
66
apitype: "DLLExport"
@@ -16,9 +16,9 @@ Reads data from a file.
1616

1717
```C
1818
int _read(
19-
int fd,
20-
void *buffer,
21-
unsigned int count
19+
int const fd,
20+
void * const buffer,
21+
unsigned const buffer_size
2222
);
2323
```
2424

@@ -30,22 +30,22 @@ File descriptor referring to the open file.
3030
*buffer*<br/>
3131
Storage location for data.
3232

33-
*count*<br/>
34-
Maximum number of bytes.
33+
*buffer_size*<br/>
34+
Maximum number of bytes to read.
3535

3636
## Return Value
3737

38-
**_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.
38+
**_read** returns the number of bytes read, which might be less than *buffer_size* if there are fewer than *buffer_size* bytes left in the file, or if the file was opened in text mode. In text mode, 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.
3939

40-
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**.
40+
If the function tries to read at end of file, it returns 0. If *fd* is not valid, the file isn't 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**.
4141

42-
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**.
42+
If *buffer* is **NULL**, or if *buffer_size* > **INT_MAX**, the invalid parameter handler is invoked. If execution is allowed to continue, the function returns -1 and **errno** is set to **EINVAL**.
4343

4444
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).
4545

4646
## Remarks
4747

48-
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.
48+
The **_read** function reads a maximum of *buffer_size* 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.
4949

5050
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](lseek-lseeki64.md) to clear the end-of-file indicator.
5151

@@ -81,18 +81,18 @@ char buffer[60000];
8181

8282
int main( void )
8383
{
84-
int fh;
85-
unsigned int nbytes = 60000, bytesread;
84+
int fh, bytesread;
85+
unsigned int nbytes = 60000;
8686

8787
/* Open file for input: */
88-
if( _sopen_s( &fh, "crt_read.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
88+
if ( _sopen_s( &fh, "crt_read.txt", _O_RDONLY, _SH_DENYNO, 0 ))
8989
{
9090
perror( "open failed on input file" );
9191
exit( 1 );
9292
}
9393

9494
/* Read in input: */
95-
if( ( bytesread = _read( fh, buffer, nbytes ) ) <= 0 )
95+
if (( bytesread = _read( fh, buffer, nbytes )) <= 0 )
9696
perror( "Problem reading file" );
9797
else
9898
printf( "Read %u bytes from file\n", bytesread );

0 commit comments

Comments
 (0)