From 6fe5395074c753b3915db9c3ca9da544249d5593 Mon Sep 17 00:00:00 2001 From: faissaloo Date: Thu, 14 Jul 2016 22:17:44 +0100 Subject: Added error message for invalid cd attempts --- sh | Bin 4448 -> 4576 bytes sh.asm | 13 +++++++++++-- sh.o | Bin 4784 -> 4928 bytes 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sh b/sh index 80f47f7..42f7bed 100755 Binary files a/sh and b/sh differ diff --git a/sh.asm b/sh.asm index a239844..81c7977 100644 --- a/sh.asm +++ b/sh.asm @@ -7,7 +7,9 @@ section .data nfe: db "Error: program not found", 0x2e, `\n` env: db "/etc/environment", 0x0 boem: db "Error: input overflows buffer", 0x2e, `\n` - invalid_int_str: db "Error: Invalid integer",`\n` + no_dir_str: db "cd: Unknown directory",`\n` + no_dir_str_len: equ $-no_dir_str + invalid_int_str: db "exit: Invalid integer",`\n` invalid_int_str_len: equ $-invalid_int_str ;Flag indicating ability to execute X_OK equ 0x1 @@ -431,12 +433,19 @@ _quit: xor rdi, rdi syscall -;cd [dir] +;cd [dir (rax)] ;changes to the given directory _builtin_cd: mov rdi,rax mov rax, sys_chdir syscall + cmp rax, 0 + jz _read_loop + mov rax, sys_write + mov rdi, 0x1 + mov rsi, no_dir_str + mov rdx, no_dir_str_len + syscall jmp _read_loop ;usage: exit [status] ;exits with the given status or 0 if one hasn't been provided diff --git a/sh.o b/sh.o index ebf5bca..d5ee55b 100644 Binary files a/sh.o and b/sh.o differ -- cgit v1.2.3