Modify file error to match real cat
This commit is contained in:
+15
-15
@@ -68,19 +68,19 @@ open_fd:
|
||||
2:
|
||||
ret
|
||||
|
||||
# Check if the given file exists without opening fd
|
||||
# @param[in] a0: ptr to null-terminated file str.
|
||||
# @param[out] a0: result code (0-exists 1-doesn't exist).
|
||||
file_exists:
|
||||
mv a1, a0
|
||||
li a0, -100 # relative/absolute path
|
||||
li a2, 0
|
||||
li a7, 48
|
||||
ecall
|
||||
beqz a0, 1f
|
||||
li a0, 1
|
||||
ret
|
||||
# # Check if the given file exists without opening fd
|
||||
# # @param[in] a0: ptr to null-terminated file str.
|
||||
# # @param[out] a0: result code (0-exists 1-doesn't exist).
|
||||
# file_exists:
|
||||
# mv a1, a0
|
||||
# li a0, -100 # relative/absolute path
|
||||
# li a2, 0
|
||||
# li a7, 48
|
||||
# ecall
|
||||
# beqz a0, 1f
|
||||
# li a0, 1
|
||||
# ret
|
||||
|
||||
1:
|
||||
li a0, 0
|
||||
ret
|
||||
# 1:
|
||||
# li a0, 0
|
||||
# ret
|
||||
|
||||
+23
-15
@@ -1,9 +1,11 @@
|
||||
.data
|
||||
argc: .space 8
|
||||
file_err: .asciz "File not found or cannot be accessed: "
|
||||
|
||||
cat_prefix: .asciz "cat: "
|
||||
.equ CAT_PREFIX_LEN, . - cat_prefix
|
||||
file_err: .asciz ": No such file or directory\n"
|
||||
.equ FILE_ERR_LEN, . - file_err
|
||||
|
||||
|
||||
.section .text
|
||||
.globl _start
|
||||
|
||||
@@ -20,17 +22,17 @@ _start:
|
||||
mv s0, a1 # store argc
|
||||
li s1, 1
|
||||
|
||||
5: #iterate through and check that all files exist first
|
||||
mv a0, s1
|
||||
call fetch_argv
|
||||
bnez a0, 1f # error if failed
|
||||
mv a0, a1
|
||||
call file_exists
|
||||
bnez a0, 4f
|
||||
addi s1, s1, 1
|
||||
blt s1, s0, 5b
|
||||
# 5: #iterate through and check that all files exist first
|
||||
# mv a0, s1
|
||||
# call fetch_argv
|
||||
# bnez a0, 1f # error if failed
|
||||
# mv a0, a1
|
||||
# call file_exists
|
||||
# bnez a0, 4f
|
||||
# addi s1, s1, 1
|
||||
# blt s1, s0, 5b
|
||||
|
||||
li s1, 1 # reset counter now that we've verified all files exist, skip command
|
||||
# li s1, 1 # reset counter now that we've verified all files exist, skip command
|
||||
|
||||
3:
|
||||
mv a0, s1
|
||||
@@ -45,12 +47,11 @@ _start:
|
||||
|
||||
4:
|
||||
li a0, 1
|
||||
la a1, file_err
|
||||
li a2, FILE_ERR_LEN
|
||||
la a1, cat_prefix
|
||||
li a2, CAT_PREFIX_LEN
|
||||
li a7, 64
|
||||
ecall
|
||||
|
||||
li t0, 1
|
||||
mv a0, s1
|
||||
call fetch_argv
|
||||
|
||||
@@ -58,6 +59,13 @@ _start:
|
||||
li a7, 64
|
||||
ecall
|
||||
|
||||
li a0, 1
|
||||
la a1, file_err
|
||||
li a2, FILE_ERR_LEN
|
||||
li a7, 64
|
||||
ecall
|
||||
|
||||
|
||||
1:
|
||||
li a0, 1
|
||||
li a7, 93
|
||||
|
||||
Reference in New Issue
Block a user