From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,28ea7b019fb285f0 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2002-04-03 23:48:21 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: Paul Eggert Newsgroups: comp.unix.tru64 Subject: Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? Date: 03 Apr 2002 23:48:20 -0800 Organization: Twin Sun Inc, El Segundo, CA, USA Message-ID: <7wofgz6h17.fsf@sic.twinsun.com> Sender: eggert@sic.twinsun.com References: <200204012205.QAA0000012227@gskc01.stowers-institute.org> <200204020013.g320DUf08044@shade.twinsun.com> <7wzo0mwi2e.fsf@sic.twinsun.com> <7wwuvqxlm0.fsf@sic.twinsun.com> User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.unix.tru64:7203 Bob Harris writes: > the wording only says what nbyte is if it is greater than SSIZE_MAX. It's pretty clear from the standard that when nbyte is less than or equal to SSIZE_MAX, 'read' is supposed to read all nbyte bytes from a regular file. 'read' can return a value less than nbyte only at end of file, or if there is an error, or if a signal occurs. (The rules are a bit different for non-regular files.) There is no provision to return -1 with errno==EINVAL merely because the buffer size is too large. The ssize_t type was established mostly to allow implementations to do the right thing with buffers whose sizes did not fit in 'int'. This change occurred in POSIX 1003.1-1990; the earlier 1988 standard had 'read' returning 'int'. Perhaps older versions of Tru64 were defined according to the 1998 standard, and the incompatibility with newer editions of the standard has never been fixed for some reason. Also, POSIX says that 'readv' must fail with errno==EINVAL if the sum of the buffer lengths exceeds SSIZE_MAX. I wonder whether Tru64 readv fails with errno==EINVAL if the sum of the buffer lengths exceeds INT_MAX. If so, that would be another incompatibility with POSIX.