Skip to content

Commit

Permalink
2.36.08
Browse files Browse the repository at this point in the history
  • Loading branch information
nidud committed Dec 3, 2024
1 parent 764fc59 commit cb1b085
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 14 deletions.
4 changes: 4 additions & 0 deletions include/stdlib.inc
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ _rotr64 proto watcall :uint64_t, :abs {
}
endif

_getpath proto __cdecl :string_t, :string_t, :size_t
_searchenv proto __cdecl :string_t, :string_t, :string_t
_searchenv_s proto __cdecl :string_t, :string_t, :string_t, :size_t
_splitpath proto __cdecl :string_t, :string_t, :string_t, :string_t, :string_t
_splitpath_s proto __cdecl :string_t, :string_t, :size_t, :string_t, :size_t, :string_t, :size_t, :string_t, :size_t
Expand All @@ -590,6 +592,8 @@ _wperror proto __cdecl :wstring_t
endif
_wputenv proto __cdecl :wstring_t
_wputenv_s proto __cdecl :wstring_t, :wstring_t
_wgetpath proto __cdecl :wstring_t, :wstring_t, :size_t
_wsearchenv proto __cdecl :wstring_t, :wstring_t, :wstring_t
_wsearchenv_s proto __cdecl :wstring_t, :wstring_t, :wstring_t, :size_t

_wsplitpath proto __cdecl :wstring_t, :wstring_t, :wstring_t, :wstring_t, :wstring_t
Expand Down
4 changes: 4 additions & 0 deletions include/tchar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ define _tgetfattr <_wgetfattr>
define _tsetfattr <_wsetfattr>
define _tfilexist <_wfilexist>

define _tgetpath <_wgetpath>

define _TEOF WEOF

_tmain equ <wmain>
Expand Down Expand Up @@ -742,6 +744,8 @@ define _tgetfattr <getfattr>
define _tsetfattr <setfattr>
define _tfilexist <filexist>

define _tgetpath <_getpath>

define _TEOF EOF

_tmain equ <main>
Expand Down
24 changes: 12 additions & 12 deletions source/libc/stdlib/_tgetenv.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _tgetenv proc uses rbx enval:LPTSTR
.new len:int_t

.ifd ( _tcsclen( ldr(enval) ) == 0 )
.return
.return
.endif

mov len,eax
Expand All @@ -24,20 +24,20 @@ _tgetenv proc uses rbx enval:LPTSTR

.while ( rax )

.ifd ( !_tcsncicmp( rax, enval, len ) )
.ifd ( !_tcsncicmp( rax, enval, len ) )

mov eax,len
mov eax,len
ifdef _UNICODE
add eax,eax
add eax,eax
endif
add rax,[rbx]

.if ( TCHAR ptr [rax] == '=' )
.return( &[rax+TCHAR] )
.endif
.endif
add rbx,LPTSTR
mov rax,[rbx]
add rax,[rbx]

.if ( TCHAR ptr [rax] == '=' )
.return( &[rax+TCHAR] )
.endif
.endif
add rbx,LPTSTR
mov rax,[rbx]
.endw
ret

Expand Down
96 changes: 96 additions & 0 deletions source/libc/stdlib/_tgetpath.asm
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
196 changes: 196 additions & 0 deletions source/libc/stdlib/_tsearchenv.asm
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
4 changes: 2 additions & 2 deletions source/libc/string/_tcscpy_s.asm
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ ifdef _WIN64
endif
mov [rcx],[rdx]
.0:
dec rbx
jz .4
test eax,eax
jz .1
dec rbx
jz .4
add rcx,TCHAR
add rdx,TCHAR
mov [rcx],[rdx]
Expand Down
Loading

0 comments on commit cb1b085

Please sign in to comment.