POSIX.1 将 read函数的原型做了修改,经典的定义为
1 int read(int filedes, char *buf, unsigned nbytes);
修改为
1 ssize_t read(int filedes, void *buf, size_t nbytes);
主要从以下几个方面考虑
- First, the second argument was changed from a char * to a void * to be consistent with ISO C: the type void * is used for generic pointers.
- Next, the return value must be a signed integer (ssize_t) to return a positive byte count, 0 (for end of file), or 1 (for an error).
- Finally, the third argument historically has been an unsigned integer, to allow a 16-bit implementation to read or write up to 65,534 bytes at a time. With the 1990 POSIX.1 standard, the primitive system data type ssize_t was introduced to provide the signed return value, and the unsigned size_t was used for the third argument. (Recall the SSIZE_MAX constant from Section 2.5.2.)
引自 <Advanced Programming in the UNIX® Environment: Second Edition>
中文名为<UNIX环境高级编程:第二版>
时间: 2024-10-11 05:44:24