]> git.sur5r.net Git - cc65/commitdiff
Moved reusable parts of remove into oserrcheck.
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 12 Aug 2003 13:06:43 +0000 (13:06 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 12 Aug 2003 13:06:43 +0000 (13:06 +0000)
Rewrote remove().
Added rename().

git-svn-id: svn://svn.cc65.org/cc65/trunk@2272 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/Makefile
libsrc/common/oserrcheck.s [new file with mode: 0644]
libsrc/common/remove.s
libsrc/common/rename.s [new file with mode: 0644]

index 30db5df7ca871d4c2f196ec64f118dd26845b6fb..2c850d8b37e367d348fc19c1b9077897c65d8833 100644 (file)
@@ -109,9 +109,11 @@ S_OBJS =   _fdesc.o        \
                memset.o        \
                modfree.o       \
                modload.o       \
+                oserrcheck.o    \
                printf.o        \
                rand.o          \
                 raise.o         \
+                rename.o        \
                setjmp.o        \
                 signal.o        \
                 sigtable.o      \
diff --git a/libsrc/common/oserrcheck.s b/libsrc/common/oserrcheck.s
new file mode 100644 (file)
index 0000000..ba9ba7b
--- /dev/null
@@ -0,0 +1,35 @@
+;
+; Ullrich von Bassewitz, 2003-08-12
+;
+; Helper function for several high level file functions.
+;
+; The function will store the value in A into _oserror. If the value is not
+; zero, it is translated into a standard error number which is then stored
+; into errno, and -1 is returned in a/x. If the value in A was zero, errno
+; is not changed, and zero is returned in a/x.
+;
+
+        .export         oserrcheck
+        .import         __oserror
+        .import         __osmaperrno
+        .import         __errno
+
+.proc   oserrcheck
+
+        sta     __oserror               ; Store the error code
+        tay                             ; Did we have an error?
+        beq     ok                      ; Branch if no
+        jsr     __osmaperrno            ; Map os error into errno code
+        sta     __errno
+        stx     __errno+1               ; Save in errno
+        lda     #$FF                    ; Return -1
+
+; Error free, A contains zero
+
+ok:     tax                             ; Make high byte also zero
+        rts
+
+.endproc
+
+
index 1bda12474e0f5226d9a23fbd3a3584d567cfe3c5..3dba1146796e9dea4214e2bedc404318e8ab110a 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; Ullrich von Bassewitz, 16.11.2002
+; Ullrich von Bassewitz, 2003-08-12
 ;
 ; int __fastcall__ remove (const char* name);
 ;
@@ -7,36 +7,15 @@
         .export         _remove
 
         .import         __sysremove
-        .import         __osmaperrno
-        .import         __errno
+        .import         oserrcheck
 
 
 ;--------------------------------------------------------------------------
-; remove
-
 
 .proc   _remove
 
-; Go ahead and call the machine dependent function
-
-        jsr     __sysremove
-
-; Check for errors
-
-        cmp     #$00
-        bne     ok
-        jsr     __osmaperrno
-        sta     __errno
-        stx     __errno+1
-        lda     #$FF
-        tax
-        rts
-
-; Error free
-
-ok:     lda     #$00
-        tax
-        rts
+        jsr     __sysremove     ; Call the machine specific function
+        jmp     oserrcheck      ; Store into _oserror, set errno, return 0/-1
 
 .endproc
 
diff --git a/libsrc/common/rename.s b/libsrc/common/rename.s
new file mode 100644 (file)
index 0000000..8ef03fe
--- /dev/null
@@ -0,0 +1,24 @@
+;
+; Ullrich von Bassewitz, 2003-08-12
+;
+; int __fastcall__ rename (const char* oldname, const char* newname);
+;
+
+        .export         _rename
+
+        .import         __sysrename
+        .import         oserrcheck
+
+
+;--------------------------------------------------------------------------
+
+.proc   _rename
+
+        jsr     __sysrename     ; Call the machine specific function
+        jmp     oserrcheck      ; Store into _oserror, set errno, return 0/-1
+
+.endproc
+
+
+
+