proc strncpy dest, src, maxLength
push esi edi
mov edi, [dest]
mov esi, [src]
mov ecx, [maxLength]
test ecx, ecx
jz .exit
.storeChar:
lodsb
stosb
test al, al
jz .exit
.checkLength:
sub ecx, 1
jnc .storeChar
mov byte [edi-1], 0
.exit:
pop edi esi
ret
endp
That code is for strncpy, now if you just want to copy up to the file extention this could be a way:
proc removeExt buffer, fileName, bufferLength
push esi edi ebx
mov edi, [buffer]
mov esi, [fileName]
mov ecx, [bufferLength]
mov ebx, -1
test ecx, ecx
jz .return
.storeChar:
lodsb
stosb
test al, al
jz .exit
cmp al, '.'
jne .checkLength
mov ebx, esi
.checkLength:
sub ecx, 1
jnc .storeChar
mov byte [edi-1], 0
.exit:
cmp esi, ebx
jb .return
mov byte [ebx-1], 0
.return:
pop ebx edi esi
ret
endp
(Both codes untested, sorry, no time to check them)
[edit]I corrected the codes to ensure that the destination string will be null terminated (if the length is above 0)[/edit]