CheckFile
Synopsis
error = CheckFile(filename, buffer)
D0 A0 A1C Prototype
LONG CheckFile(STRPTR filename, STRPTR errorstring);Description
Allows checking the status of a file. The file is opened in MODE_OLDFILE; if everything is fine, it returns NULL as the result. Otherwise, it returns the error code from dos.library/IoErr().
In addition to returning the error code, CheckFile() can also provide an associated error text by calling dos.library/Fault(). This is done by providing a buffer, which will be filled with the text of the associated error. However, you should always refer to the return error code to determine whether an error actually occurred.
The buffer pointer must be at least 80 characters long. The string will be NULL-terminated. The buffer pointer is not mandatory; if left as zero, it has no effect, and it will be the task’s responsibility to display the error as text.
The error text is linked to the system LOCALE, so the error string is in the language chosen in the system preferences.
Inputs
- filename — Pointer to a string containing the path and name of the file to check.
- buffer — OPTIONAL parameter. Address of a buffer, minimum 80 characters, that will contain the string describing the error in the system language.
Result
- error — NULL if no error occurred. Otherwise, an error code is returned via
dos.library/IoErr().
See Also
dos.library/IoErr(), dos.library/Fault(), dos.library/PrintFault()
Implementation
The original 68020 assembly implementation:
; (02-Mar-1995) --- error = CheckFile(filename,buffer) (a0/a1)
_LVOCheckFile
movem.l d2-d6/a6,-(sp)
move.l a1,d6 ; Save Buffer
move.l ab_DosBase(a6),a6
move.l a0,d1
lea MODE_OLDFILE.W,A0
move.l a0,d2
jsr _LVOOpen(a6)
tst.l d0
bne.s CK_CLO
jsr _LVOIoErr(a6)
move.l d0,d5
CKGOERR move.l d6,d3 ; output buffer
beq.s CK_NTX
move.l d5,d1 ; Error code
moveq #0,d2 ; header buffer null
moveq #80,d4
jsr _LVOFault(a6)
move.l d5,d0
CK_NTX movem.l (sp)+,d2-d6/a6
rts
CK_CLO move.l d0,d1
jsr _LVOClose(a6)
moveq #0,d0
movem.l (sp)+,d2-d6/a6
rts