2003-08-12 13:51:11 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-08-12
|
|
|
|
;
|
|
|
|
; char* __fastcall__ getcwd (char* buf, size_t size);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _getcwd
|
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
.import popptr1
|
2003-08-12 13:51:11 +00:00
|
|
|
.import __cwd
|
|
|
|
.importzp ptr1, ptr2
|
|
|
|
|
|
|
|
.include "errno.inc"
|
|
|
|
|
|
|
|
|
|
|
|
;--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.proc _getcwd
|
|
|
|
|
2020-10-25 13:27:26 +00:00
|
|
|
; Remember size with each byte incremented because this simplifies the following loop
|
2003-08-12 13:51:11 +00:00
|
|
|
|
2020-10-25 13:27:26 +00:00
|
|
|
inx
|
|
|
|
stx ptr2+1
|
|
|
|
tax
|
|
|
|
inx
|
2020-10-27 05:08:04 +00:00
|
|
|
stx ptr2 ; Save size with each byte incremented separately
|
2003-08-12 13:51:11 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; Get buf to ptr1
|
2003-08-12 13:51:11 +00:00
|
|
|
|
|
|
|
; Copy __cwd to the given buffer checking the length
|
|
|
|
|
2018-05-21 12:41:12 +00:00
|
|
|
; ldy #$00 is guaranteed by popptr1
|
2020-10-25 13:27:26 +00:00
|
|
|
loop: dec ptr2
|
2003-08-12 13:51:11 +00:00
|
|
|
bne @L1
|
2020-10-25 13:27:26 +00:00
|
|
|
dec ptr2+1
|
2003-08-12 13:51:11 +00:00
|
|
|
beq overflow
|
|
|
|
|
2003-08-12 13:58:17 +00:00
|
|
|
; Copy one character, end the loop if the zero terminator is reached. We
|
|
|
|
; don't support directories longer than 255 characters for now.
|
2003-08-12 13:51:11 +00:00
|
|
|
|
|
|
|
@L1: lda __cwd,y
|
|
|
|
sta (ptr1),y
|
2003-08-12 13:58:17 +00:00
|
|
|
beq done
|
|
|
|
iny
|
2003-08-12 13:51:11 +00:00
|
|
|
bne loop
|
|
|
|
|
2003-08-12 13:58:17 +00:00
|
|
|
; For some reason the cwd is longer than 255 characters. This should not
|
|
|
|
; happen, we handle it as if the passed buffer was too short.
|
|
|
|
;
|
2003-08-12 13:51:11 +00:00
|
|
|
; String overflow, return ERANGE
|
|
|
|
|
|
|
|
overflow:
|
|
|
|
lda #<ERANGE
|
2010-06-03 21:29:28 +00:00
|
|
|
jsr __seterrno ; Returns 0 in A
|
|
|
|
tax ; Return zero
|
|
|
|
rts
|
|
|
|
|
2003-08-12 13:58:17 +00:00
|
|
|
; Success, return buf
|
|
|
|
|
|
|
|
done: lda ptr1
|
|
|
|
ldx ptr1+1
|
2003-08-12 13:51:11 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|