From b141c632007adea4d6418fdb5115e1aaa3a600cc Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sun, 13 Mar 2016 00:52:58 +0000 Subject: [PATCH] newlib: fixed error handling in write() git-svn-id: svn://kolibrios.org@6330 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../sdk/sources/newlib/libc/include/ctype.h | 5 ++- contrib/sdk/sources/newlib/libc/sys/iowrite.c | 45 ++++++++++--------- contrib/sdk/sources/newlib/libc/sys/write.c | 3 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/contrib/sdk/sources/newlib/libc/include/ctype.h b/contrib/sdk/sources/newlib/libc/include/ctype.h index 969d3ef1f3..9bd69c9c1c 100644 --- a/contrib/sdk/sources/newlib/libc/include/ctype.h +++ b/contrib/sdk/sources/newlib/libc/include/ctype.h @@ -40,9 +40,10 @@ int _EXFUN(toascii, (int __c)); #define _B 0200 #ifndef _MB_CAPABLE -_CONST +extern _CONST __IMPORT char *__ctype_ptr__; +#else +extern __IMPORT char *__ctype_ptr__; #endif -extern __IMPORT char *__ctype_ptr__; #ifndef __cplusplus /* These macros are intentionally written in a manner that will trigger diff --git a/contrib/sdk/sources/newlib/libc/sys/iowrite.c b/contrib/sdk/sources/newlib/libc/sys/iowrite.c index a92814f452..c82ae86c7a 100644 --- a/contrib/sdk/sources/newlib/libc/sys/iowrite.c +++ b/contrib/sdk/sources/newlib/libc/sys/iowrite.c @@ -1,28 +1,33 @@ #include +#include #include int write_file(const char *path,const void *buff, size_t offset, size_t count, size_t *writes) { - int retval; - __asm__ __volatile__( - "pushl $0 \n\t" - "pushl $0 \n\t" - "movl %%eax, 1(%%esp) \n\t" - "pushl %%ebx \n\t" - "pushl %%edx \n\t" - "pushl $0 \n\t" - "pushl %%ecx \n\t" - "pushl $3 \n\t" - "movl %%esp, %%ebx \n\t" - "mov $70, %%eax \n\t" - "int $0x40 \n\t" - "testl %%esi, %%esi \n\t" - "jz 1f \n\t" - "movl %%ebx, (%%esi) \n\t" + int retval; + __asm__ __volatile__( + "pushl $0 \n\t" + "pushl $0 \n\t" + "movl %%eax, 1(%%esp) \n\t" + "pushl %%ebx \n\t" + "pushl %%edx \n\t" + "pushl $0 \n\t" + "pushl %%ecx \n\t" + "pushl $3 \n\t" + "movl %%esp, %%ebx \n\t" + "mov $70, %%eax \n\t" + "int $0x40 \n\t" + "testl %%esi, %%esi \n\t" + "jz 1f \n\t" + "movl %%ebx, (%%esi) \n\t" "1:" - "addl $28, %%esp \n\t" - :"=a" (retval) - :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes)); - return retval; + "addl $28, %%esp \n\t" + :"=a" (retval) + :"a"(path),"b"(buff),"c"(offset),"d"(count),"S"(writes)); + if(retval == 0) + return 0; + else if (retval == 8) + return ENOSPC; + return -1; }; diff --git a/contrib/sdk/sources/newlib/libc/sys/write.c b/contrib/sdk/sources/newlib/libc/sys/write.c index f30edfd931..9fa78d2ba9 100644 --- a/contrib/sdk/sources/newlib/libc/sys/write.c +++ b/contrib/sdk/sources/newlib/libc/sys/write.c @@ -86,9 +86,10 @@ static int os_write(int handle, const void *buffer, unsigned len, unsigned *amt ioh->offset+= *amt; - if( *amt != len ) + if( *amt && *amt != len ) { rc = ENOSPC; + errno = rc; } return( rc );