THINK C4 stdio gotchas

Johnny LEE t-jlee at microsoft.UUCP
Fri May 25 14:16:43 AEST 1990


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 at microsoft.UUCP
...!uunet!microsoft!t-jlee



More information about the Comp.lang.c mailing list