1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 15:29:46 +00:00

Add support for append mode

git-svn-id: svn://svn.cc65.org/cc65/trunk@1542 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-11-19 14:27:06 +00:00
parent ca905a8705
commit b2a06ab041
2 changed files with 18 additions and 24 deletions

View File

@ -85,13 +85,13 @@ namecheck:
bpl namecheck bpl namecheck
tax tax
lda __ctype,x lda __ctype,x
and #(CT_LOWER|CT_DIGIT) and #CT_ALNUM
beq invalidname beq invalidname
; Check the maximum length, store the character ; Check the maximum length, store the character
nameok: ldx fnlen nameok: ldx fnlen
cpx #14 ; Maximum length reached? cpx #16 ; Maximum length reached?
bcs invalidname bcs invalidname
lda (ptr1),y ; Reload char lda (ptr1),y ; Reload char
sta fnbuf,x ; Store into buffer sta fnbuf,x ; Store into buffer
@ -159,7 +159,7 @@ fnlen: .res 1
.data .data
fncmd: .byte 's' ; Use as scratch command fncmd: .byte 's' ; Use as scratch command
fnbuf: .res 20 fnbuf: .res 22 ; 0:0123456789012345,t,m
.rodata .rodata
; Characters that are ok in filenames besides digits and letters ; Characters that are ok in filenames besides digits and letters

View File

@ -50,26 +50,15 @@ parmok: jsr popax ; Get flags
bcs nofile bcs nofile
stx tmp2 stx tmp2
; Check the flags. We cannot have: ; Check the flags. We cannot have both, read and write flags set, and we cannot
; ; open a file for writing without creating it.
; - both, read and write flags set
; - the append flag set
;
lda tmp3 lda tmp3
and #O_RDWR and #(O_RDWR | O_CREAT)
beq invflags ; Neither read nor write cmp #O_RDONLY ; Open for reading?
cmp #O_RDWR beq doread ; Yes: Branch
beq invflags ; Jump if both set cmp #(O_WRONLY | O_CREAT) ; Open for writing?
cmp #O_RDONLY bne invflags ; No: Invalid open mode
beq doread
; Write bit is set. We cannot open a file for writing without creating it,
; so check for the O_CREAT bit.
lda tmp3
and #O_CREAT
beq invflags
; If O_TRUNC is set, scratch the file, but ignore any errors ; If O_TRUNC is set, scratch the file, but ignore any errors
@ -78,10 +67,15 @@ parmok: jsr popax ; Get flags
beq notrunc beq notrunc
jsr scratch jsr scratch
; Complete the the file name ; Complete the the file name. Check for append mode here.
notrunc: notrunc:
lda #'w' lda tmp3 ; Get the mode again
ldx #'a'
and #O_APPEND ; Append mode?
bne append ; Branch if yes
ldx #'w'
append: txa
jsr fncomplete jsr fncomplete
; Setup the real open flags ; Setup the real open flags