Alexandre Julliard : msvcrt: Properly implemented strerror and perror
(based on a patch by
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Jan 23 14:48:07 CST 2006
Module: wine
Branch: refs/heads/master
Commit: 2dacd3c54e66c155303475dfe31056d0c5381c95
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=2dacd3c54e66c155303475dfe31056d0c5381c95
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Jan 23 19:58:10 2006 +0100
msvcrt: Properly implemented strerror and perror (based on a patch by
Uwe Bonnes).
---
dlls/msvcrt/errno.c | 40 ++++++++++++++++++++++++++++++++++------
dlls/msvcrt/main.c | 1 +
dlls/msvcrt/msvcrt.h | 1 +
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcrt/errno.c b/dlls/msvcrt/errno.c
index cca743d..656e5ba 100644
--- a/dlls/msvcrt/errno.c
+++ b/dlls/msvcrt/errno.c
@@ -199,17 +199,36 @@ unsigned long* MSVCRT___doserrno(void)
*/
char* MSVCRT_strerror(int err)
{
- return strerror(err); /* FIXME */
+ thread_data_t *data = msvcrt_get_thread_data();
+
+ if (!data->strerror_buffer)
+ if (!(data->strerror_buffer = MSVCRT_malloc(256))) return NULL;
+
+ if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
+ strcpy( data->strerror_buffer, MSVCRT__sys_errlist[err] );
+ return data->strerror_buffer;
}
/**********************************************************************
* _strerror (MSVCRT.@)
*/
-char* _strerror(const char* err)
+char* _strerror(const char* str)
{
- static char strerrbuff[256]; /* FIXME: Per thread, nprintf */
- sprintf(strerrbuff,"%s: %s\n",err,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
- return strerrbuff;
+ thread_data_t *data = msvcrt_get_thread_data();
+ int err;
+
+ if (!data->strerror_buffer)
+ if (!(data->strerror_buffer = MSVCRT_malloc(256))) return NULL;
+
+ err = data->thread_errno;
+ if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
+
+ if (str && *str)
+ sprintf( data->strerror_buffer, "%s: %s\n", str, MSVCRT__sys_errlist[err] );
+ else
+ sprintf( data->strerror_buffer, "%s\n", MSVCRT__sys_errlist[err] );
+
+ return data->strerror_buffer;
}
/*********************************************************************
@@ -217,7 +236,16 @@ char* _strerror(const char* err)
*/
void MSVCRT_perror(const char* str)
{
- _cprintf("%s: %s\n",str,MSVCRT_strerror(msvcrt_get_thread_data()->thread_errno));
+ int err = *MSVCRT__errno();
+ if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
+
+ if (str && *str)
+ {
+ _write( 2, str, strlen(str) );
+ _write( 2, ": ", 2 );
+ }
+ _write( 2, MSVCRT__sys_errlist[err], strlen(MSVCRT__sys_errlist[err]) );
+ _write( 2, "\n", 1 );
}
/******************************************************************************
diff --git a/dlls/msvcrt/main.c b/dlls/msvcrt/main.c
index 6697c1c..c43b88c 100644
--- a/dlls/msvcrt/main.c
+++ b/dlls/msvcrt/main.c
@@ -75,6 +75,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,
HeapFree(GetProcessHeap(),0,tls->efcvt_buffer);
HeapFree(GetProcessHeap(),0,tls->asctime_buffer);
HeapFree(GetProcessHeap(),0,tls->wasctime_buffer);
+ HeapFree(GetProcessHeap(),0,tls->strerror_buffer);
}
HeapFree(GetProcessHeap(), 0, tls);
TRACE("finished thread free\n");
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index e3b82de..0ac0758 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -101,6 +101,7 @@ struct __thread_data {
char *asctime_buffer; /* buffer for asctime */
MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
struct MSVCRT_tm time_buffer; /* buffer for localtime/gmtime */
+ char *strerror_buffer; /* buffer for strerror */
int fpecode;
MSVCRT_terminate_function terminate_handler;
MSVCRT_unexpected_function unexpected_handler;
More information about the wine-cvs
mailing list