t-jlee@microsoft.UUCP (Johnny LEE) (05/25/90)
While porting GNU Diff to the Mac in my spare time, I came upon an anomaly in the stdio and unix libraries for THINK C4. In K&R 2Ed, fread and read are defined as: size_t fread(void *ptr, size_t size, size_t nobj, FILE *stream); int read (int fd, char *buf, int n); THINK C has size_t as an unsigned long and int read (int fd, char *buf, unsigned int n); So the number of chars you can request and the number returned as read won't be equal for values>32767. In fact, you can request 65535 (or is it 32768?) and if you get all 65535 chars, your return value will look like an EOF. Makes read() kinda limited. 'Tis fun porting stuff which assumes int==long. Fun... WOW. Standard Disclaimer. Johnny Lee t-jlee@microsoft.UUCP ...!uunet!microsoft!t-jlee
karl@haddock.ima.isc.com (Karl Heuer) (05/27/90)
In article <54861@microsoft.UUCP> t-jlee@microsoft.UUCP (Johnny LEE) writes: >THINK C has size_t as an unsigned long and > int read (int fd, char *buf, unsigned int n); >So the number of chars you can request and the number returned as read >won't be equal for values>32767. >In fact, you can request 65535 (or is it 32768?) and if you get >all 65535 chars, your return value will look like an EOF. Actually a read error rather than an EOF. Use of errno can disambiguate this case. >Makes read() kinda limited. Yes. The correct hack is for such implementations to supply a separate function, perhaps named lread(), that does the right thing. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint Followups to comp.lang.c only.