* read(fd, buf, N) fails when N doesn't fit in 32 bits? [not found] ` <200204020013.g320DUf08044@shade.twinsun.com> @ 2002-04-02 9:44 ` Paul Eggert 2002-04-02 13:15 ` Johan Danielsson 0 siblings, 1 reply; 6+ messages in thread From: Paul Eggert @ 2002-04-02 9:44 UTC (permalink / raw) A Tru64 5.1 user reports that GNU Diffutils 2.8 doesn't work on his system because the read(2) system call won't accept a size argument greater than 2**31 - 1. His truss output looks like this: read(6, 0x0000000140015000, 5312561138) Err#22 Invalid argument Is there some compile-time option that he can use on Tru64 to work around this problem? Or perhaps there's a Tru64 patch that I can recommend to him? You can read his original bug report in: http://groups.google.com/groups?hl=en&selm=200204012205.QAA0000012227%40gskc01.stowers-institute.org and my proposed workaround in: http://groups.google.com/groups?hl=en&selm=200204020013.g320DUf08044%40shade.twinsun.com This workaround limits the 'read' calls to less than 2**31 bytes, but I'd prefer a solution that removes that arbitrary limit. Sorry, I don't use Tru64 myself, so I'm not well versed in its compile-time options and patches. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? 2002-04-02 9:44 ` read(fd, buf, N) fails when N doesn't fit in 32 bits? Paul Eggert @ 2002-04-02 13:15 ` Johan Danielsson 2002-04-02 13:42 ` Paul Eggert 0 siblings, 1 reply; 6+ messages in thread From: Johan Danielsson @ 2002-04-02 13:15 UTC (permalink / raw) Paul Eggert <eggert@twinsun.com> writes: > Is there some compile-time option that he can use on Tru64 to work > around this problem? For obscure reasons, read doesn't accept large buffers: if (uap->count > INT_MAX) return (EINVAL); A workaround using readv is probably the easiest route. It would be fairly simple to autoconf a test for this. /Johan ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? 2002-04-02 13:15 ` Johan Danielsson @ 2002-04-02 13:42 ` Paul Eggert 2002-04-04 0:37 ` Bob Harris 0 siblings, 1 reply; 6+ messages in thread From: Paul Eggert @ 2002-04-02 13:42 UTC (permalink / raw) joda@pdc.kth.se (Johan Danielsson) writes: > For obscure reasons, read doesn't accept large buffers: > > if (uap->count > INT_MAX) > return (EINVAL); Ouch. My first reaction was "this violates POSIX!" but I just re-read the POSIX spec for "read" and it says "If the value of nbyte is greater than {SSIZE_MAX}, the result is implementation-defined." So -- what is the value of SSIZE_MAX on Tru64? Does SSIZE_MAX == INT_MAX? If so, then Tru64 conforms to POSIX after all, and I should limit reads to at most SSIZE_MAX bytes. I should do this anyway, to stay within the letter of POSIX law. If SSIZE_MAX == INT_MAX, that would suffice to avoid this problem on Tru64. > A workaround using readv is probably the easiest route. Thanks, but that would cause porting problems on other hosts, alas. I think I'll limit myself to (2**31 - 1)-byte reads. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? 2002-04-02 13:42 ` Paul Eggert @ 2002-04-04 0:37 ` Bob Harris 2002-04-04 7:48 ` Paul Eggert 0 siblings, 1 reply; 6+ messages in thread From: Bob Harris @ 2002-04-04 0:37 UTC (permalink / raw) In article <7wwuvqxlm0.fsf@sic.twinsun.com>, Paul Eggert <eggert@twinsun.com> wrote: X joda@pdc.kth.se (Johan Danielsson) writes: X X > For obscure reasons, read doesn't accept large buffers: X > X > if (uap->count > INT_MAX) X > return (EINVAL); X X Ouch. X X My first reaction was "this violates POSIX!" but I just re-read the X POSIX spec for "read" and it says "If the value of nbyte is greater X than {SSIZE_MAX}, the result is implementation-defined." X X So -- what is the value of SSIZE_MAX on Tru64? Does SSIZE_MAX == X INT_MAX? If so, then Tru64 conforms to POSIX after all, and I should X limit reads to at most SSIZE_MAX bytes. I should do this anyway, to X stay within the letter of POSIX law. If SSIZE_MAX == INT_MAX, that X would suffice to avoid this problem on Tru64. X X > A workaround using readv is probably the easiest route. X X Thanks, but that would cause porting problems on other hosts, alas. I X think I'll limit myself to (2**31 - 1)-byte reads. SSIZE_MAX on Tru64 UNIX is LONG_MAX (aka a signed 64 bit value). I am _NOT_ a POSIX lawyer, but the wording only says what nbyte is if it is greater than SSIZE_MAX. It does not say that nbyte needs to be as large as SSIZE_MAX. I know this is cutting it rather thin, but an argument could be made along those lines. There are lots of loop holes in the POSIX standard, this could be an intentional loop hole, poor wording on the part of POSIS, or it could be an Oops on the part of Compaq. Your mileage may vary (mine always does :-) Bob Harris ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? 2002-04-04 0:37 ` Bob Harris @ 2002-04-04 7:48 ` Paul Eggert 2002-04-05 15:33 ` Johan Danielsson 0 siblings, 1 reply; 6+ messages in thread From: Paul Eggert @ 2002-04-04 7:48 UTC (permalink / raw) Bob Harris <harris@zk3.dec.com> 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: read(fd, buf, N) fails when N doesn't fit in 32 bits? 2002-04-04 7:48 ` Paul Eggert @ 2002-04-05 15:33 ` Johan Danielsson 0 siblings, 0 replies; 6+ messages in thread From: Johan Danielsson @ 2002-04-05 15:33 UTC (permalink / raw) Paul Eggert <eggert@twinsun.com> writes: > I wonder whether Tru64 readv fails with errno==EINVAL if the sum of > the buffer lengths exceeds INT_MAX. There's a 64-bit "fixed" version of readv that you get automatically if you include the proper header. Why there isn't an equivalent for read is unknown to me. /Johan ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-04-05 15:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <200204012205.QAA0000012227@gskc01.stowers-institute.org>
[not found] ` <200204020013.g320DUf08044@shade.twinsun.com>
2002-04-02 9:44 ` read(fd, buf, N) fails when N doesn't fit in 32 bits? Paul Eggert
2002-04-02 13:15 ` Johan Danielsson
2002-04-02 13:42 ` Paul Eggert
2002-04-04 0:37 ` Bob Harris
2002-04-04 7:48 ` Paul Eggert
2002-04-05 15:33 ` Johan Danielsson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox