From 109befa1e4b0e63230b61c78dca11f001cc1afc1 Mon Sep 17 00:00:00 2001 From: turbocat Date: Sun, 29 Aug 2021 18:27:24 +0000 Subject: [PATCH] libc.obj: - fixed fread bug git-svn-id: svn://kolibrios.org@9165 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/include/sys/ksys.h | 12 ++----- .../ktcc/trunk/libc.obj/source/stdio/fread.c | 32 +++++++++---------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h index 4b844b398..2b33facc0 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h @@ -1304,16 +1304,12 @@ int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned s k.p20 = 0; k.p21 = name; int status; - unsigned bytes_read_v; asm_inline( "int $0x40" - :"=a"(status), "=b"(bytes_read_v) + :"=a"(status), "=b"(*bytes_read) :"a"(70), "b"(&k) :"memory" ); - if (!status) { - *bytes_read = bytes_read_v; - } return status; } @@ -1343,16 +1339,12 @@ int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned k.p20 = 0; k.p21 = name; int status; - unsigned bytes_written_v; asm_inline( "int $0x40" - :"=a"(status), "=b"(bytes_written_v) + :"=a"(status), "=b"(*bytes_written) :"a"(70), "b"(&k) :"memory" ); - if (!status) { - *bytes_written = bytes_written_v; - } return status; } diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c b/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c index 6010ad123..be28b9398 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c @@ -24,24 +24,22 @@ size_t fread(void *restrict ptr, size_t size, size_t nmemb, FILE *restrict strea return nmemb; } - else{ - if(stream->mode & _FILEMODE_R){ - if(!stream->__ungetc_emu_buff){ - ((char*) ptr)[0]=(char)stream->__ungetc_emu_buff; - //debug_printf("Ungetc: %x\n", ((char*) ptr)[0]); - } - unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read); - if (status != KSYS_FS_ERR_SUCCESS) { - if(status == KSYS_FS_ERR_EOF){ - stream->eof=1; - }else{ - errno = EIO; - stream->error = errno; - return 0; - } - } - stream->position+=bytes_read; + if(stream->mode & _FILEMODE_R){ + if(!stream->__ungetc_emu_buff){ + ((char*) ptr)[0]=(char)stream->__ungetc_emu_buff; + //debug_printf("Ungetc: %x\n", ((char*) ptr)[0]); } + unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read); + if (status != KSYS_FS_ERR_SUCCESS) { + if(status == KSYS_FS_ERR_EOF){ + stream->eof=1; + }else{ + errno = EIO; + stream->error = errno; + return 0; + } + } + stream->position+=bytes_read; } return bytes_read/size; }