>On Thu, 9 Mar 2000, Per Mildner wrote:
>
>> However, the "OS may strip CR characters"-branch of the code will,
>> incorrectly, fail if the number of bytes read is actually exactly the
>> same as the size reported by the system. This happens for some files
>> under cygwin.
>
>It is this case that I don't understand. What's more, I don't understand
>how calling xrealloc ``fixes'' that problem, especially if realloc is
>smart and doesn't do anything in that case.
The fix is not that xrealloc is called. The fix is that the else-part
is *not* called. The fact that xrealloc is called instead is just
harmless.
The original code stripped of ifdefs looks like:
while ((n = read (file, result + count, file_size)) > 0)
count += n;
if (0 < count && count < file_size)
result = xrealloc (result, count + 2);
else if (n == -1)
<<ERROR>>
The problem with this is that if count is equal to file_size then the
<<ERROR>> code is used. My fix makes sure that the xrealloc case is
used instead which is a no-op when count equals file_size. As I said
it would be possible to special case this to avoid the call to
xrealloc but that is only worth it if xrealloc is doing something
stupid when it is asked to realloc something to a size it already has.
--
Per Mildner, PhD [EMAIL PROTECTED]
Swedish Institute of Computer Science