The MASM Forum Archive 2004 to 2012

Specialised Projects => Pelle's Macro Assembler Development => Topic started by: Vortex on April 28, 2012, 10:02:38 AM

Title: Get file extension
Post by: Vortex on April 28, 2012, 10:02:38 AM
GetFileExtension finds the address of a file name. It returns the address of the string if there is no file extension.

EndOfStr, a modified version of the StrLen function determines the end of a NULL terminated string.


.386
.model flat,stdcall
option casemap:none

EndOfStr PROTO :DWORD

.code

GetFileExtension PROC USES esi edi pFileName:DWORD

    mov     esi,pFileName
    mov     edi,1
    invoke  EndOfStr,esi
    movzx   ecx,BYTE PTR [esi]
    mov     BYTE PTR [esi],'.'
@@:
    sub     eax,edi
    cmp     BYTE PTR [eax],'.'
    jne     @b
   
    mov     BYTE PTR [esi],cl
    ret

GetFileExtension ENDP

END