From f279e522b05950655c6b4699ecd7a7f115261bc8 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 26 Jun 2002 05:29:41 +0000 Subject: * autoload (noload): Avoid clobbering bx register. * environ.cc (codepage_init): Use case insensitive match. * fhandler_console.cc (cp_get_internal): Delete. (con_to_str): Use get_cp to derive code page. (str_to_con): Ditto. * miscfuncs.cc (get_cp): New function. (sys_wcstombs): New function. Converted from macro. (sys_mbstowcs): Ditto. * winsup.h: Reflect above changes. --- winsup/cygwin/ChangeLog | 14 ++++++++++++++ winsup/cygwin/autoload.cc | 6 +++--- winsup/cygwin/environ.cc | 8 +++----- winsup/cygwin/fhandler_console.cc | 16 ++++------------ winsup/cygwin/miscfuncs.cc | 20 ++++++++++++++++++++ winsup/cygwin/winsup.h | 13 ++++++++----- 6 files changed, 52 insertions(+), 25 deletions(-) (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index cc3ea2890..330ef3aab 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2002-06-26 Christopher Faylor + + * autoload (noload): Avoid clobbering bx register. + + * environ.cc (codepage_init): Use case insensitive match. + + * fhandler_console.cc (cp_get_internal): Delete. + (con_to_str): Use get_cp to derive code page. + (str_to_con): Ditto. + * miscfuncs.cc (get_cp): New function. + (sys_wcstombs): New function. Converted from macro. + (sys_mbstowcs): Ditto. + * winsup.h: Reflect above changes. + 2002-06-26 Christopher Faylor * winsup.h: Minor cleanup. diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc index 9bae17deb..d910b43ed 100644 --- a/winsup/cygwin/autoload.cc +++ b/winsup/cygwin/autoload.cc @@ -122,10 +122,10 @@ noload: \n\ jz 1f # Nope. \n\ decl %eax # Yes. This is the # of bytes + 1 \n\ popl %edx # Caller's caller \n\ - movl %eax,%ebx # For manipulation \n\ - andl $0xffff,%eax # Only want lower word \n\ addl %eax,%esp # Pop off bytes \n\ - pushl %ebx # Save for later \n\ + andl $0xffff0000,%eax# upper word \n\ + subl %eax,%esp # adjust for possible return value \n\ + pushl %eax # Save for later \n\ movl $127,%eax # ERROR_PROC_NOT_FOUND \n\ pushl %eax # First argument \n\ call _SetLastError@4 # Set it \n\ diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 9fc4d0ab8..ab280265c 100644 --- a/winsup/cygwin/environ.cc +++ b/winsup/cygwin/environ.cc @@ -448,20 +448,18 @@ codepage_init (const char *buf) if (!buf || !*buf) return; - if (strcmp (buf, "oem")== 0) + if (strcasematch (buf, "oem")) { current_codepage = oem_cp; set_file_api_mode (current_codepage); } - else if (strcmp (buf, "ansi")== 0) + else if (strcasematch (buf, "ansi")) { current_codepage = ansi_cp; set_file_api_mode (current_codepage); } else - { - debug_printf ("Wrong codepage name: %s", buf); - } + debug_printf ("Wrong codepage name: %s", buf); } static void diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index cc948d3d0..458c5a337 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -17,7 +17,7 @@ details. */ #include #include #include -#include // MultiByteToWideChar () and friends +#include #include #include #include "cygerrno.h" @@ -32,16 +32,8 @@ details. */ #define CONVERT_LIMIT 4096 -/* The codepages are resolved here instead of using CP_ACP and - CP_OEMCP, so that they can later be compared for equality. */ -inline UINT -cp_get_internal () -{ - return current_codepage == ansi_cp ? GetACP() : GetOEMCP(); -} - static BOOL -cp_convert (UINT destcp, char * dest, UINT srccp, const char * src, DWORD size) +cp_convert (UINT destcp, char *dest, UINT srccp, const char *src, DWORD size) { if (!size) /* no action */; @@ -68,13 +60,13 @@ cp_convert (UINT destcp, char * dest, UINT srccp, const char * src, DWORD size) inline BOOL con_to_str (char *d, const char *s, DWORD sz) { - return cp_convert (cp_get_internal (), d, GetConsoleCP (), s, sz); + return cp_convert (get_cp (), d, GetConsoleCP (), s, sz); } inline BOOL str_to_con (char *d, const char *s, DWORD sz) { - return cp_convert (GetConsoleOutputCP (), d, cp_get_internal (), s, sz); + return cp_convert (GetConsoleOutputCP (), d, get_cp (), s, sz); } /* diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc index 5d3010470..6fd9ffc91 100644 --- a/winsup/cygwin/miscfuncs.cc +++ b/winsup/cygwin/miscfuncs.cc @@ -11,6 +11,8 @@ details. */ #include "winsup.h" #include "cygerrno.h" #include +#include +#include long tls_ix = -1; @@ -176,3 +178,21 @@ __check_invalid_read_ptr_errno (const void *s, unsigned sz) return 0; return set_errno (EFAULT); } + +UINT +get_cp () +{ + return current_codepage == ansi_cp ? GetACP() : GetOEMCP(); +} + +int __stdcall +sys_wcstombs (char *tgt, const WCHAR *src, int len) +{ + return WideCharToMultiByte (get_cp (), 0, src, -1, tgt, len, NULL, NULL); +} + +int __stdcall +sys_mbstowcs (WCHAR *tgt, const char *src, int len) +{ + return MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len); +} diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 5735985c7..4cfce5d4c 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -68,15 +68,18 @@ extern "C" DWORD WINAPI GetLastError (void); enum codepage_type {ansi_cp, oem_cp}; extern codepage_type current_codepage; -extern int cygserver_running; +UINT get_cp (); + +int __stdcall sys_wcstombs(char *, const WCHAR *, int) + __attribute__ ((regparm(3))); + +int __stdcall sys_mbstowcs(WCHAR *, const char *, int) + __attribute__ ((regparm(3))); /* Used to check if Cygwin DLL is dynamically loaded. */ extern int dynamically_loaded; -#define sys_wcstombs(tgt,src,len) \ - WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL) -#define sys_mbstowcs(tgt,src,len) \ - MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len)) +extern int cygserver_running; #define TITLESIZE 1024 -- cgit v1.2.3