X-Git-Url: https://git.danieliu.xyz/?p=sped.git;a=blobdiff_plain;f=fileutils.asm;h=54c989534f86bebb62aac83c79b8ee3f2f93dbd2;hp=6c30ca61658fa6f2e9ff68b2160ae4f31c3dd8d5;hb=0e7c787c5d6e31bd64fb9348c1cc4704d5b5928e;hpb=6cf67300c03d92a9cc0c5888b33cdb21a852eb69 diff --git a/fileutils.asm b/fileutils.asm index 6c30ca6..54c9895 100644 --- a/fileutils.asm +++ b/fileutils.asm @@ -14,6 +14,7 @@ global writeFile section .data wrongfile_str db `unable to open file, error code: %i\n`, 0x00 + returnvalue_str db `system call return was %i\n`, 0x00 section .text @@ -62,13 +63,13 @@ readFile: push DWORD [ebp-FILE_HANDLE] call readLine - mov esi, eax mov [ebp-IS_EOF], ebx ; check if eof was reached cmp DWORD [ebp-IS_EOF], 1 je _readFile_exit + ; push esi ; call printf @@ -233,11 +234,13 @@ writeFile: ; check if file was open successfully cmp eax, 0 - jge _writeFile_loop - push eax - push wrongfile_str - call printf - jmp _writeFile_exit + jl _writeFile_error + + ; truncate file + mov eax, 93 + mov ebx, [ebp-FILE_HANDLE] + mov ecx, 1 + int 0x80 _writeFile_loop: @@ -262,6 +265,12 @@ writeFile: jmp _writeFile_loop + _writeFile_error: + push eax + push wrongfile_str + call printf + jmp _writeFile_exit + _writeFile_exit: ; close file