-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
451 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
; _TGETPATH.ASM-- | ||
; | ||
; Copyright (c) The Asmc Contributors. All rights reserved. | ||
; Consult your license regarding permissions and restrictions. | ||
; | ||
|
||
include stdlib.inc | ||
include errno.inc | ||
include tchar.inc | ||
ifdef __UNIX__ | ||
define DELIM ':' | ||
else | ||
define DELIM ';' | ||
endif | ||
|
||
define _HPFS_ | ||
|
||
.code | ||
|
||
assume rbx:tstring_t | ||
|
||
_tgetpath proc uses rbx src:tstring_t, dst:tstring_t, maxlen:size_t | ||
|
||
ldr rbx,src | ||
ldr rcx,maxlen | ||
ldr rdx,dst | ||
|
||
.while ( [rbx] == DELIM ) | ||
add rbx,TCHAR | ||
.endw | ||
mov src,rbx | ||
dec rcx | ||
jz error | ||
|
||
.while ( [rbx] && [rbx] != DELIM ) | ||
|
||
ifdef _HPFS_ | ||
|
||
.if ( [rbx] != '"' ) | ||
|
||
mov _tal,[rbx] | ||
mov [rdx],_tal | ||
add rdx,TCHAR | ||
add rbx,TCHAR | ||
dec rcx | ||
jz error | ||
|
||
.else | ||
|
||
add rbx,TCHAR | ||
.while ( [rbx] && [rbx] != '"' ) | ||
|
||
mov _tal,[rbx] | ||
mov [rdx],_tal | ||
add rdx,TCHAR | ||
add rbx,TCHAR | ||
dec rcx | ||
jz error | ||
.endw | ||
.if ( [rbx] ) | ||
add rbx,TCHAR | ||
.endif | ||
.endif | ||
|
||
else | ||
mov _tal,[rbx] | ||
mov [rdx],_tal | ||
add rdx,TCHAR | ||
add rbx,TCHAR | ||
dec rcx | ||
jz error | ||
endif | ||
.endw | ||
|
||
.while ( [rbx] == DELIM ) | ||
add rbx,TCHAR | ||
.endw | ||
|
||
appendnull: | ||
xor eax,eax | ||
mov [rdx],_tal | ||
.if ( rbx != src ) | ||
mov rax,rbx | ||
.endif | ||
ret | ||
|
||
error: | ||
mov src,rbx | ||
mov dst,rdx | ||
_set_errno(ERANGE) | ||
mov rdx,dst | ||
jmp appendnull | ||
|
||
_tgetpath endp | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
; _TSEARCHENV.ASM-- | ||
; | ||
; Copyright (c) The Asmc Contributors. All rights reserved. | ||
; Consult your license regarding permissions and restrictions. | ||
; | ||
|
||
include stdlib.inc | ||
include io.inc | ||
include errno.inc | ||
include string.inc | ||
include malloc.inc | ||
include tchar.inc | ||
|
||
.code | ||
|
||
_tsearchenv_s proc uses rbx fname:LPTSTR, env_var:LPTSTR, path:LPTSTR, size:size_t | ||
|
||
.new p:LPTSTR | ||
.new envbuf:LPTSTR = NULL | ||
.new env_p:LPTSTR | ||
.new save_env_p:LPTSTR | ||
.new len:size_t | ||
.new pathbuf[_MAX_PATH + 4]:TCHAR | ||
.new pbuf:LPTSTR = NULL | ||
.new fnamelen:size_t | ||
.new buflen:size_t | ||
.new save_errno:errno_t | ||
.new acc:int_t | ||
.new retvalue:errno_t = 0 | ||
|
||
ldr rbx,path | ||
ldr rax,size | ||
.if ( !rax || !rbx ) | ||
|
||
_set_errno(EINVAL) | ||
.return( EINVAL ) | ||
.endif | ||
|
||
ldr rcx,fname | ||
.if ( !rcx ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
_set_errno(EINVAL) | ||
.return( EINVAL ) | ||
.endif | ||
|
||
.if ( TCHAR ptr [rcx] == 0 ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
_set_errno(ENOENT) | ||
.return( ENOENT ) | ||
.endif | ||
|
||
_get_errno(&save_errno) | ||
mov acc,_taccess(fname, 0) | ||
_set_errno(save_errno) | ||
|
||
.if ( acc == 0 ) | ||
|
||
.if ( _tfullpath(rbx, fname, size) == NULL ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
.return( _get_errno( NULL ) ) | ||
.endif | ||
.return( 0 ) | ||
.endif | ||
|
||
.if ( _tdupenv_s(&envbuf, NULL, env_var) || envbuf == NULL ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
_set_errno(ENOENT) | ||
.return( ENOENT ) | ||
.endif | ||
|
||
mov env_p,envbuf | ||
mov fnamelen,_tcslen(fname) | ||
mov pbuf,&pathbuf | ||
mov buflen,_countof(pathbuf) | ||
|
||
.if ( fnamelen >= buflen ) | ||
|
||
_tcslen(env_p) | ||
add rax,fnamelen | ||
add rax,2 | ||
mov buflen,rax | ||
mov pbuf,calloc( buflen, sizeof(TCHAR) ) | ||
|
||
.if ( rax == NULL ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
mov retvalue,ENOMEM | ||
jmp cleanup | ||
.endif | ||
.endif | ||
_get_errno(&save_errno) | ||
|
||
.while ( env_p ) | ||
|
||
mov save_env_p,env_p | ||
mov rcx,buflen | ||
sub rcx,fnamelen | ||
dec rcx | ||
mov env_p,_tgetpath(env_p, pbuf, rcx) | ||
mov ecx,_get_errno( NULL ) | ||
lea rax,pathbuf | ||
.if ( env_p == NULL && rax == pbuf && ecx == ERANGE ) | ||
|
||
_tcslen(save_env_p) | ||
add rax,fnamelen | ||
add rax,2 | ||
mov buflen,rax | ||
mov pbuf,calloc( buflen, sizeof(TCHAR) ) | ||
|
||
.if ( rax == NULL ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
mov retvalue,ENOMEM | ||
jmp cleanup | ||
.endif | ||
mov rcx,buflen | ||
sub rcx,fnamelen | ||
mov env_p,_tgetpath(save_env_p, pbuf, rcx) | ||
.endif | ||
|
||
mov rcx,pbuf | ||
.if ( env_p == NULL || TCHAR ptr [rcx] == 0 ) | ||
.break | ||
.endif | ||
|
||
mov rcx,_tcslen(pbuf) | ||
ifdef _UNICODE | ||
add rax,rax | ||
endif | ||
add rax,pbuf | ||
mov _tdl,[rax-TCHAR] | ||
ifdef __UNIX__ | ||
.if ( _tdl != '/' ) | ||
mov _tdl,'/' | ||
else | ||
.if ( _tdl != '/' && _tdl != '\' && _tdl != ':' ) | ||
mov _tdl,'\' | ||
endif | ||
mov [rax],_tdl | ||
add rax,TCHAR | ||
inc rcx | ||
.endif | ||
mov len,rcx | ||
mov p,rax | ||
sub rax,pbuf | ||
mov rcx,buflen | ||
sub rcx,rax | ||
|
||
.break .ifd _tcscpy_s(p, rcx, fname) | ||
|
||
.ifd ( _taccess(pbuf, 0) == 0 ) | ||
|
||
mov rax,len | ||
add rax,fnamelen | ||
.if ( rax >= size ) | ||
|
||
mov TCHAR ptr [rbx],0 | ||
_set_errno(ERANGE) | ||
mov retvalue,ERANGE | ||
jmp cleanup | ||
.endif | ||
_set_errno(save_errno) | ||
.break .ifd _tcscpy_s(path, size, pbuf) | ||
mov retvalue,0 | ||
jmp cleanup | ||
.endif | ||
.endw | ||
|
||
mov TCHAR ptr [rbx],0 | ||
_set_errno(ENOENT) | ||
mov retvalue,ENOENT | ||
|
||
cleanup: | ||
lea rax,pathbuf | ||
.if ( rax != pbuf ) | ||
free(pbuf) | ||
.endif | ||
free(envbuf) | ||
mov eax,retvalue | ||
ret | ||
|
||
_tsearchenv_s endp | ||
|
||
|
||
_tsearchenv proc fname:LPTSTR, env_var:LPTSTR, path:LPTSTR | ||
|
||
_tsearchenv_s(ldr(fname), ldr(env_var), ldr(path), _MAX_PATH) | ||
ret | ||
|
||
_tsearchenv endp | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.