- spare = (size_t)(stream->endbuf - stream->upto);
- if (towrite < spare)
- {
- memcpy(stream->upto, ptr, towrite);
- *actualWritten = towrite;
- stream->upto += towrite;
- return;
- }
- memcpy(stream->upto, ptr, spare);
-#ifdef __OS2__
- rc = DosWrite(stream->hfile,
- stream->fbuf,
- stream->szfbuf,
- &tempWritten);
- if (rc != 0)
- {
- stream->errorInd = 1;
- errno = rc;
- return;
- }
-#endif
-#ifdef __MSDOS__
- tempWritten = __write(stream->hfile,
- stream->fbuf,
- stream->szfbuf,
- &errind);
- if (errind)
- {
- stream->errorInd = 1;
- errno = tempWritten;
- return;
- }
-#endif
- *actualWritten = spare;
- stream->upto = stream->fbuf;
- stream->bufStartR += tempWritten;
- if (towrite > stream->szfbuf)
- {
- stream->quickBin = 1;
-#ifdef __OS2__
- rc = DosWrite(stream->hfile,
- (char *)ptr + *actualWritten,
- towrite - *actualWritten,
- &tempWritten);
- if (rc != 0)
- {
- stream->errorInd = 1;
- errno = rc;
- return;
- }
-#endif
-#ifdef __MSDOS__
- tempWritten = __write(stream->hfile,
- (char *)ptr + *actualWritten,
- towrite - *actualWritten,
- &errind);
- if (errind)
- {
- stream->errorInd = 1;
- errno = tempWritten;
- return;
- }
-#endif
- *actualWritten += tempWritten;
- stream->bufStartR += tempWritten;
- }
- else
- {
- memcpy(stream->fbuf,
- (char *)ptr + *actualWritten,
- towrite - *actualWritten);
- stream->upto += (towrite - *actualWritten);
- *actualWritten = towrite;
- }
- stream->bufStartR += *actualWritten;
- return;