qa.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
UniqueFile
   Example  Back  Contents  Index
──────────────────────────────────────────────────────────────────────────────
 
;* UniqueFile - Creates and opens a new file with a name unique to the
;* specified directory. The name is manufactured from the current time,
;* making it useful for temporary files. For DOS versions 3.0 and higher.
;*
;* Shows:   DOS Function - 5Ah (Create Temporary File)
;*
;* Params:  attr - Attribute code (see header comments for CreateFile)
;*          fspec - Pointer to ASCIIZ path specification
;*
;* Return:  Short integer with file handle or -1 for error
 
UniqueFile PROC \
        USES ds, \
        attr:WORD, pspec:PTR BYTE
 
        call    GetVer                  ; Get DOS version
        cmp     ax, 300                 ; 3.0 or higher?
        jb      e_exit                  ; No?  Quit with error
        LoadPtr ds, dx, pspec           ; Point DS:DX to path spec
        mov     cx, attr                ; CX = attribute
        mov     ah, 5Ah                 ; AH = function number
        int     21h                     ; Create Temporary File
        jnc     exit                    ; Return AX = handle if ok
e_exit: mov     ax, -1                  ; Else set error code
exit:   ret
 
UniqueFile ENDP
                                    -♦-