diff --git a/kernel/fcbfns.c b/kernel/fcbfns.c index 6942b13..0c71a95 100644 --- a/kernel/fcbfns.c +++ b/kernel/fcbfns.c @@ -337,19 +337,26 @@ void FcbCalcRec(xfcb FAR * lpXfcb) lpFcb->fcb_curec = lpFcb->fcb_rndm & 127; } -UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, COUNT nRecords, int mode) +UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, UWORD *nRecords, int mode) { - UCOUNT recno = 0; - UBYTE nErrorCode; + unsigned recno; + UBYTE nErrorCode = FCB_SUCCESS; FcbCalcRec(lpXfcb); /* Convert to fcb if necessary */ lpFcb = ExtFcbToFcb(lpXfcb); - do - nErrorCode = FcbReadWrite(lpXfcb, recno++, mode); - while ((--nRecords > 0) && (nErrorCode == 0)); + for (recno = 0; recno < *nRecords; recno++) + { + nErrorCode = FcbReadWrite(lpXfcb, recno, mode); + /* end-of-file, partial read should count last record */ + if (nErrorCode == FCB_ERR_EOF) + recno++; + if (nErrorCode != FCB_SUCCESS) + break; + } + *nRecords = recno; /* Now update the fcb */ lpFcb->fcb_rndm = FcbRec(); diff --git a/kernel/inthndlr.c b/kernel/inthndlr.c index 556ea69..1290538 100644 --- a/kernel/inthndlr.c +++ b/kernel/inthndlr.c @@ -658,12 +658,12 @@ dispatch: /* Read random record(s) using FCB */ case 0x27: - lr.AL = FcbRandomBlockIO(FP_DS_DX, lr.CX, XFR_READ); + lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_READ); break; /* Write random record(s) using FCB */ case 0x28: - lr.AL = FcbRandomBlockIO(FP_DS_DX, lr.CX, XFR_WRITE); + lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_WRITE); break; /* Parse File Name */ diff --git a/kernel/proto.h b/kernel/proto.h index c28c1ad..c82c76a 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -210,7 +210,7 @@ const BYTE FAR *GetNameField(const BYTE FAR * lpFileName, BYTE FAR * lpDestField UBYTE FcbReadWrite(xfcb FAR *, UCOUNT, int); UBYTE FcbGetFileSize(xfcb FAR * lpXfcb); void FcbSetRandom(xfcb FAR * lpXfcb); -UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, COUNT nRecords, int mode); +UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, UWORD *nRecords, int mode); UBYTE FcbRandomIO(xfcb FAR * lpXfcb, int mode); UBYTE FcbOpen(xfcb FAR * lpXfcb, unsigned flags); int FcbNameInit(fcb FAR * lpFcb, BYTE * pszBuffer, COUNT * pCurDrive);