| author | |
| committer | |
| log | 8afe928b6e5483894d58efac9034a7ce3bb8359f |
| tree | 49375d0e952359688faeb0bdb85380034a9736d8 |
| parent | ed10a5db588a74d4ecbff8dd4f5617d8fc75cd27 |
| signature |
77 files changed, 3759 insertions(+), 4521 deletions(-)
lib/libc/mingw/crt/cinitexe.c+3-4| ... | ... | @@ -1,13 +1,12 @@ |
| 1 | 1 | #include <stdio.h> |
| 2 | 2 | #include <sect_attribs.h> |
| 3 | #include <corecrt_startup.h> | |
| 3 | 4 | |
| 4 | 5 | #ifdef _MSC_VER |
| 5 | 6 | #pragma comment(linker, "/merge:.CRT=.rdata") |
| 6 | 7 | #endif |
| 7 | 8 | |
| 8 | typedef void (__cdecl *_PVFV)(void); | |
| 9 | ||
| 10 | _CRTALLOC(".CRT$XIA") _PVFV __xi_a[] = { NULL }; | |
| 11 | _CRTALLOC(".CRT$XIZ") _PVFV __xi_z[] = { NULL }; | |
| 9 | _CRTALLOC(".CRT$XIA") _PIFV __xi_a[] = { NULL }; | |
| 10 | _CRTALLOC(".CRT$XIZ") _PIFV __xi_z[] = { NULL }; | |
| 12 | 11 | _CRTALLOC(".CRT$XCA") _PVFV __xc_a[] = { NULL }; |
| 13 | 12 | _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[] = { NULL }; |
lib/libc/mingw/crt/crt_handler.c-4| ... | ... | @@ -51,10 +51,6 @@ __mingw_init_ehandler (void) |
| 51 | 51 | if (_FindPESectionByName (".pdata") != NULL) |
| 52 | 52 | return 1; |
| 53 | 53 | |
| 54 | /* Allocate # of e tables and entries. */ | |
| 55 | memset (emu_pdata, 0, sizeof (RUNTIME_FUNCTION) * MAX_PDATA_ENTRIES); | |
| 56 | memset (emu_xdata, 0, sizeof (UNWIND_INFO) * MAX_PDATA_ENTRIES); | |
| 57 | ||
| 58 | 54 | e = 0; |
| 59 | 55 | /* Fill tables and entries. */ |
| 60 | 56 | while (e < MAX_PDATA_ENTRIES && (pSec = _FindPESectionExec (e)) != NULL) |
lib/libc/mingw/crt/crtdll.c+14-7| ... | ... | @@ -97,7 +97,8 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) |
| 97 | 97 | 	{ |
| 98 | 98 | 	 __native_startup_state = __initializing; |
| 99 | 99 | 	 |
| 100 | 	 _initterm ((_PVFV *) (void *) __xi_a, (_PVFV *) (void *) __xi_z); | |
| 100 | 	 if (_initterm_e (__xi_a, __xi_z) != 0) | |
| 101 | 	 return FALSE; | |
| 101 | 102 | 	} |
| 102 | 103 | if (__native_startup_state == __initializing) |
| 103 | 104 | 	{ |
| ... | ... | @@ -147,15 +148,15 @@ WINBOOL WINAPI |
| 147 | 148 | DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) |
| 148 | 149 | { |
| 149 | 150 | __mingw_app_type = 0; |
| 150 | if (dwReason == DLL_PROCESS_ATTACH) | |
| 151 | { | |
| 152 | #if defined(__x86_64__) && !defined(__SEH__) | |
| 153 | __mingw_init_ehandler (); | |
| 154 | #endif | |
| 155 | } | |
| 156 | 151 | return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved); |
| 157 | 152 | } |
| 158 | 153 | |
| 154 | static | |
| 155 | #if defined(__i386__) || defined(_X86_) | |
| 156 | /* We need to make sure that we align the stack to 16 bytes for the sake of SSE | |
| 157 | opts in DllMain/DllEntryPoint or in functions called from DllMain/DllEntryPoint. */ | |
| 158 | __attribute__((force_align_arg_pointer)) | |
| 159 | #endif | |
| 159 | 160 | __declspec(noinline) WINBOOL |
| 160 | 161 | __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) |
| 161 | 162 | { |
| ... | ... | @@ -168,6 +169,12 @@ __DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) |
| 168 | 169 | 	goto i__leave; |
| 169 | 170 | } |
| 170 | 171 | _pei386_runtime_relocator (); |
| 172 | ||
| 173 | #if defined(__x86_64__) && !defined(__SEH__) | |
| 174 | if (dwReason == DLL_PROCESS_ATTACH) | |
| 175 | __mingw_init_ehandler (); | |
| 176 | #endif | |
| 177 | ||
| 171 | 178 | if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH) |
| 172 | 179 | { |
| 173 | 180 | retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved); |
lib/libc/mingw/crt/crtexe.c+13-6| ... | ... | @@ -58,11 +58,9 @@ extern void __main(void); |
| 58 | 58 | static _TCHAR **argv; |
| 59 | 59 | static _TCHAR **envp; |
| 60 | 60 | |
| 61 | static int argret; | |
| 62 | 61 | static int mainret=0; |
| 63 | 62 | static int managedapp; |
| 64 | 63 | static int has_cctor = 0; |
| 65 | static _startupinfo startinfo; | |
| 66 | 64 | extern LPTOP_LEVEL_EXCEPTION_FILTER __mingw_oldexcpt_handler; |
| 67 | 65 | |
| 68 | 66 | extern void _pei386_runtime_relocator (void); |
| ... | ... | @@ -97,6 +95,7 @@ __mingw_invalidParameterHandler (const wchar_t * __UNUSED_PARAM_1(expression), |
| 97 | 95 | static int __cdecl |
| 98 | 96 | pre_c_init (void) |
| 99 | 97 | { |
| 98 | int ret; | |
| 100 | 99 | managedapp = check_managed_app (); |
| 101 | 100 | if (__mingw_app_type) |
| 102 | 101 | __set_app_type(_GUI_APP); |
| ... | ... | @@ -107,10 +106,12 @@ pre_c_init (void) |
| 107 | 106 | * __p__commode() = _commode; |
| 108 | 107 | |
| 109 | 108 | #ifdef _UNICODE |
| 110 | _wsetargv(); | |
| 109 | ret = _wsetargv(); | |
| 111 | 110 | #else |
| 112 | _setargv(); | |
| 111 | ret = _setargv(); | |
| 113 | 112 | #endif |
| 113 | if (ret < 0) | |
| 114 | _amsg_exit(8); /* _RT_SPACEARG */ | |
| 114 | 115 | if (_MINGW_INSTALL_DEBUG_MATHERR == 1) |
| 115 | 116 | { |
| 116 | 117 | __setusermatherr (_matherr); |
| ... | ... | @@ -125,6 +126,9 @@ pre_c_init (void) |
| 125 | 126 | static void __cdecl |
| 126 | 127 | pre_cpp_init (void) |
| 127 | 128 | { |
| 129 | _startupinfo startinfo; | |
| 130 | int argret; | |
| 131 | ||
| 128 | 132 | startinfo.newmode = _newmode; |
| 129 | 133 | |
| 130 | 134 | #ifdef _UNICODE |
| ... | ... | @@ -132,6 +136,8 @@ pre_cpp_init (void) |
| 132 | 136 | #else |
| 133 | 137 | argret = __getmainargs(&argc,&argv,&envp,_dowildcard,&startinfo); |
| 134 | 138 | #endif |
| 139 | if (argret < 0) | |
| 140 | _amsg_exit(8); /* _RT_SPACEARG */ | |
| 135 | 141 | } |
| 136 | 142 | |
| 137 | 143 | static int __tmainCRTStartup (void); |
| ... | ... | @@ -197,7 +203,7 @@ int mainCRTStartup (void) |
| 197 | 203 | static |
| 198 | 204 | #if defined(__i386__) || defined(_X86_) |
| 199 | 205 | /* We need to make sure that we align the stack to 16 bytes for the sake of SSE |
| 200 | opts in main or in functions called main. */ | |
| 206 | opts in main or in functions called from main. */ | |
| 201 | 207 | __attribute__((force_align_arg_pointer)) |
| 202 | 208 | #endif |
| 203 | 209 | __declspec(noinline) int |
| ... | ... | @@ -223,7 +229,8 @@ __tmainCRTStartup (void) |
| 223 | 229 | else if (__native_startup_state == __uninitialized) |
| 224 | 230 | { |
| 225 | 231 | 	__native_startup_state = __initializing; |
| 226 | 	_initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z); | |
| 232 | 	if (_initterm_e (__xi_a, __xi_z) != 0) | |
| 233 | 	 return 255; | |
| 227 | 234 | } |
| 228 | 235 | else |
| 229 | 236 | has_cctor = 1; |
lib/libc/mingw/crt/intrincs/RtlSecureZeroMemory.c deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | #define __CRT__NO_INLINE 1 | |
| 2 | #include <windows.h> | |
| 3 | ||
| 4 | PVOID WINAPI RtlSecureZeroMemory(PVOID ptr,SIZE_T cnt) | |
| 5 | { | |
| 6 | volatile char *vptr = (volatile char *)ptr; | |
| 7 | #ifdef __x86_64 | |
| 8 | __stosb ((PBYTE)((DWORD64)vptr),0,cnt); | |
| 9 | #else | |
| 10 | while (cnt != 0) | |
| 11 | { | |
| 12 | *vptr++ = 0; | |
| 13 | cnt--; | |
| 14 | } | |
| 15 | #endif /* __x86_64 */ | |
| 16 | return ptr; | |
| 17 | } |
lib/libc/mingw/crt/tlssup.c+1| ... | ... | @@ -32,6 +32,7 @@ typedef struct TlsDtorNode { |
| 32 | 32 | _PVFV funcs[FUNCS_PER_NODE]; |
| 33 | 33 | } TlsDtorNode; |
| 34 | 34 | |
| 35 | __attribute__((used)) | |
| 35 | 36 | ULONG _tls_index = 0; |
| 36 | 37 | |
| 37 | 38 | /* TLS raw template data start and end. |
lib/libc/mingw/def-include/crt-aliases.def.in+14-10| ... | ... | @@ -231,6 +231,12 @@ ADD_UNDERSCORE(y1) |
| 231 | 231 | ADD_UNDERSCORE(yn) |
| 232 | 232 | |
| 233 | 233 | ; This is list of symbol aliases for C95 functions |
| 234 | #ifdef WITH_GET_PUT_WCHAR_ALIASES | |
| 235 | getwc == fgetwc | |
| 236 | getwchar == _fgetwchar | |
| 237 | putwc == fputwc | |
| 238 | putwchar == _fputwchar | |
| 239 | #endif | |
| 234 | 240 | #ifdef USE_WCSTOK_S_FOR_WCSTOK |
| 235 | 241 | wcstok == wcstok_s |
| 236 | 242 | #endif |
| ... | ... | @@ -531,24 +537,22 @@ __ms_printf == printf |
| 531 | 537 | __ms_scanf == scanf |
| 532 | 538 | __ms_sprintf == sprintf |
| 533 | 539 | __ms_sscanf == sscanf |
| 534 | #ifdef PRE_C95_SWPRINTF | |
| 535 | __ms_swprintf == swprintf | |
| 536 | #else | |
| 537 | __ms_swprintf == _swprintf | |
| 538 | #endif | |
| 539 | 540 | __ms_swscanf == swscanf |
| 540 | 541 | __ms_vfprintf == vfprintf |
| 541 | 542 | __ms_vfwprintf == vfwprintf |
| 542 | 543 | __ms_vprintf == vprintf |
| 543 | 544 | __ms_vsprintf == vsprintf |
| 544 | #ifdef PRE_C95_SWPRINTF | |
| 545 | __ms_vswprintf == vswprintf | |
| 546 | #else | |
| 547 | __ms_vswprintf == _vswprintf | |
| 548 | #endif | |
| 549 | 545 | __ms_vwprintf == vwprintf |
| 550 | 546 | __ms_wprintf == wprintf |
| 551 | 547 | __ms_wscanf == wscanf |
| 548 | #ifdef WITH_MS_VSCANF_ALIASES | |
| 549 | __ms_vfscanf == vfscanf | |
| 550 | __ms_vfwscanf == vfwscanf | |
| 551 | __ms_vscanf == vscanf | |
| 552 | __ms_vsscanf == vsscanf | |
| 553 | __ms_vswscanf == vswscanf | |
| 554 | __ms_vwscanf == vwscanf | |
| 555 | #endif | |
| 552 | 556 | #endif |
| 553 | 557 | |
| 554 | 558 | ; This is list of additional symbol aliases not available in any library as neither native symbols nor aliases |
lib/libc/mingw/include/msvcrt.h+9-4| ... | ... | @@ -1,10 +1,15 @@ |
| 1 | #include <winbase.h> | |
| 2 | ||
| 3 | 1 | #ifndef __LIBMSVCRT_OS__ |
| 4 | 2 | #error "This file should only be used in libmsvcrt-os.a" |
| 5 | 3 | #endif |
| 6 | 4 | |
| 7 | static inline HANDLE __mingw_get_msvcrt_handle(void) | |
| 5 | #ifndef MSVCRT_H | |
| 6 | #define MSVCRT_H | |
| 7 | ||
| 8 | #include <winbase.h> | |
| 9 | ||
| 10 | static inline HMODULE __mingw_get_msvcrt_handle(void) | |
| 8 | 11 | { |
| 9 | return GetModuleHandleW(L"msvcrt.dll"); | |
| 12 | return GetModuleHandleA("msvcrt.dll"); | |
| 10 | 13 | } |
| 14 | ||
| 15 | #endif |
lib/libc/mingw/intrincs/RtlSecureZeroMemory.c created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | #define __CRT__NO_INLINE 1 | |
| 2 | #include <windows.h> | |
| 3 | ||
| 4 | PVOID WINAPI RtlSecureZeroMemory(PVOID ptr,SIZE_T cnt) | |
| 5 | { | |
| 6 | volatile char *vptr = (volatile char *)ptr; | |
| 7 | #ifdef __x86_64 | |
| 8 | __stosb ((PBYTE)((DWORD64)vptr),0,cnt); | |
| 9 | #else | |
| 10 | while (cnt != 0) | |
| 11 | { | |
| 12 | *vptr++ = 0; | |
| 13 | cnt--; | |
| 14 | } | |
| 15 | #endif /* __x86_64 */ | |
| 16 | return ptr; | |
| 17 | } |
lib/libc/mingw/lib-common/kernel32.def.in+5| ... | ... | @@ -25,6 +25,7 @@ AddVectoredContinueHandler |
| 25 | 25 | AddVectoredExceptionHandler |
| 26 | 26 | AdjustCalendarDate |
| 27 | 27 | AllocConsole |
| 28 | AllocConsoleWithOptions | |
| 28 | 29 | AllocateUserPhysicalPages |
| 29 | 30 | AllocateUserPhysicalPagesNuma |
| 30 | 31 | AppPolicyGetClrCompat |
| ... | ... | @@ -447,6 +448,7 @@ FindVolumeMountPointClose |
| 447 | 448 | FlsAlloc |
| 448 | 449 | FlsFree |
| 449 | 450 | FlsGetValue |
| 451 | FlsGetValue2 | |
| 450 | 452 | FlsSetValue |
| 451 | 453 | FlushConsoleInputBuffer |
| 452 | 454 | FlushFileBuffers |
| ... | ... | @@ -626,6 +628,7 @@ GetFileAttributesW |
| 626 | 628 | GetFileBandwidthReservation |
| 627 | 629 | GetFileInformationByHandle |
| 628 | 630 | GetFileInformationByHandleEx |
| 631 | GetFileInformationByName | |
| 629 | 632 | GetFileMUIInfo |
| 630 | 633 | GetFileMUIPath |
| 631 | 634 | GetFileSize |
| ... | ... | @@ -1282,6 +1285,7 @@ ReleaseActCtxWorker |
| 1282 | 1285 | ReleaseMutex |
| 1283 | 1286 | ReleaseMutexWhenCallbackReturns |
| 1284 | 1287 | ReleasePackageVirtualizationContext |
| 1288 | ReleasePseudoConsole | |
| 1285 | 1289 | ReleaseSRWLockExclusive |
| 1286 | 1290 | ReleaseSRWLockShared |
| 1287 | 1291 | ReleaseSemaphore |
| ... | ... | @@ -1543,6 +1547,7 @@ Thread32Next |
| 1543 | 1547 | TlsAlloc |
| 1544 | 1548 | TlsFree |
| 1545 | 1549 | TlsGetValue |
| 1550 | TlsGetValue2 | |
| 1546 | 1551 | TlsSetValue |
| 1547 | 1552 | Toolhelp32ReadProcessMemory |
| 1548 | 1553 | TransactNamedPipe |
lib/libc/mingw/lib-common/vcruntime140-common.def.in created+89| ... | ... | @@ -0,0 +1,89 @@ |
| 1 | _CreateFrameInfo | |
| 2 | F_I386(_CxxThrowException@8) | |
| 3 | F_NON_I386(_CxxThrowException) | |
| 4 | F_I386(_EH_prolog) | |
| 5 | _FindAndUnlinkFrame | |
| 6 | _IsExceptionObjectToBeDestroyed | |
| 7 | F_I386(_NLG_Dispatch2@4) | |
| 8 | F_I386(_NLG_Return@12) | |
| 9 | F_I386(_NLG_Return2) | |
| 10 | _SetWinRTOutOfMemoryExceptionCallback | |
| 11 | __AdjustPointer | |
| 12 | __BuildCatchObject | |
| 13 | __BuildCatchObjectHelper | |
| 14 | F_NON_I386(__C_specific_handler) | |
| 15 | F_NON_I386(__C_specific_handler_noexcept) | |
| 16 | __CxxDetectRethrow | |
| 17 | __CxxExceptionFilter | |
| 18 | __CxxFrameHandler | |
| 19 | __CxxFrameHandler2 | |
| 20 | __CxxFrameHandler3 | |
| 21 | F_I386(__CxxLongjmpUnwind@4) | |
| 22 | __CxxQueryExceptionSize | |
| 23 | __CxxRegisterExceptionObject | |
| 24 | __CxxUnregisterExceptionObject | |
| 25 | __DestructExceptionObject | |
| 26 | __FrameUnwindFilter | |
| 27 | __GetPlatformExceptionInfo | |
| 28 | F_NON_I386(__NLG_Dispatch2) | |
| 29 | F_NON_I386(__NLG_Return2) | |
| 30 | __RTCastToVoid | |
| 31 | __RTDynamicCast | |
| 32 | __RTtypeid | |
| 33 | __TypeMatch | |
| 34 | __current_exception | |
| 35 | __current_exception_context | |
| 36 | F_NON_ARM64(__intrinsic_setjmp) | |
| 37 | F_NON_I386(__intrinsic_setjmpex) | |
| 38 | F_ARM32(__jump_unwind) | |
| 39 | __processing_throw | |
| 40 | __report_gsfailure | |
| 41 | __std_exception_copy | |
| 42 | __std_exception_destroy | |
| 43 | __std_terminate | |
| 44 | __std_type_info_compare | |
| 45 | __std_type_info_destroy_list | |
| 46 | __std_type_info_hash | |
| 47 | __std_type_info_name | |
| 48 | __telemetry_main_invoke_trigger | |
| 49 | __telemetry_main_return_trigger | |
| 50 | __unDName | |
| 51 | __unDNameEx | |
| 52 | __uncaught_exception | |
| 53 | __uncaught_exceptions | |
| 54 | __vcrt_GetModuleFileNameW | |
| 55 | __vcrt_GetModuleHandleW | |
| 56 | __vcrt_InitializeCriticalSectionEx | |
| 57 | __vcrt_LoadLibraryExW | |
| 58 | F_I386(_chkesp) | |
| 59 | F_I386(_except_handler2) | |
| 60 | F_I386(_except_handler3) | |
| 61 | F_I386(_except_handler4_common) | |
| 62 | _get_purecall_handler | |
| 63 | _get_unexpected | |
| 64 | F_I386(_global_unwind2) | |
| 65 | _is_exception_typeof | |
| 66 | F64(_local_unwind) | |
| 67 | F_I386(_local_unwind2) | |
| 68 | F_I386(_local_unwind4) | |
| 69 | F_I386(_longjmpex) | |
| 70 | _purecall | |
| 71 | F_I386(_seh_longjmp_unwind4@4) | |
| 72 | F_I386(_seh_longjmp_unwind@4) | |
| 73 | _set_purecall_handler | |
| 74 | _set_se_translator | |
| 75 | F_I386(_setjmp3) | |
| 76 | longjmp | |
| 77 | memchr | |
| 78 | memcmp | |
| 79 | memcpy | |
| 80 | memmove | |
| 81 | memset | |
| 82 | set_unexpected | |
| 83 | strchr | |
| 84 | strrchr | |
| 85 | strstr | |
| 86 | unexpected | |
| 87 | wcschr | |
| 88 | wcsrchr | |
| 89 | wcsstr |
lib/libc/mingw/lib-common/vcruntime140.def.in+1-90| ... | ... | @@ -2,93 +2,4 @@ LIBRARY "VCRUNTIME140.dll" |
| 2 | 2 | EXPORTS |
| 3 | 3 | |
| 4 | 4 | #include "func.def.in" |
| 5 | ||
| 6 | _CreateFrameInfo | |
| 7 | F_I386(_CxxThrowException@8) | |
| 8 | F_NON_I386(_CxxThrowException) | |
| 9 | F_I386(_EH_prolog) | |
| 10 | _FindAndUnlinkFrame | |
| 11 | _IsExceptionObjectToBeDestroyed | |
| 12 | F_I386(_NLG_Dispatch2@4) | |
| 13 | F_I386(_NLG_Return@12) | |
| 14 | F_I386(_NLG_Return2) | |
| 15 | _SetWinRTOutOfMemoryExceptionCallback | |
| 16 | __AdjustPointer | |
| 17 | __BuildCatchObject | |
| 18 | __BuildCatchObjectHelper | |
| 19 | F_NON_I386(__C_specific_handler) | |
| 20 | F_NON_I386(__C_specific_handler_noexcept) | |
| 21 | __CxxDetectRethrow | |
| 22 | __CxxExceptionFilter | |
| 23 | __CxxFrameHandler | |
| 24 | __CxxFrameHandler2 | |
| 25 | __CxxFrameHandler3 | |
| 26 | F_I386(__CxxLongjmpUnwind@4) | |
| 27 | __CxxQueryExceptionSize | |
| 28 | __CxxRegisterExceptionObject | |
| 29 | __CxxUnregisterExceptionObject | |
| 30 | __DestructExceptionObject | |
| 31 | __FrameUnwindFilter | |
| 32 | __GetPlatformExceptionInfo | |
| 33 | F_NON_I386(__NLG_Dispatch2) | |
| 34 | F_NON_I386(__NLG_Return2) | |
| 35 | __RTCastToVoid | |
| 36 | __RTDynamicCast | |
| 37 | __RTtypeid | |
| 38 | __TypeMatch | |
| 39 | __current_exception | |
| 40 | __current_exception_context | |
| 41 | F_NON_ARM64(__intrinsic_setjmp) | |
| 42 | F_NON_I386(__intrinsic_setjmpex) | |
| 43 | F_ARM32(__jump_unwind) | |
| 44 | __processing_throw | |
| 45 | __report_gsfailure | |
| 46 | __std_exception_copy | |
| 47 | __std_exception_destroy | |
| 48 | __std_terminate | |
| 49 | __std_type_info_compare | |
| 50 | __std_type_info_destroy_list | |
| 51 | __std_type_info_hash | |
| 52 | __std_type_info_name | |
| 53 | __telemetry_main_invoke_trigger | |
| 54 | __telemetry_main_return_trigger | |
| 55 | __unDName | |
| 56 | __unDNameEx | |
| 57 | __uncaught_exception | |
| 58 | __uncaught_exceptions | |
| 59 | __vcrt_GetModuleFileNameW | |
| 60 | __vcrt_GetModuleHandleW | |
| 61 | __vcrt_InitializeCriticalSectionEx | |
| 62 | __vcrt_LoadLibraryExW | |
| 63 | F_I386(_chkesp) | |
| 64 | F_I386(_except_handler2) | |
| 65 | F_I386(_except_handler3) | |
| 66 | F_I386(_except_handler4_common) | |
| 67 | _get_purecall_handler | |
| 68 | _get_unexpected | |
| 69 | F_I386(_global_unwind2) | |
| 70 | _is_exception_typeof | |
| 71 | F64(_local_unwind) | |
| 72 | F_I386(_local_unwind2) | |
| 73 | F_I386(_local_unwind4) | |
| 74 | F_I386(_longjmpex) | |
| 75 | _purecall | |
| 76 | F_I386(_seh_longjmp_unwind4@4) | |
| 77 | F_I386(_seh_longjmp_unwind@4) | |
| 78 | _set_purecall_handler | |
| 79 | _set_se_translator | |
| 80 | F_I386(_setjmp3) | |
| 81 | longjmp | |
| 82 | memchr | |
| 83 | memcmp | |
| 84 | memcpy | |
| 85 | memmove | |
| 86 | memset | |
| 87 | set_unexpected | |
| 88 | strchr | |
| 89 | strrchr | |
| 90 | strstr | |
| 91 | unexpected | |
| 92 | wcschr | |
| 93 | wcsrchr | |
| 94 | wcsstr | |
| 5 | #include "vcruntime140-common.def.in" |
lib/libc/mingw/lib-common/vcruntime140_app.def.in+2-92| ... | ... | @@ -1,95 +1,5 @@ |
| 1 | LIBRARY vcruntime140_app | |
| 2 | ||
| 1 | LIBRARY "VCRUNTIME140_APP.dll" | |
| 3 | 2 | EXPORTS |
| 4 | 3 | |
| 5 | 4 | #include "func.def.in" |
| 6 | ||
| 7 | _CreateFrameInfo | |
| 8 | F_I386(_CxxThrowException@8) | |
| 9 | F_NON_I386(_CxxThrowException) | |
| 10 | F_I386(_EH_prolog) | |
| 11 | _FindAndUnlinkFrame | |
| 12 | _IsExceptionObjectToBeDestroyed | |
| 13 | F_I386(_NLG_Dispatch2) | |
| 14 | F_I386(_NLG_Return) | |
| 15 | F_I386(_NLG_Return2) | |
| 16 | _SetWinRTOutOfMemoryExceptionCallback | |
| 17 | __AdjustPointer | |
| 18 | __BuildCatchObject | |
| 19 | __BuildCatchObjectHelper | |
| 20 | F_NON_I386(__C_specific_handler) | |
| 21 | F_NON_I386(__C_specific_handler_noexcept) | |
| 22 | __CxxDetectRethrow | |
| 23 | __CxxExceptionFilter | |
| 24 | __CxxFrameHandler | |
| 25 | __CxxFrameHandler2 | |
| 26 | __CxxFrameHandler3 | |
| 27 | F_I386(__CxxLongjmpUnwind@4) | |
| 28 | __CxxQueryExceptionSize | |
| 29 | __CxxRegisterExceptionObject | |
| 30 | __CxxUnregisterExceptionObject | |
| 31 | __DestructExceptionObject | |
| 32 | __FrameUnwindFilter | |
| 33 | __GetPlatformExceptionInfo | |
| 34 | F_NON_I386(__NLG_Dispatch2) | |
| 35 | F_NON_I386(__NLG_Return2) | |
| 36 | __RTCastToVoid | |
| 37 | __RTDynamicCast | |
| 38 | __RTtypeid | |
| 39 | __TypeMatch | |
| 40 | __current_exception | |
| 41 | __current_exception_context | |
| 42 | F_NON_ARM64(__intrinsic_setjmp) | |
| 43 | F_NON_I386(__intrinsic_setjmpex) | |
| 44 | F_ARM32(__jump_unwind) | |
| 45 | __processing_throw | |
| 46 | __report_gsfailure | |
| 47 | __std_exception_copy | |
| 48 | __std_exception_destroy | |
| 49 | __std_terminate | |
| 50 | __std_type_info_compare | |
| 51 | __std_type_info_destroy_list | |
| 52 | __std_type_info_hash | |
| 53 | __std_type_info_name | |
| 54 | __telemetry_main_invoke_trigger | |
| 55 | __telemetry_main_return_trigger | |
| 56 | __unDName | |
| 57 | __unDNameEx | |
| 58 | __uncaught_exception | |
| 59 | __uncaught_exceptions | |
| 60 | __vcrt_GetModuleFileNameW | |
| 61 | __vcrt_GetModuleHandleW | |
| 62 | __vcrt_InitializeCriticalSectionEx | |
| 63 | __vcrt_LoadLibraryExW | |
| 64 | F_I386(_chkesp) | |
| 65 | F_I386(_except_handler2) | |
| 66 | F_I386(_except_handler3) | |
| 67 | F_I386(_except_handler4_common) | |
| 68 | _get_purecall_handler | |
| 69 | _get_unexpected | |
| 70 | F_I386(_global_unwind2) | |
| 71 | _is_exception_typeof | |
| 72 | F_I386(_local_unwind2) | |
| 73 | F_I386(_local_unwind4) | |
| 74 | F_I386(_longjmpex) | |
| 75 | F64(_local_unwind) | |
| 76 | _purecall | |
| 77 | F_I386(_seh_longjmp_unwind4@4) | |
| 78 | F_I386(_seh_longjmp_unwind@4) | |
| 79 | _set_purecall_handler | |
| 80 | _set_se_translator | |
| 81 | F_I386(_setjmp3) | |
| 82 | longjmp | |
| 83 | memchr | |
| 84 | memcmp | |
| 85 | memcpy | |
| 86 | memmove | |
| 87 | memset | |
| 88 | set_unexpected | |
| 89 | strchr | |
| 90 | strrchr | |
| 91 | strstr | |
| 92 | unexpected | |
| 93 | wcschr | |
| 94 | wcsrchr | |
| 95 | wcsstr | |
| 5 | #include "vcruntime140-common.def.in" |
lib/libc/mingw/lib-common/vcruntime140d.def.in+1-90| ... | ... | @@ -2,93 +2,4 @@ LIBRARY "VCRUNTIME140D.dll" |
| 2 | 2 | EXPORTS |
| 3 | 3 | |
| 4 | 4 | #include "func.def.in" |
| 5 | ||
| 6 | _CreateFrameInfo | |
| 7 | F_I386(_CxxThrowException@8) | |
| 8 | F_NON_I386(_CxxThrowException) | |
| 9 | F_I386(_EH_prolog) | |
| 10 | _FindAndUnlinkFrame | |
| 11 | _IsExceptionObjectToBeDestroyed | |
| 12 | F_I386(_NLG_Dispatch2@4) | |
| 13 | F_I386(_NLG_Return@12) | |
| 14 | F_I386(_NLG_Return2) | |
| 15 | _SetWinRTOutOfMemoryExceptionCallback | |
| 16 | __AdjustPointer | |
| 17 | __BuildCatchObject | |
| 18 | __BuildCatchObjectHelper | |
| 19 | F_NON_I386(__C_specific_handler) | |
| 20 | F_NON_I386(__C_specific_handler_noexcept) | |
| 21 | __CxxDetectRethrow | |
| 22 | __CxxExceptionFilter | |
| 23 | __CxxFrameHandler | |
| 24 | __CxxFrameHandler2 | |
| 25 | __CxxFrameHandler3 | |
| 26 | F_I386(__CxxLongjmpUnwind@4) | |
| 27 | __CxxQueryExceptionSize | |
| 28 | __CxxRegisterExceptionObject | |
| 29 | __CxxUnregisterExceptionObject | |
| 30 | __DestructExceptionObject | |
| 31 | __FrameUnwindFilter | |
| 32 | __GetPlatformExceptionInfo | |
| 33 | F_NON_I386(__NLG_Dispatch2) | |
| 34 | F_NON_I386(__NLG_Return2) | |
| 35 | __RTCastToVoid | |
| 36 | __RTDynamicCast | |
| 37 | __RTtypeid | |
| 38 | __TypeMatch | |
| 39 | __current_exception | |
| 40 | __current_exception_context | |
| 41 | F_NON_ARM64(__intrinsic_setjmp) | |
| 42 | F_NON_I386(__intrinsic_setjmpex) | |
| 43 | F_ARM32(__jump_unwind) | |
| 44 | __processing_throw | |
| 45 | __report_gsfailure | |
| 46 | __std_exception_copy | |
| 47 | __std_exception_destroy | |
| 48 | __std_terminate | |
| 49 | __std_type_info_compare | |
| 50 | __std_type_info_destroy_list | |
| 51 | __std_type_info_hash | |
| 52 | __std_type_info_name | |
| 53 | __telemetry_main_invoke_trigger | |
| 54 | __telemetry_main_return_trigger | |
| 55 | __unDName | |
| 56 | __unDNameEx | |
| 57 | __uncaught_exception | |
| 58 | __uncaught_exceptions | |
| 59 | __vcrt_GetModuleFileNameW | |
| 60 | __vcrt_GetModuleHandleW | |
| 61 | __vcrt_InitializeCriticalSectionEx | |
| 62 | __vcrt_LoadLibraryExW | |
| 63 | F_I386(_chkesp) | |
| 64 | F_I386(_except_handler2) | |
| 65 | F_I386(_except_handler3) | |
| 66 | F_I386(_except_handler4_common) | |
| 67 | _get_purecall_handler | |
| 68 | _get_unexpected | |
| 69 | F_I386(_global_unwind2) | |
| 70 | _is_exception_typeof | |
| 71 | F64(_local_unwind) | |
| 72 | F_I386(_local_unwind2) | |
| 73 | F_I386(_local_unwind4) | |
| 74 | F_I386(_longjmpex) | |
| 75 | _purecall | |
| 76 | F_I386(_seh_longjmp_unwind4@4) | |
| 77 | F_I386(_seh_longjmp_unwind@4) | |
| 78 | _set_purecall_handler | |
| 79 | _set_se_translator | |
| 80 | F_I386(_setjmp3) | |
| 81 | longjmp | |
| 82 | memchr | |
| 83 | memcmp | |
| 84 | memcpy | |
| 85 | memmove | |
| 86 | memset | |
| 87 | set_unexpected | |
| 88 | strchr | |
| 89 | strrchr | |
| 90 | strstr | |
| 91 | unexpected | |
| 92 | wcschr | |
| 93 | wcsrchr | |
| 94 | wcsstr | |
| 5 | #include "vcruntime140-common.def.in" |
lib/libc/mingw/lib32/dxva2.def+1| ... | ... | @@ -8,6 +8,7 @@ EXPORTS |
| 8 | 8 | CapabilitiesRequestAndCapabilitiesReply@12 |
| 9 | 9 | DXVA2CreateDirect3DDeviceManager9@8 |
| 10 | 10 | DXVA2CreateVideoService@12 |
| 11 | DXVAHD_CreateDevice@20 | |
| 11 | 12 | DegaussMonitor@4 |
| 12 | 13 | DestroyPhysicalMonitor@4 |
| 13 | 14 | DestroyPhysicalMonitors@8 |
lib/libc/mingw/lib32/kernel32.def+6-1| ... | ... | @@ -30,6 +30,7 @@ AddVectoredContinueHandler@8 |
| 30 | 30 | AddVectoredExceptionHandler@8 |
| 31 | 31 | AdjustCalendarDate@12 |
| 32 | 32 | AllocConsole@0 |
| 33 | AllocConsoleWithOptions@8 | |
| 33 | 34 | AllocateUserPhysicalPages@12 |
| 34 | 35 | AllocateUserPhysicalPagesNuma@16 |
| 35 | 36 | AppPolicyGetClrCompat@8 |
| ... | ... | @@ -440,6 +441,7 @@ FindVolumeClose@4 |
| 440 | 441 | FindVolumeMountPointClose@4 |
| 441 | 442 | FlsAlloc@4 |
| 442 | 443 | FlsFree@4 |
| 444 | FlsGetValue2@4 | |
| 443 | 445 | FlsGetValue@4 |
| 444 | 446 | FlsSetValue@8 |
| 445 | 447 | FlushConsoleInputBuffer@4 |
| ... | ... | @@ -616,6 +618,7 @@ GetFileAttributesW@4 |
| 616 | 618 | GetFileBandwidthReservation@24 |
| 617 | 619 | GetFileInformationByHandle@8 |
| 618 | 620 | GetFileInformationByHandleEx@16 |
| 621 | GetFileInformationByName@16 | |
| 619 | 622 | GetFileMUIInfo@16 |
| 620 | 623 | GetFileMUIPath@28 |
| 621 | 624 | GetFileSize@8 |
| ... | ... | @@ -1270,6 +1273,7 @@ ReleaseActCtxWorker@4 |
| 1270 | 1273 | ReleaseMutex@4 |
| 1271 | 1274 | ReleaseMutexWhenCallbackReturns@8 |
| 1272 | 1275 | ReleasePackageVirtualizationContext@4 |
| 1276 | ReleasePseudoConsole@4 | |
| 1273 | 1277 | ReleaseSRWLockExclusive@4 |
| 1274 | 1278 | ReleaseSRWLockShared@4 |
| 1275 | 1279 | ReleaseSemaphore@12 |
| ... | ... | @@ -1518,6 +1522,7 @@ Thread32First@8 |
| 1518 | 1522 | Thread32Next@8 |
| 1519 | 1523 | TlsAlloc@0 |
| 1520 | 1524 | TlsFree@4 |
| 1525 | TlsGetValue2@4 | |
| 1521 | 1526 | TlsGetValue@4 |
| 1522 | 1527 | TlsSetValue@8 |
| 1523 | 1528 | Toolhelp32ReadProcessMemory@20 |
| ... | ... | @@ -1605,7 +1610,7 @@ WerRegisterRuntimeExceptionModuleWorker@8 |
| 1605 | 1610 | WerSetFlags@4 |
| 1606 | 1611 | WerSetFlagsWorker@4 |
| 1607 | 1612 | WerUnregisterAdditionalProcess@4 |
| 1608 | WerUnregisterAppLocalDump | |
| 1613 | WerUnregisterAppLocalDump@0 | |
| 1609 | 1614 | WerUnregisterCustomMetadata@4 |
| 1610 | 1615 | WerUnregisterExcludedMemoryBlock@4 |
| 1611 | 1616 | WerUnregisterFile@4 |
lib/libc/mingw/lib64/kernel32.def+5| ... | ... | @@ -24,6 +24,7 @@ AddVectoredContinueHandler |
| 24 | 24 | AddVectoredExceptionHandler |
| 25 | 25 | AdjustCalendarDate |
| 26 | 26 | AllocConsole |
| 27 | AllocConsoleWithOptions | |
| 27 | 28 | AllocateUserPhysicalPages |
| 28 | 29 | AllocateUserPhysicalPagesNuma |
| 29 | 30 | AppPolicyGetClrCompat |
| ... | ... | @@ -446,6 +447,7 @@ FindVolumeMountPointClose |
| 446 | 447 | FlsAlloc |
| 447 | 448 | FlsFree |
| 448 | 449 | FlsGetValue |
| 450 | FlsGetValue2 | |
| 449 | 451 | FlsSetValue |
| 450 | 452 | FlushConsoleInputBuffer |
| 451 | 453 | FlushFileBuffers |
| ... | ... | @@ -625,6 +627,7 @@ GetFileAttributesW |
| 625 | 627 | GetFileBandwidthReservation |
| 626 | 628 | GetFileInformationByHandle |
| 627 | 629 | GetFileInformationByHandleEx |
| 630 | GetFileInformationByName | |
| 628 | 631 | GetFileMUIInfo |
| 629 | 632 | GetFileMUIPath |
| 630 | 633 | GetFileSize |
| ... | ... | @@ -1281,6 +1284,7 @@ ReleaseActCtxWorker |
| 1281 | 1284 | ReleaseMutex |
| 1282 | 1285 | ReleaseMutexWhenCallbackReturns |
| 1283 | 1286 | ReleasePackageVirtualizationContext |
| 1287 | ReleasePseudoConsole | |
| 1284 | 1288 | ReleaseSRWLockExclusive |
| 1285 | 1289 | ReleaseSRWLockShared |
| 1286 | 1290 | ReleaseSemaphore |
| ... | ... | @@ -1542,6 +1546,7 @@ Thread32Next |
| 1542 | 1546 | TlsAlloc |
| 1543 | 1547 | TlsFree |
| 1544 | 1548 | TlsGetValue |
| 1549 | TlsGetValue2 | |
| 1545 | 1550 | TlsSetValue |
| 1546 | 1551 | Toolhelp32ReadProcessMemory |
| 1547 | 1552 | TransactNamedPipe |
lib/libc/mingw/libsrc/wia-uuid.c+1-101| ... | ... | @@ -1,106 +1,6 @@ |
| 1 | 1 | /* unknwn-uuid.c */ |
| 2 | 2 | /* Generate GUIDs for WIA interfaces */ |
| 3 | 3 | |
| 4 | /* All IIDs defined in this file were extracted from | |
| 5 | * HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\ */ | |
| 6 | ||
| 7 | 4 | #define INITGUID |
| 8 | 5 | #include <basetyps.h> |
| 9 | ||
| 10 | // Image types | |
| 11 | DEFINE_GUID(WiaImgFmt_UNDEFINED,0xb96b3ca9,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 12 | DEFINE_GUID(WiaImgFmt_RAWRGB,0xbca48b55,0xf272,0x4371,0xb0,0xf1,0x4a,0x15,0x0d,0x05,0x7b,0xb4); | |
| 13 | DEFINE_GUID(WiaImgFmt_MEMORYBMP,0xb96b3caa,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 14 | DEFINE_GUID(WiaImgFmt_BMP,0xb96b3cab,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 15 | DEFINE_GUID(WiaImgFmt_EMF,0xb96b3cac,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 16 | DEFINE_GUID(WiaImgFmt_WMF,0xb96b3cad,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 17 | DEFINE_GUID(WiaImgFmt_JPEG,0xb96b3cae,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 18 | DEFINE_GUID(WiaImgFmt_PNG,0xb96b3caf,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 19 | DEFINE_GUID(WiaImgFmt_GIF,0xb96b3cb0,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 20 | DEFINE_GUID(WiaImgFmt_TIFF,0xb96b3cb1,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 21 | DEFINE_GUID(WiaImgFmt_EXIF,0xb96b3cb2,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 22 | DEFINE_GUID(WiaImgFmt_PHOTOCD,0xb96b3cb3,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 23 | DEFINE_GUID(WiaImgFmt_FLASHPIX,0xb96b3cb4,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 24 | DEFINE_GUID(WiaImgFmt_ICO,0xb96b3cb5,0x0728,0x11d3,0x9d,0x7b,0x00,0x00,0xf8,0x1e,0xf3,0x2e); | |
| 25 | DEFINE_GUID(WiaImgFmt_CIFF,0x9821a8ab,0x3a7e,0x4215,0x94,0xe0,0xd2,0x7a,0x46,0x0c,0x03,0xb2); | |
| 26 | DEFINE_GUID(WiaImgFmt_PICT,0xa6bc85d8,0x6b3e,0x40ee,0xa9,0x5c,0x25,0xd4,0x82,0xe4,0x1a,0xdc); | |
| 27 | DEFINE_GUID(WiaImgFmt_JPEG2K,0x344ee2b2,0x39db,0x4dde,0x81,0x73,0xc4,0xb7,0x5f,0x8f,0x1e,0x49); | |
| 28 | DEFINE_GUID(WiaImgFmt_JPEG2KX,0x43e14614,0xc80a,0x4850,0xba,0xf3,0x4b,0x15,0x2d,0xc8,0xda,0x27); | |
| 29 | ||
| 30 | // Document and other types | |
| 31 | DEFINE_GUID(WiaImgFmt_RTF,0x573dd6a3,0x4834,0x432d,0xa9,0xb5,0xe1,0x98,0xdd,0x9e,0x89,0x0d); | |
| 32 | DEFINE_GUID(WiaImgFmt_XML,0xb9171457,0xdac8,0x4884,0xb3,0x93,0x15,0xb4,0x71,0xd5,0xf0,0x7e); | |
| 33 | DEFINE_GUID(WiaImgFmt_HTML,0xc99a4e62,0x99de,0x4a94,0xac,0xca,0x71,0x95,0x6a,0xc2,0x97,0x7d); | |
| 34 | DEFINE_GUID(WiaImgFmt_TXT,0xfafd4d82,0x723f,0x421f,0x93,0x18,0x30,0x50,0x1a,0xc4,0x4b,0x59); | |
| 35 | DEFINE_GUID(WiaImgFmt_MPG,0xecd757e4,0xd2ec,0x4f57,0x95,0x5d,0xbc,0xf8,0xa9,0x7c,0x4e,0x52); | |
| 36 | DEFINE_GUID(WiaImgFmt_AVI,0x32f8ca14,0x087c,0x4908,0xb7,0xc4,0x67,0x57,0xfe,0x7e,0x90,0xab); | |
| 37 | DEFINE_GUID(WiaImgFmt_ASF,0x8d948ee9,0xd0aa,0x4a12,0x9d,0x9a,0x9c,0xc5,0xde,0x36,0x19,0x9b); | |
| 38 | DEFINE_GUID(WiaImgFmt_SCRIPT,0xfe7d6c53,0x2dac,0x446a,0xb0,0xbd,0xd7,0x3e,0x21,0xe9,0x24,0xc9); | |
| 39 | DEFINE_GUID(WiaImgFmt_EXEC,0x485da097,0x141e,0x4aa5,0xbb,0x3b,0xa5,0x61,0x8d,0x95,0xd0,0x2b); | |
| 40 | DEFINE_GUID(WiaImgFmt_UNICODE16,0x1b7639b6,0x6357,0x47d1,0x9a,0x07,0x12,0x45,0x2d,0xc0,0x73,0xe9); | |
| 41 | DEFINE_GUID(WiaImgFmt_DPOF,0x369eeeab,0xa0e8,0x45ca,0x86,0xa6,0xa8,0x3c,0xe5,0x69,0x7e,0x28); | |
| 42 | ||
| 43 | // Audio types | |
| 44 | DEFINE_GUID(WiaAudFmt_WAV,0xf818e146,0x07af,0x40ff,0xae,0x55,0xbe,0x8f,0x2c,0x06,0x5d,0xbe); | |
| 45 | DEFINE_GUID(WiaAudFmt_MP3,0x0fbc71fb,0x43bf,0x49f2,0x91,0x90,0xe6,0xfe,0xcf,0xf3,0x7e,0x54); | |
| 46 | DEFINE_GUID(WiaAudFmt_AIFF,0x66e2bf4f,0xb6fc,0x443f,0x94,0xc8,0x2f,0x33,0xc8,0xa6,0x5a,0xaf); | |
| 47 | DEFINE_GUID(WiaAudFmt_WMA,0xd61d6413,0x8bc2,0x438f,0x93,0xad,0x21,0xbd,0x48,0x4d,0xb6,0xa1); | |
| 48 | ||
| 49 | // Event GUIDs | |
| 50 | DEFINE_GUID(WIA_EVENT_DEVICE_DISCONNECTED,0x143e4e83,0x6497,0x11d2,0xa2,0x31,0x00,0xc0,0x4f,0xa3,0x18,0x09); | |
| 51 | DEFINE_GUID(WIA_EVENT_DEVICE_CONNECTED,0xa28bbade,0x64b6,0x11d2,0xa2,0x31,0x00,0xc0,0x4f,0xa3,0x18,0x09); | |
| 52 | DEFINE_GUID(WIA_EVENT_ITEM_DELETED,0x1d22a559,0xe14f,0x11d2,0xb3,0x26,0x00,0xc0,0x4f,0x68,0xce,0x61); | |
| 53 | DEFINE_GUID(WIA_EVENT_ITEM_CREATED,0x4c8f4ef5,0xe14f,0x11d2,0xb3,0x26,0x00,0xc0,0x4f,0x68,0xce,0x61); | |
| 54 | DEFINE_GUID(WIA_EVENT_TREE_UPDATED,0xc9859b91,0x4ab2,0x4cd6,0xa1,0xfc,0x58,0x2e,0xec,0x55,0xe5,0x85); | |
| 55 | DEFINE_GUID(WIA_EVENT_VOLUME_INSERT,0x9638bbfd,0xd1bd,0x11d2,0xb3,0x1f,0x00,0xc0,0x4f,0x68,0xce,0x61); | |
| 56 | DEFINE_GUID(WIA_EVENT_SCAN_IMAGE,0xa6c5a715,0x8c6e,0x11d2,0x97,0x7a,0x00,0x00,0xf8,0x7a,0x92,0x6f); | |
| 57 | DEFINE_GUID(WIA_EVENT_SCAN_PRINT_IMAGE,0xb441f425,0x8c6e,0x11d2,0x97,0x7a,0x00,0x00,0xf8,0x7a,0x92,0x6f); | |
| 58 | DEFINE_GUID(WIA_EVENT_SCAN_FAX_IMAGE,0xc00eb793,0x8c6e,0x11d2,0x97,0x7a,0x00,0x00,0xf8,0x7a,0x92,0x6f); | |
| 59 | DEFINE_GUID(WIA_EVENT_SCAN_OCR_IMAGE,0x9d095b89,0x37d6,0x4877,0xaf,0xed,0x62,0xa2,0x97,0xdc,0x6d,0xbe); | |
| 60 | DEFINE_GUID(WIA_EVENT_SCAN_EMAIL_IMAGE,0xc686dcee,0x54f2,0x419e,0x9a,0x27,0x2f,0xc7,0xf2,0xe9,0x8f,0x9e); | |
| 61 | DEFINE_GUID(WIA_EVENT_SCAN_FILM_IMAGE,0x9b2b662c,0x6185,0x438c,0xb6,0x8b,0xe3,0x9e,0xe2,0x5e,0x71,0xcb); | |
| 62 | DEFINE_GUID(WIA_EVENT_SCAN_IMAGE2,0xfc4767c1,0xc8b3,0x48a2,0x9c,0xfa,0x2e,0x90,0xcb,0x3d,0x35,0x90); | |
| 63 | DEFINE_GUID(WIA_EVENT_SCAN_IMAGE3,0x154e27be,0xb617,0x4653,0xac,0xc5,0x0f,0xd7,0xbd,0x4c,0x65,0xce); | |
| 64 | DEFINE_GUID(WIA_EVENT_SCAN_IMAGE4,0xa65b704a,0x7f3c,0x4447,0xa7,0x5d,0x8a,0x26,0xdf,0xca,0x1f,0xdf); | |
| 65 | DEFINE_GUID(WIA_EVENT_STORAGE_CREATED,0x353308b2,0xfe73,0x46c8,0x89,0x5e,0xfa,0x45,0x51,0xcc,0xc8,0x5a); | |
| 66 | DEFINE_GUID(WIA_EVENT_STORAGE_DELETED,0x5e41e75e,0x9390,0x44c5,0x9a,0x51,0xe4,0x70,0x19,0xe3,0x90,0xcf); | |
| 67 | DEFINE_GUID(WIA_EVENT_STI_PROXY,0xd711f81f,0x1f0d,0x422d,0x86,0x41,0x92,0x7d,0x1b,0x93,0xe5,0xe5); | |
| 68 | DEFINE_GUID(WIA_EVENT_CANCEL_IO,0xc860f7b8,0x9ccd,0x41ea,0xbb,0xbf,0x4d,0xd0,0x9c,0x5b,0x17,0x95); | |
| 69 | ||
| 70 | // Power management event GUIDs,sent by the WIA service to drivers | |
| 71 | DEFINE_GUID(WIA_EVENT_POWER_SUSPEND,0xa0922ff9,0xc3b4,0x411c,0x9e,0x29,0x03,0xa6,0x69,0x93,0xd2,0xbe); | |
| 72 | DEFINE_GUID(WIA_EVENT_POWER_RESUME,0x618f153e,0xf686,0x4350,0x96,0x34,0x41,0x15,0xa3,0x04,0x83,0x0c); | |
| 73 | ||
| 74 | // No action handler and prompt handler | |
| 75 | DEFINE_GUID(WIA_EVENT_HANDLER_NO_ACTION,0xe0372b7d,0xe115,0x4525,0xbc,0x55,0xb6,0x29,0xe6,0x8c,0x74,0x5a); | |
| 76 | DEFINE_GUID(WIA_EVENT_HANDLER_PROMPT,0x5f4baad0,0x4d59,0x4fcd,0xb2,0x13,0x78,0x3c,0xe7,0xa9,0x2f,0x22); | |
| 77 | ||
| 78 | // WIA Commands | |
| 79 | DEFINE_GUID(WIA_CMD_SYNCHRONIZE,0x9b26b7b2,0xacad,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 80 | DEFINE_GUID(WIA_CMD_TAKE_PICTURE,0xaf933cac,0xacad,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 81 | DEFINE_GUID(WIA_CMD_DELETE_ALL_ITEMS,0xe208c170,0xacad,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 82 | DEFINE_GUID(WIA_CMD_CHANGE_DOCUMENT,0x04e725b0,0xacae,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 83 | DEFINE_GUID(WIA_CMD_UNLOAD_DOCUMENT,0x1f3b3d8e,0xacae,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 84 | DEFINE_GUID(WIA_CMD_DIAGNOSTIC,0x10ff52f5,0xde04,0x4cf0,0xa5,0xad,0x69,0x1f,0x8d,0xce,0x01,0x41); | |
| 85 | ||
| 86 | DEFINE_GUID(WIA_CMD_DELETE_DEVICE_TREE,0x73815942,0xdbea,0x11d2,0x84,0x16,0x00,0xc0,0x4f,0xa3,0x61,0x45); | |
| 87 | DEFINE_GUID(WIA_CMD_BUILD_DEVICE_TREE,0x9cba5ce0,0xdbea,0x11d2,0x84,0x16,0x00,0xc0,0x4f,0xa3,0x61,0x45); | |
| 88 | ||
| 89 | DEFINE_GUID(IID_IWiaUIExtension,0xDA319113,0x50EE,0x4C80,0xB4,0x60,0x57,0xD0,0x05,0xD4,0x4A,0x2C); | |
| 90 | ||
| 91 | DEFINE_GUID(IID_IWiaDevMgr,0x5eb2502a,0x8cf1,0x11d1,0xbf,0x92,0x00,0x60,0x08,0x1e,0xd8,0x11); | |
| 92 | DEFINE_GUID(IID_IEnumWIA_DEV_INFO,0x5e38b83c,0x8cf1,0x11d1,0xbf,0x92,0x00,0x60,0x08,0x1e,0xd8,0x11); | |
| 93 | DEFINE_GUID(IID_IWiaEventCallback,0xae6287b0,0x0084,0x11d2,0x97,0x3b,0x00,0xa0,0xc9,0x06,0x8f,0x2e); | |
| 94 | DEFINE_GUID(IID_IWiaDataCallback,0xa558a866,0xa5b0,0x11d2,0xa0,0x8f,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 95 | DEFINE_GUID(IID_IWiaDataTransfer,0xa6cef998,0xa5b0,0x11d2,0xa0,0x8f,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 96 | DEFINE_GUID(IID_IWiaItem,0x4db1ad10,0x3391,0x11d2,0x9a,0x33,0x00,0xc0,0x4f,0xa3,0x61,0x45); | |
| 97 | DEFINE_GUID(IID_IWiaPropertyStorage,0x98B5E8A0,0x29CC,0x491a,0xAA,0xC0,0xE6,0xDB,0x4F,0xDC,0xCE,0xB6); | |
| 98 | DEFINE_GUID(IID_IEnumWiaItem,0x5e8383fc,0x3391,0x11d2,0x9a,0x33,0x00,0xc0,0x4f,0xa3,0x61,0x45); | |
| 99 | DEFINE_GUID(IID_IEnumWIA_DEV_CAPS,0x1fcc4287,0xaca6,0x11d2,0xa0,0x93,0x00,0xc0,0x4f,0x72,0xdc,0x3c); | |
| 100 | DEFINE_GUID(IID_IEnumWIA_FORMAT_INFO,0x81BEFC5B,0x656D,0x44f1,0xB2,0x4C,0xD4,0x1D,0x51,0xB4,0xDC,0x81); | |
| 101 | DEFINE_GUID(IID_IWiaLog,0xA00C10B6,0x82A1,0x452f,0x8B,0x6C,0x86,0x06,0x2A,0xAD,0x68,0x90); | |
| 102 | DEFINE_GUID(IID_IWiaLogEx,0xAF1F22AC,0x7A40,0x4787,0xB4,0x21,0xAE,0xb4,0x7A,0x1F,0xBD,0x0B); | |
| 103 | DEFINE_GUID(IID_IWiaNotifyDevMgr,0x70681EA0,0xE7BF,0x4291,0x9F,0xB1,0x4E,0x88,0x13,0xA3,0xF7,0x8E); | |
| 104 | DEFINE_GUID(IID_IWiaItemExtras,0x6291ef2c,0x36ef,0x4532,0x87,0x6a,0x8e,0x13,0x25,0x93,0x77,0x8d); | |
| 105 | DEFINE_GUID(CLSID_WiaDevMgr,0xa1f4e726,0x8cf1,0x11d1,0xbf,0x92,0x00,0x60,0x08,0x1e,0xd8,0x11); | |
| 106 | DEFINE_GUID(CLSID_WiaLog,0xA1E75357,0x881A,0x419e,0x83,0xE2,0xBB,0x16,0xDB,0x19,0x7C,0x68); | |
| 6 | #include <wia.h> |
lib/libc/mingw/math/x86/cossin.c-23| ... | ... | @@ -5,7 +5,6 @@ |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | void sincos (double __x, double *p_sin, double *p_cos); |
| 8 | void sincosl (long double __x, long double *p_sin, long double *p_cos); | |
| 9 | 8 | void sincosf (float __x, float *p_sin, float *p_cos); |
| 10 | 9 | |
| 11 | 10 | void sincos (double __x, double *p_sin, double *p_cos) |
| ... | ... | @@ -51,25 +50,3 @@ void sincosf (float __x, float *p_sin, float *p_cos) |
| 51 | 50 | *p_sin = (float) s; |
| 52 | 51 | *p_cos = (float) c; |
| 53 | 52 | } |
| 54 | ||
| 55 | void sincosl (long double __x, long double *p_sin, long double *p_cos) | |
| 56 | { | |
| 57 | long double c, s; | |
| 58 | ||
| 59 | __asm__ __volatile__ ("fsincos\n\t" | |
| 60 | "fnstsw %%ax\n\t" | |
| 61 | "testl $0x400, %%eax\n\t" | |
| 62 | "jz 1f\n\t" | |
| 63 | "fldpi\n\t" | |
| 64 | "fadd %%st(0)\n\t" | |
| 65 | "fxch %%st(1)\n\t" | |
| 66 | "2: fprem1\n\t" | |
| 67 | "fnstsw %%ax\n\t" | |
| 68 | "testl $0x400, %%eax\n\t" | |
| 69 | "jnz 2b\n\t" | |
| 70 | "fstp %%st(1)\n\t" | |
| 71 | "fsincos\n\t" | |
| 72 | "1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax"); | |
| 73 | *p_sin = s; | |
| 74 | *p_cos = c; | |
| 75 | } |
lib/libc/mingw/math/x86/cossinl.c created+29| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | void sincosl (long double __x, long double *p_sin, long double *p_cos); | |
| 8 | ||
| 9 | void sincosl (long double __x, long double *p_sin, long double *p_cos) | |
| 10 | { | |
| 11 | long double c, s; | |
| 12 | ||
| 13 | __asm__ __volatile__ ("fsincos\n\t" | |
| 14 | "fnstsw %%ax\n\t" | |
| 15 | "testl $0x400, %%eax\n\t" | |
| 16 | "jz 1f\n\t" | |
| 17 | "fldpi\n\t" | |
| 18 | "fadd %%st(0)\n\t" | |
| 19 | "fxch %%st(1)\n\t" | |
| 20 | "2: fprem1\n\t" | |
| 21 | "fnstsw %%ax\n\t" | |
| 22 | "testl $0x400, %%eax\n\t" | |
| 23 | "jnz 2b\n\t" | |
| 24 | "fstp %%st(1)\n\t" | |
| 25 | "fsincos\n\t" | |
| 26 | "1:" : "=t" (c), "=u" (s) : "0" (__x) : "eax"); | |
| 27 | *p_sin = s; | |
| 28 | *p_cos = c; | |
| 29 | } |
lib/libc/mingw/misc/isblank.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #define __NO_CTYPE_LINES | |
| 2 | #include <ctype.h> | |
| 3 | ||
| 4 | int __cdecl isblank (int _C) | |
| 5 | { | |
| 6 | return (_isctype(_C, _BLANK) || _C == '\t'); | |
| 7 | } |
lib/libc/mingw/misc/iswblank.c deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | #define _CRT_WCTYPE_NOINLINE | |
| 2 | #include <ctype.h> | |
| 3 | ||
| 4 | int __cdecl iswblank (wint_t _C) | |
| 5 | { | |
| 6 | return (iswctype(_C, _BLANK) || _C == '\t'); | |
| 7 | } |
lib/libc/mingw/misc/wctob.c+1-1| ... | ... | @@ -25,5 +25,5 @@ int wctob (wint_t wc ) |
| 25 | 25 | 	 || invalid_char) |
| 26 | 26 | return EOF; |
| 27 | 27 | |
| 28 | return (int) c; | |
| 28 | return (unsigned char) c; | |
| 29 | 29 | } |
lib/libc/mingw/misc/wctrans.c deleted-65| ... | ... | @@ -1,65 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | /* | |
| 7 | wctrans.c | |
| 8 | 7.25.3.2 Extensible wide-character case mapping functions | |
| 9 | ||
| 10 | Contributed by: Danny Smith <dannysmith@usesr.sourcefoge.net> | |
| 11 | 		 2005-02-24 | |
| 12 | ||
| 13 | This source code is placed in the PUBLIC DOMAIN. It is modified | |
| 14 | from the Q8 package created by Doug Gwyn <gwyn@arl.mil> | |
| 15 | ||
| 16 | */ | |
| 17 | ||
| 18 | #include <string.h> | |
| 19 | #include <wctype.h> | |
| 20 | ||
| 21 | /* | |
| 22 | This differs from the MS implementation of wctrans which | |
| 23 | returns 0 for tolower and 1 for toupper. According to | |
| 24 | C99, a 0 return value indicates invalid input. | |
| 25 | ||
| 26 | These two function go in the same translation unit so that we | |
| 27 | can ensure that | |
| 28 | towctrans(wc, wctrans("tolower")) == towlower(wc) | |
| 29 | towctrans(wc, wctrans("toupper")) == towupper(wc) | |
| 30 | It also ensures that | |
| 31 | towctrans(wc, wctrans("")) == wc | |
| 32 | which is not required by standard. | |
| 33 | */ | |
| 34 | ||
| 35 | static const struct { | |
| 36 | const char *name; | |
| 37 | wctrans_t val; } tmap[] = { | |
| 38 | {"tolower", _LOWER}, | |
| 39 | {"toupper", _UPPER} | |
| 40 | }; | |
| 41 | ||
| 42 | #define	NTMAP	(sizeof tmap / sizeof tmap[0]) | |
| 43 | ||
| 44 | wctrans_t | |
| 45 | wctrans (const char* property) | |
| 46 | { | |
| 47 | int i; | |
| 48 | for ( i = 0; i < (int) NTMAP; ++i ) | |
| 49 | if (strcmp (property, tmap[i].name) == 0) | |
| 50 | return tmap[i].val; | |
| 51 | return 0; | |
| 52 | } | |
| 53 | ||
| 54 | wint_t towctrans (wint_t wc, wctrans_t desc) | |
| 55 | { | |
| 56 | switch (desc) | |
| 57 | { | |
| 58 | case _LOWER: | |
| 59 | return towlower (wc); | |
| 60 | case _UPPER: | |
| 61 | return towupper (wc); | |
| 62 | default: | |
| 63 | return wc; | |
| 64 | } | |
| 65 | } |
lib/libc/mingw/misc/wctype.c deleted-65| ... | ... | @@ -1,65 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | /* | |
| 7 | wctype.c | |
| 8 | 7.25.2.2.2 The wctype function | |
| 9 | ||
| 10 | Contributed by: Danny Smith <dannysmith@usesr.sourcefoge.net> | |
| 11 | 		 2005-02-24 | |
| 12 | ||
| 13 | This source code is placed in the PUBLIC DOMAIN. It is modified | |
| 14 | from the Q8 package created by Doug Gwyn <gwyn@arl.mil> | |
| 15 | ||
| 16 | The wctype function constructs a value with type wctype_t that | |
| 17 | describes a class of wide characters identified by the string | |
| 18 | argument property. | |
| 19 | ||
| 20 | In particular, we map the property strings so that: | |
| 21 | ||
| 22 | iswctype(wc, wctype("alnum")) == iswalnum(wc) | |
| 23 | iswctype(wc, wctype("alpha")) == iswalpha(wc) | |
| 24 | iswctype(wc, wctype("cntrl")) == iswcntrl(wc) | |
| 25 | iswctype(wc, wctype("digit")) == iswdigit(wc) | |
| 26 | iswctype(wc, wctype("graph")) == iswgraph(wc) | |
| 27 | iswctype(wc, wctype("lower")) == iswlower(wc) | |
| 28 | iswctype(wc, wctype("print")) == iswprint(wc) | |
| 29 | iswctype(wc, wctype("punct")) == iswpunct(wc) | |
| 30 | iswctype(wc, wctype("space")) == iswspace(wc) | |
| 31 | iswctype(wc, wctype("upper")) == iswupper(wc) | |
| 32 | iswctype(wc, wctype("xdigit")) == iswxdigit(wc) | |
| 33 | ||
| 34 | */ | |
| 35 | ||
| 36 | #include	<string.h> | |
| 37 | #include	<wctype.h> | |
| 38 | ||
| 39 | /* Using the bit-OR'd ctype character classification flags as return | |
| 40 | values achieves compatibility with MS iswctype(). */ | |
| 41 | static const struct { | |
| 42 | const char *name; | |
| 43 | wctype_t flags;} cmap[] = { | |
| 44 | {"alnum", _ALPHA|_DIGIT}, | |
| 45 | {"alpha", _ALPHA}, | |
| 46 | {"cntrl", _CONTROL}, | |
| 47 | {"digit", _DIGIT}, | |
| 48 | {"graph", _PUNCT|_ALPHA|_DIGIT}, | |
| 49 | {"lower", _LOWER}, | |
| 50 | {"print", _BLANK|_PUNCT|_ALPHA|_DIGIT}, | |
| 51 | {"punct", _PUNCT}, | |
| 52 | {"space", _SPACE}, | |
| 53 | {"upper", _UPPER}, | |
| 54 | {"xdigit", _HEX} | |
| 55 | }; | |
| 56 | ||
| 57 | #define NCMAP	(sizeof cmap / sizeof cmap[0]) | |
| 58 | wctype_t wctype (const char *property) | |
| 59 | { | |
| 60 | int i; | |
| 61 | for (i = 0; i < (int) NCMAP; ++i) | |
| 62 | if (strcmp (property, cmap[i].name) == 0) | |
| 63 | return cmap[i].flags; | |
| 64 | return 0; | |
| 65 | } |
lib/libc/mingw/stdio/mingw_fprintfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_fprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_fwprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_fprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_pformat.h+9-2| ... | ... | @@ -72,13 +72,20 @@ |
| 72 | 72 | |
| 73 | 73 | # define __printf __mingw_wprintf |
| 74 | 74 | # define __fprintf __mingw_fwprintf |
| 75 | # define __sprintf __mingw_swprintf | |
| 75 | #ifdef __BUILD_WIDEAPI_ISO | |
| 76 | # define __snprintf __mingw_swprintf | |
| 77 | #else | |
| 76 | 78 | # define __snprintf __mingw_snwprintf |
| 79 | #endif | |
| 77 | 80 | |
| 78 | 81 | # define __vprintf __mingw_vwprintf |
| 79 | 82 | # define __vfprintf __mingw_vfwprintf |
| 80 | # define __vsprintf __mingw_vswprintf | |
| 83 | #ifdef __BUILD_WIDEAPI_ISO | |
| 84 | # define __vsnprintf __mingw_vswprintf | |
| 85 | #else | |
| 81 | 86 | # define __vsnprintf __mingw_vsnwprintf |
| 87 | #endif | |
| 88 | ||
| 82 | 89 | #else |
| 83 | 90 | # define __pformat __mingw_pformat |
| 84 | 91 | #define __fputc(X,STR) fputc((X), (STR)) |
lib/libc/mingw/stdio/mingw_pformatw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_pformat.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_printfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_printf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_sformat.c created+1602| ... | ... | @@ -0,0 +1,1602 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #define __LARGE_MBSTATE_T | |
| 46 | ||
| 47 | #include <limits.h> | |
| 48 | #include <stddef.h> | |
| 49 | #include <stdarg.h> | |
| 50 | #include <stdio.h> | |
| 51 | #include <stdint.h> | |
| 52 | #include <stdlib.h> | |
| 53 | #include <string.h> | |
| 54 | #include <wchar.h> | |
| 55 | #include <ctype.h> | |
| 56 | #include <wctype.h> | |
| 57 | #include <locale.h> | |
| 58 | #include <errno.h> | |
| 59 | ||
| 60 | #include "mingw_sformat.h" | |
| 61 | ||
| 62 | /* Helper flags for conversion. */ | |
| 63 | #define IS_C		0x0001 | |
| 64 | #define IS_S		0x0002 | |
| 65 | #define IS_L		0x0004 | |
| 66 | #define IS_LL		0x0008 | |
| 67 | #define IS_SIGNED_NUM	0x0010 | |
| 68 | #define IS_POINTER	0x0020 | |
| 69 | #define IS_HEX_FLOAT	0x0040 | |
| 70 | #define IS_SUPPRESSED	0x0080 | |
| 71 | #define USE_GROUP	0x0100 | |
| 72 | #define USE_GNU_ALLOC	0x0200 | |
| 73 | #define USE_POSIX_ALLOC	0x0400 | |
| 74 | ||
| 75 | #define IS_ALLOC_USED	(USE_GNU_ALLOC | USE_POSIX_ALLOC) | |
| 76 | ||
| 77 | static void * | |
| 78 | get_va_nth (va_list argp, unsigned int n) | |
| 79 | { | |
| 80 | va_list ap; | |
| 81 | if (!n) abort (); | |
| 82 | va_copy (ap, argp); | |
| 83 | while (--n > 0) | |
| 84 | (void) va_arg(ap, void *); | |
| 85 | return va_arg (ap, void *); | |
| 86 | } | |
| 87 | ||
| 88 | static void | |
| 89 | optimize_alloc (char **p, char *end, size_t alloc_sz) | |
| 90 | { | |
| 91 | size_t need_sz; | |
| 92 | char *h; | |
| 93 | ||
| 94 | if (!p || !*p) | |
| 95 | return; | |
| 96 | ||
| 97 | need_sz = end - *p; | |
| 98 | if (need_sz == alloc_sz) | |
| 99 | return; | |
| 100 | ||
| 101 | if ((h = (char *) realloc (*p, need_sz)) != NULL) | |
| 102 | *p = h; | |
| 103 | } | |
| 104 | ||
| 105 | static void | |
| 106 | back_ch (int c, _IFP *s, size_t *rin, int not_eof) | |
| 107 | { | |
| 108 | if (!not_eof && c == EOF) | |
| 109 | return; | |
| 110 | if (s->is_string == 0) | |
| 111 | { | |
| 112 | FILE *fp = s->fp; | |
| 113 | ungetc (c, fp); | |
| 114 | rin[0] -= 1; | |
| 115 | return; | |
| 116 | } | |
| 117 | rin[0] -= 1; | |
| 118 | s->bch[s->back_top] = c; | |
| 119 | s->back_top += 1; | |
| 120 | } | |
| 121 | ||
| 122 | static int | |
| 123 | in_ch (_IFP *s, size_t *rin) | |
| 124 | { | |
| 125 | int r; | |
| 126 | if (s->back_top) | |
| 127 | { | |
| 128 | s->back_top -= 1; | |
| 129 | r = s->bch[s->back_top]; | |
| 130 | rin[0] += 1; | |
| 131 | } | |
| 132 | else if (s->seen_eof) | |
| 133 | { | |
| 134 | return EOF; | |
| 135 | } | |
| 136 | else if (s->is_string) | |
| 137 | { | |
| 138 | const char *ps = s->str; | |
| 139 | r = ((int) *ps) & 0xff; | |
| 140 | ps++; | |
| 141 | if (r != 0) | |
| 142 | { | |
| 143 | rin[0] += 1; | |
| 144 | s->str = ps; | |
| 145 | return r; | |
| 146 | } | |
| 147 | s->seen_eof = 1; | |
| 148 | return EOF; | |
| 149 | } | |
| 150 | else | |
| 151 | { | |
| 152 | FILE *fp = (FILE *) s->fp; | |
| 153 | r = getc (fp); | |
| 154 | if (r != EOF) | |
| 155 | rin[0] += 1; | |
| 156 | else s->seen_eof = 1; | |
| 157 | } | |
| 158 | return r; | |
| 159 | } | |
| 160 | ||
| 161 | static int | |
| 162 | match_string (_IFP *s, size_t *rin, int *c, const char *str) | |
| 163 | { | |
| 164 | int ch = *c; | |
| 165 | ||
| 166 | if (*str == 0) | |
| 167 | return 1; | |
| 168 | ||
| 169 | if (*str != (char) tolower (ch)) | |
| 170 | return 0; | |
| 171 | ++str; | |
| 172 | while (*str != 0) | |
| 173 | { | |
| 174 | if ((ch = in_ch (s, rin)) == EOF) | |
| 175 | { | |
| 176 | c[0] = ch; | |
| 177 | return 0; | |
| 178 | } | |
| 179 | ||
| 180 | if (*str != (char) tolower (ch)) | |
| 181 | { | |
| 182 | c[0] = ch; | |
| 183 | return 0; | |
| 184 | } | |
| 185 | ++str; | |
| 186 | } | |
| 187 | c[0] = ch; | |
| 188 | return 1; | |
| 189 | } | |
| 190 | ||
| 191 | struct gcollect | |
| 192 | { | |
| 193 | size_t count; | |
| 194 | struct gcollect *next; | |
| 195 | char **ptrs[32]; | |
| 196 | }; | |
| 197 | ||
| 198 | static void | |
| 199 | release_ptrs (struct gcollect **pt, char **wbuf) | |
| 200 | { | |
| 201 | struct gcollect *pf; | |
| 202 | size_t cnt; | |
| 203 | ||
| 204 | if (wbuf) | |
| 205 | { | |
| 206 | free (*wbuf); | |
| 207 | *wbuf = NULL; | |
| 208 | } | |
| 209 | if (!pt || (pf = *pt) == NULL) | |
| 210 | return; | |
| 211 | while (pf != NULL) | |
| 212 | { | |
| 213 | struct gcollect *pf_sv = pf; | |
| 214 | for (cnt = 0; cnt < pf->count; ++cnt) | |
| 215 | 	{ | |
| 216 | 	 free (*pf->ptrs[cnt]); | |
| 217 | 	 *pf->ptrs[cnt] = NULL; | |
| 218 | 	} | |
| 219 | pf = pf->next; | |
| 220 | free (pf_sv); | |
| 221 | } | |
| 222 | *pt = NULL; | |
| 223 | } | |
| 224 | ||
| 225 | static int | |
| 226 | cleanup_return (int rval, struct gcollect **pfree, char **strp, char **wbuf) | |
| 227 | { | |
| 228 | if (rval == EOF) | |
| 229 | release_ptrs (pfree, wbuf); | |
| 230 | else | |
| 231 | { | |
| 232 | if (pfree) | |
| 233 | { | |
| 234 | struct gcollect *pf = *pfree, *pf_sv; | |
| 235 | while (pf != NULL) | |
| 236 | { | |
| 237 | pf_sv = pf; | |
| 238 | pf = pf->next; | |
| 239 | free (pf_sv); | |
| 240 | } | |
| 241 | *pfree = NULL; | |
| 242 | } | |
| 243 | if (strp != NULL) | |
| 244 | 	{ | |
| 245 | 	 free (*strp); | |
| 246 | 	 *strp = NULL; | |
| 247 | 	} | |
| 248 | if (wbuf) | |
| 249 | 	{ | |
| 250 | 	 free (*wbuf); | |
| 251 | 	 *wbuf = NULL; | |
| 252 | 	} | |
| 253 | } | |
| 254 | return rval; | |
| 255 | } | |
| 256 | ||
| 257 | static struct gcollect * | |
| 258 | resize_gcollect (struct gcollect *pf) | |
| 259 | { | |
| 260 | struct gcollect *np; | |
| 261 | if (pf && pf->count < 32) | |
| 262 | return pf; | |
| 263 | np = malloc (sizeof (struct gcollect)); | |
| 264 | np->count = 0; | |
| 265 | np->next = pf; | |
| 266 | return np; | |
| 267 | } | |
| 268 | ||
| 269 | static char * | |
| 270 | resize_wbuf (size_t wpsz, size_t *wbuf_max_sz, char *old) | |
| 271 | { | |
| 272 | char *wbuf; | |
| 273 | size_t nsz; | |
| 274 | if (*wbuf_max_sz != wpsz) | |
| 275 | return old; | |
| 276 | nsz = (256 > (2 * wbuf_max_sz[0]) ? 256 : (2 * wbuf_max_sz[0])); | |
| 277 | if (!old) | |
| 278 | wbuf = (char *) malloc (nsz); | |
| 279 | else | |
| 280 | wbuf = (char *) realloc (old, nsz); | |
| 281 | if (!wbuf) | |
| 282 | { | |
| 283 | if (old) | |
| 284 | free (old); | |
| 285 | } | |
| 286 | else | |
| 287 | *wbuf_max_sz = nsz; | |
| 288 | return wbuf; | |
| 289 | } | |
| 290 | ||
| 291 | int | |
| 292 | __cdecl | |
| 293 | __mingw_sformat (_IFP *s, const char *format, va_list argp) | |
| 294 | { | |
| 295 | const char *f = format; | |
| 296 | struct gcollect *gcollect = NULL; | |
| 297 | size_t read_in = 0, wbuf_max_sz = 0, cnt; | |
| 298 | ssize_t str_sz = 0; | |
| 299 | char *str = NULL, **pstr = NULL, *wbuf = NULL; | |
| 300 | wchar_t *wstr = NULL; | |
| 301 | int rval = 0, c = 0, ignore_ws = 0; | |
| 302 | va_list arg; | |
| 303 | unsigned char fc; | |
| 304 | unsigned int npos; | |
| 305 | int width, flags, base = 0, errno_sv; | |
| 306 | size_t wbuf_cur_sz, read_in_sv, new_sz, n; | |
| 307 | char seen_dot, seen_exp, is_neg, not_in; | |
| 308 | char *tmp_wbuf_ptr, buf[MB_LEN_MAX]; | |
| 309 | const char *lc_decimal_point, *lc_thousands_sep; | |
| 310 | mbstate_t state, cstate; | |
| 311 | union { | |
| 312 | unsigned long long ull; | |
| 313 | unsigned long ul; | |
| 314 | long long ll; | |
| 315 | long l; | |
| 316 | } cv_val; | |
| 317 | ||
| 318 | arg = argp; | |
| 319 | ||
| 320 | if (!s || s->fp == NULL || !format) | |
| 321 | { | |
| 322 | errno = EINVAL; | |
| 323 | return EOF; | |
| 324 | } | |
| 325 | ||
| 326 | memset (&state, 0, sizeof (state)); | |
| 327 | ||
| 328 | lc_decimal_point = localeconv()->decimal_point; | |
| 329 | lc_thousands_sep = localeconv()->thousands_sep; | |
| 330 | if (lc_thousands_sep != NULL && *lc_thousands_sep == 0) | |
| 331 | lc_thousands_sep = NULL; | |
| 332 | ||
| 333 | while (*f != 0) | |
| 334 | { | |
| 335 | if (!isascii ((unsigned char) *f)) | |
| 336 | 	{ | |
| 337 | 	 int len; | |
| 338 | ||
| 339 | 	 if ((len = mbrlen (f, strlen (f), &state)) > 0) | |
| 340 | 	 { | |
| 341 | 	 do | |
| 342 | 		{ | |
| 343 | 		 if ((c = in_ch (s, &read_in)) == EOF || c != (unsigned char) *f++) | |
| 344 | 		 { | |
| 345 | 		 back_ch (c, s, &read_in, 1); | |
| 346 | 		 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 347 | 		 } | |
| 348 | 		} | |
| 349 | 	 while (--len > 0); | |
| 350 | ||
| 351 | 	 continue; | |
| 352 | 	 } | |
| 353 | 	} | |
| 354 | ||
| 355 | fc = *f++; | |
| 356 | if (fc != '%') | |
| 357 | { | |
| 358 | if (isspace (fc)) | |
| 359 | ignore_ws = 1; | |
| 360 | else | |
| 361 | 	 { | |
| 362 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 363 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 364 | ||
| 365 | 	 if (ignore_ws) | |
| 366 | 		{ | |
| 367 | 		 ignore_ws = 0; | |
| 368 | 		 if (isspace (c)) | |
| 369 | 		 { | |
| 370 | 		 do | |
| 371 | 			{ | |
| 372 | 			 if ((c = in_ch (s, &read_in)) == EOF) | |
| 373 | 			 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 374 | 			} | |
| 375 | 		 while (isspace (c)); | |
| 376 | 		 } | |
| 377 | 		} | |
| 378 | ||
| 379 | 	 if (c != fc) | |
| 380 | 		{ | |
| 381 | 		 back_ch (c, s, &read_in, 0); | |
| 382 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 383 | 		} | |
| 384 | 	 } | |
| 385 | ||
| 386 | 	 continue; | |
| 387 | 	} | |
| 388 | ||
| 389 | width = flags = 0; | |
| 390 | npos = 0; | |
| 391 | wbuf_cur_sz = 0; | |
| 392 | ||
| 393 | if (isdigit ((unsigned char) *f)) | |
| 394 | 	{ | |
| 395 | 	 const char *svf = f; | |
| 396 | 	 npos = (unsigned char) *f++ - '0'; | |
| 397 | 	 while (isdigit ((unsigned char) *f)) | |
| 398 | 	 npos = npos * 10 + ((unsigned char) *f++ - '0'); | |
| 399 | 	 if (*f != '$') | |
| 400 | 	 { | |
| 401 | 	 npos = 0; | |
| 402 | 	 f = svf; | |
| 403 | 	 } | |
| 404 | 	 else | |
| 405 | 	 f++; | |
| 406 | 	} | |
| 407 | ||
| 408 | do | |
| 409 | 	{ | |
| 410 | 	 if (*f == '*') | |
| 411 | 	 flags |= IS_SUPPRESSED; | |
| 412 | 	 else if (*f == '\'') | |
| 413 | 	 { | |
| 414 | 	 if (lc_thousands_sep) | |
| 415 | 		flags |= USE_GROUP; | |
| 416 | 	 } | |
| 417 | 	 else if (*f == 'I') | |
| 418 | 	 { | |
| 419 | 	 /* we don't support locale's digits (i18N), but ignore it for now silently. */ | |
| 420 | 	 ; | |
| 421 | #ifdef _WIN32 | |
| 422 | if (f[1] == '6' && f[2] == '4') | |
| 423 | { | |
| 424 | 		 flags |= IS_LL | IS_L; | |
| 425 | 		 f += 2; | |
| 426 | 		} | |
| 427 | 	 else if (f[1] == '3' && f[2] == '2') | |
| 428 | 		{ | |
| 429 | 		 flags |= IS_L; | |
| 430 | 		 f += 2; | |
| 431 | 		} | |
| 432 | 	 else | |
| 433 | 	 { | |
| 434 | #ifdef _WIN64 | |
| 435 | 		 flags |= IS_LL | IS_L; | |
| 436 | #else | |
| 437 | 		 flags |= IS_L; | |
| 438 | #endif | |
| 439 | 		} | |
| 440 | #endif | |
| 441 | 	 } | |
| 442 | 	 else | |
| 443 | 	 break; | |
| 444 | 	 ++f; | |
| 445 | } | |
| 446 | while (1); | |
| 447 | ||
| 448 | while (isdigit ((unsigned char) *f)) | |
| 449 | 	width = width * 10 + ((unsigned char) *f++ - '0'); | |
| 450 | ||
| 451 | if (!width) | |
| 452 | 	width = -1; | |
| 453 | ||
| 454 | switch (*f) | |
| 455 | 	{ | |
| 456 | 	case 'h': | |
| 457 | 	 ++f; | |
| 458 | 	 flags |= (*f == 'h' ? IS_C : IS_S); | |
| 459 | 	 if (*f == 'h') | |
| 460 | 	 ++f; | |
| 461 | 	 break; | |
| 462 | 	case 'l': | |
| 463 | 	 ++f; | |
| 464 | 	 flags |= (*f == 'l' ? IS_LL : 0) | IS_L; | |
| 465 | 	 if (*f == 'l') | |
| 466 | 	 ++f; | |
| 467 | 	 break; | |
| 468 | 	case 'q': case 'L': | |
| 469 | 	 ++f; | |
| 470 | 	 flags |= IS_LL | IS_L; | |
| 471 | 	 break; | |
| 472 | 	case 'a': | |
| 473 | 	 if (f[1] != 's' && f[1] != 'S' && f[1] != '[') | |
| 474 | 	 break; | |
| 475 | 	 ++f; | |
| 476 | 	 flags |= USE_GNU_ALLOC; | |
| 477 | 	 break; | |
| 478 | 	case 'm': | |
| 479 | 	 flags |= USE_POSIX_ALLOC; | |
| 480 | 	 ++f; | |
| 481 | 	 if (*f == 'l') | |
| 482 | 	 { | |
| 483 | 	 flags |= IS_L; | |
| 484 | 	 f++; | |
| 485 | 	 } | |
| 486 | 	 break; | |
| 487 | 	case 'z': | |
| 488 | #ifdef _WIN64 | |
| 489 | 	 flags |= IS_LL | IS_L; | |
| 490 | #else | |
| 491 | 	 flags |= IS_L; | |
| 492 | #endif | |
| 493 | 	 ++f; | |
| 494 | 	 break; | |
| 495 | 	case 'j': | |
| 496 | 	 if (sizeof (uintmax_t) > sizeof (unsigned long)) | |
| 497 | 	 flags |= IS_LL; | |
| 498 | 	 else if (sizeof (uintmax_t) > sizeof (unsigned int)) | |
| 499 | 	 flags |= IS_L; | |
| 500 | 	 ++f; | |
| 501 | 	 break; | |
| 502 | 	case 't': | |
| 503 | #ifdef _WIN64 | |
| 504 | 	 flags |= IS_LL; | |
| 505 | #else | |
| 506 | 	 flags |= IS_L; | |
| 507 | #endif | |
| 508 | 	 ++f; | |
| 509 | 	 break; | |
| 510 | 	case 0: | |
| 511 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 512 | 	default: | |
| 513 | 	 break; | |
| 514 | 	} | |
| 515 | ||
| 516 | if (*f == 0) | |
| 517 | 	return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 518 | ||
| 519 | fc = *f++; | |
| 520 | if (ignore_ws || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n')) | |
| 521 | 	{ | |
| 522 | 	 errno_sv = errno; | |
| 523 | 	 errno = 0; | |
| 524 | 	 do | |
| 525 | 	 { | |
| 526 | 	 if ((c == EOF || (c = in_ch (s, &read_in)) == EOF) | |
| 527 | 	 && errno == EINTR) | |
| 528 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 529 | 	 } | |
| 530 | 	 while (isspace (c)); | |
| 531 | ||
| 532 | 	 ignore_ws = 0; | |
| 533 | 	 errno = errno_sv; | |
| 534 | 	 back_ch (c, s, &read_in, 0); | |
| 535 | 	} | |
| 536 | ||
| 537 | switch (fc) | |
| 538 | { | |
| 539 | case 'c': | |
| 540 | if ((flags & IS_L) != 0) | |
| 541 | fc = 'C'; | |
| 542 | break; | |
| 543 | case 's': | |
| 544 | if ((flags & IS_L) != 0) | |
| 545 | fc = 'S'; | |
| 546 | break; | |
| 547 | } | |
| 548 | ||
| 549 | switch (fc) | |
| 550 | 	{ | |
| 551 | 	case '%': | |
| 552 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 553 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 554 | 	 if (c != fc) | |
| 555 | 	 { | |
| 556 | 	 back_ch (c, s, &read_in, 1); | |
| 557 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 558 | 	 } | |
| 559 | 	 break; | |
| 560 | ||
| 561 | 	case 'n': | |
| 562 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 563 | 	 { | |
| 564 | 	 if ((flags & IS_LL) != 0) | |
| 565 | 		*(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = read_in; | |
| 566 | 	 else if ((flags & IS_L) != 0) | |
| 567 | 		*(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = read_in; | |
| 568 | 	 else if ((flags & IS_S) != 0) | |
| 569 | 		*(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = read_in; | |
| 570 | 	 else if ((flags & IS_C) != 0) | |
| 571 | 	 *(npos != 0 ? (char *) get_va_nth (argp, npos) : va_arg (arg, char *)) = read_in; | |
| 572 | 	 else | |
| 573 | 		*(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = read_in; | |
| 574 | 	 } | |
| 575 | 	 break; | |
| 576 | ||
| 577 | 	case 'c': | |
| 578 | 	 if (width == -1) | |
| 579 | 	 width = 1; | |
| 580 | ||
| 581 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 582 | 	 { | |
| 583 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 584 | 		{ | |
| 585 | 		 if (npos != 0) | |
| 586 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 587 | 		 else | |
| 588 | 		 pstr = va_arg (arg, char **); | |
| 589 | ||
| 590 | 		 if (!pstr) | |
| 591 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 592 | ||
| 593 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 594 | 		 if ((str = *pstr = (char *) malloc (str_sz)) == NULL) | |
| 595 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 596 | ||
| 597 | 		 gcollect = resize_gcollect (gcollect); | |
| 598 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 599 | 		} | |
| 600 | 	 else | |
| 601 | 		{ | |
| 602 | 		 if (npos != 0) | |
| 603 | 		 str = (char *) get_va_nth (argp, npos); | |
| 604 | 		 else | |
| 605 | 		 str = va_arg (arg, char *); | |
| 606 | 		 if (!str) | |
| 607 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 608 | 		} | |
| 609 | 	 } | |
| 610 | ||
| 611 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 612 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 613 | ||
| 614 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 615 | 	 { | |
| 616 | 	 do | |
| 617 | 		{ | |
| 618 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 619 | 		 { | |
| 620 | 		 new_sz = str_sz + (str_sz >= width ? width - 1 : str_sz); | |
| 621 | 		 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 622 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 623 | 			new_sz = str_sz + 1; | |
| 624 | 		 if (!str) | |
| 625 | 			{ | |
| 626 | 			 release_ptrs (&gcollect, &wbuf); | |
| 627 | 			 return EOF; | |
| 628 | 			} | |
| 629 | 		 *pstr = str; | |
| 630 | 		 str += str_sz; | |
| 631 | 		 str_sz = new_sz; | |
| 632 | 		 } | |
| 633 | 		 *str++ = c; | |
| 634 | 		} | |
| 635 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 636 | 	 } | |
| 637 | 	 else | |
| 638 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 639 | ||
| 640 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 641 | 	 { | |
| 642 | 	 optimize_alloc (pstr, str, str_sz); | |
| 643 | 	 pstr = NULL; | |
| 644 | 	 ++rval; | |
| 645 | 	 } | |
| 646 | ||
| 647 | 	 break; | |
| 648 | ||
| 649 | 	case 'C': | |
| 650 | 	 if (width == -1) | |
| 651 | 	 width = 1; | |
| 652 | ||
| 653 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 654 | 	 { | |
| 655 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 656 | 		{ | |
| 657 | 		 if (npos != 0) | |
| 658 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 659 | 		 else | |
| 660 | 		 pstr = va_arg (arg, char **); | |
| 661 | ||
| 662 | 		 if (!pstr) | |
| 663 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 664 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 665 | 		 *pstr = (char *) malloc (str_sz * sizeof (wchar_t)); | |
| 666 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 667 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 668 | 		 gcollect = resize_gcollect (gcollect); | |
| 669 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 670 | 		} | |
| 671 | 	 else | |
| 672 | 		{ | |
| 673 | 		 if (npos != 0) | |
| 674 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 675 | 		 else | |
| 676 | 		 wstr = va_arg (arg, wchar_t *); | |
| 677 | 		 if (!wstr) | |
| 678 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 679 | 		} | |
| 680 | 	 } | |
| 681 | ||
| 682 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 683 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 684 | ||
| 685 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 686 | ||
| 687 | 	 do | |
| 688 | 	 { | |
| 689 | 	 buf[0] = c; | |
| 690 | ||
| 691 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 692 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 693 | 		{ | |
| 694 | 		 new_sz = str_sz + (str_sz > width ? width - 1 : str_sz); | |
| 695 | ||
| 696 | 		 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 697 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 698 | 		 new_sz = str_sz + 1; | |
| 699 | 		 if (!wstr) | |
| 700 | 		 { | |
| 701 | 		 release_ptrs (&gcollect, &wbuf); | |
| 702 | 		 return EOF; | |
| 703 | 		 } | |
| 704 | 		 *pstr = (char *) wstr; | |
| 705 | 		 wstr += str_sz; | |
| 706 | 		 str_sz = new_sz; | |
| 707 | 		} | |
| 708 | ||
| 709 | 	 while (1) | |
| 710 | 		{ | |
| 711 | 		 n = mbrtowc ((flags & IS_SUPPRESSED) == 0 ? wstr : NULL, buf, 1, &cstate); | |
| 712 | ||
| 713 | 		 if (n == (size_t) -2) | |
| 714 | 		 { | |
| 715 | 		 if ((c = in_ch (s, &read_in)) == EOF) | |
| 716 | 			{ | |
| 717 | 			 errno = EILSEQ; | |
| 718 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 719 | 			} | |
| 720 | ||
| 721 | 		 buf[0] = c; | |
| 722 | 		 continue; | |
| 723 | 		 } | |
| 724 | ||
| 725 | 		 if (n != 1) | |
| 726 | 		 { | |
| 727 | 			errno = EILSEQ; | |
| 728 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 729 | 		 } | |
| 730 | 		 break; | |
| 731 | 		} | |
| 732 | ||
| 733 | 	 ++wstr; | |
| 734 | 	 } | |
| 735 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 736 | ||
| 737 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 738 | 	 { | |
| 739 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 740 | 	 pstr = NULL; | |
| 741 | 	 ++rval; | |
| 742 | 	 } | |
| 743 | 	 break; | |
| 744 | ||
| 745 | 	case 's': | |
| 746 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 747 | 	 { | |
| 748 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 749 | 		{ | |
| 750 | 		 if (npos != 0) | |
| 751 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 752 | 		 else | |
| 753 | 		 pstr = va_arg (arg, char **); | |
| 754 | ||
| 755 | 		 if (!pstr) | |
| 756 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 757 | ||
| 758 | 		 str_sz = 100; | |
| 759 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 760 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 761 | 		 gcollect = resize_gcollect (gcollect); | |
| 762 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 763 | 		} | |
| 764 | 	 else | |
| 765 | 		{ | |
| 766 | 		 if (npos != 0) | |
| 767 | 		 str = (char *) get_va_nth (argp, npos); | |
| 768 | 		 else | |
| 769 | 		 str = va_arg (arg, char *); | |
| 770 | 		 if (!str) | |
| 771 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 772 | 		} | |
| 773 | 	 } | |
| 774 | ||
| 775 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 776 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 777 | ||
| 778 | 	 do | |
| 779 | 	 { | |
| 780 | 	 if (isspace (c)) | |
| 781 | 		{ | |
| 782 | 		 back_ch (c, s, &read_in, 1); | |
| 783 | 		 break; | |
| 784 | 		} | |
| 785 | ||
| 786 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 787 | 		{ | |
| 788 | 		 *str++ = c; | |
| 789 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 790 | 		 { | |
| 791 | 		 new_sz = str_sz * 2; | |
| 792 | ||
| 793 | 		 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 794 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 795 | 			new_sz = str_sz + 1; | |
| 796 | 		 if (!str) | |
| 797 | 			{ | |
| 798 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 799 | 			 { | |
| 800 | 			 (*pstr)[str_sz - 1] = 0; | |
| 801 | 			 pstr = NULL; | |
| 802 | 			 ++rval; | |
| 803 | 			 } | |
| 804 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 805 | 			} | |
| 806 | 		 *pstr = str; | |
| 807 | 		 str += str_sz; | |
| 808 | 		 str_sz = new_sz; | |
| 809 | 		 } | |
| 810 | 		} | |
| 811 | 	 } | |
| 812 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != EOF); | |
| 813 | ||
| 814 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 815 | 	 { | |
| 816 | 	 *str++ = 0; | |
| 817 | 	 optimize_alloc (pstr, str, str_sz); | |
| 818 | 	 pstr = NULL; | |
| 819 | 	 ++rval; | |
| 820 | 	 } | |
| 821 | 	 break; | |
| 822 | ||
| 823 | 	case 'S': | |
| 824 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 825 | 	 { | |
| 826 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 827 | 		{ | |
| 828 | 		 if (npos != 0) | |
| 829 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 830 | 		 else | |
| 831 | 		 pstr = va_arg (arg, char **); | |
| 832 | ||
| 833 | 		 if (!pstr) | |
| 834 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 835 | ||
| 836 | 		 str_sz = 100; | |
| 837 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 838 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 839 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 840 | 		 gcollect = resize_gcollect (gcollect); | |
| 841 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 842 | 		} | |
| 843 | 	 else | |
| 844 | 		{ | |
| 845 | 		 if (npos != 0) | |
| 846 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 847 | 		 else | |
| 848 | 		 wstr = va_arg (arg, wchar_t *); | |
| 849 | 		 if (!wstr) | |
| 850 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 851 | 		} | |
| 852 | 	 } | |
| 853 | ||
| 854 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 855 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 856 | ||
| 857 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 858 | ||
| 859 | 	 do | |
| 860 | 	 { | |
| 861 | 	 if (isspace (c)) | |
| 862 | 		{ | |
| 863 | 		 back_ch (c, s, &read_in, 1); | |
| 864 | 		 break; | |
| 865 | 		} | |
| 866 | ||
| 867 | 	 buf[0] = c; | |
| 868 | ||
| 869 | 	 while (1) | |
| 870 | 		{ | |
| 871 | 		 n = mbrtowc ((flags & IS_SUPPRESSED) == 0 ? wstr : NULL, buf, 1, &cstate); | |
| 872 | ||
| 873 | 		 if (n == (size_t) -2) | |
| 874 | 		 { | |
| 875 | 		 if ((c = in_ch (s, &read_in)) == EOF) | |
| 876 | 			{ | |
| 877 | 			 errno = EILSEQ; | |
| 878 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 879 | 			} | |
| 880 | ||
| 881 | 		 buf[0] = c; | |
| 882 | 		 continue; | |
| 883 | 		 } | |
| 884 | ||
| 885 | 		 if (n != 1) | |
| 886 | 		 { | |
| 887 | 		 errno = EILSEQ; | |
| 888 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 889 | 		 } | |
| 890 | ||
| 891 | 		 ++wstr; | |
| 892 | 		 break; | |
| 893 | 		} | |
| 894 | ||
| 895 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 896 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 897 | 		{ | |
| 898 | 		 new_sz = str_sz * 2; | |
| 899 | 		 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 900 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 901 | 		 new_sz = str_sz + 1; | |
| 902 | 		 if (!wstr) | |
| 903 | 		 { | |
| 904 | 		 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 905 | 			{ | |
| 906 | 			 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 907 | 			 pstr = NULL; | |
| 908 | 			 ++rval; | |
| 909 | 			} | |
| 910 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 911 | 		 } | |
| 912 | 		 *pstr = (char *) wstr; | |
| 913 | 		 wstr += str_sz; | |
| 914 | 		 str_sz = new_sz; | |
| 915 | 		} | |
| 916 | 	 } | |
| 917 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != EOF); | |
| 918 | ||
| 919 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 920 | 	 { | |
| 921 | 	 *wstr++ = 0; | |
| 922 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 923 | 	 pstr = NULL; | |
| 924 | 	 ++rval; | |
| 925 | 	 } | |
| 926 | 	 break; | |
| 927 | ||
| 928 | 	case 'd': case 'i': | |
| 929 | 	case 'o': case 'p': | |
| 930 | 	case 'u': | |
| 931 | 	case 'x': case 'X': | |
| 932 | 	 switch (fc) | |
| 933 | 	 { | |
| 934 | 	 case 'd': | |
| 935 | 	 flags |= IS_SIGNED_NUM; | |
| 936 | 	 base = 10; | |
| 937 | 	 break; | |
| 938 | 	 case 'i': | |
| 939 | 	 flags |= IS_SIGNED_NUM; | |
| 940 | 	 base = 0; | |
| 941 | 	 break; | |
| 942 | 	 case 'o': | |
| 943 | 	 base = 8; | |
| 944 | 	 break; | |
| 945 | 	 case 'p': | |
| 946 | 	 base = 16; | |
| 947 | 	 flags &= ~(IS_S | IS_LL | IS_L); | |
| 948 | #ifdef _WIN64 | |
| 949 | 	 flags |= IS_LL; | |
| 950 | #endif | |
| 951 | 	 flags |= IS_L | IS_POINTER; | |
| 952 | 	 break; | |
| 953 | 	 case 'u': | |
| 954 | 	 base = 10; | |
| 955 | 	 break; | |
| 956 | 	 case 'x': case 'X': | |
| 957 | 	 base = 16; | |
| 958 | 	 break; | |
| 959 | 	 } | |
| 960 | ||
| 961 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 962 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 963 | 	 if (c == '+' || c == '-') | |
| 964 | 	 { | |
| 965 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 966 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 967 | 	 if (width > 0) | |
| 968 | 		--width; | |
| 969 | 	 c = in_ch (s, &read_in); | |
| 970 | 	 } | |
| 971 | 	 if (width != 0 && c == '0') | |
| 972 | 	 { | |
| 973 | 	 if (width > 0) | |
| 974 | 		--width; | |
| 975 | ||
| 976 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 977 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 978 | 	 c = in_ch (s, &read_in); | |
| 979 | ||
| 980 | 	 if (width != 0 && tolower (c) == 'x') | |
| 981 | 		{ | |
| 982 | 		 if (!base) | |
| 983 | 		 base = 16; | |
| 984 | 		 if (base == 16) | |
| 985 | 		 { | |
| 986 | 		 if (width > 0) | |
| 987 | 			--width; | |
| 988 | 		 c = in_ch (s, &read_in); | |
| 989 | 		 } | |
| 990 | 		} | |
| 991 | 	 else if (!base) | |
| 992 | 		base = 8; | |
| 993 | 	 } | |
| 994 | ||
| 995 | 	 if (!base) | |
| 996 | 	 base = 10; | |
| 997 | ||
| 998 | 	 while (c != EOF && width != 0) | |
| 999 | 	 { | |
| 1000 | 	 if (base == 16) | |
| 1001 | 		{ | |
| 1002 | 		 if (!isxdigit (c)) | |
| 1003 | 		 break; | |
| 1004 | 		} | |
| 1005 | 	 else if (!isdigit (c) || (int) (c - '0') >= base) | |
| 1006 | 		{ | |
| 1007 | 		 const char *p = lc_thousands_sep; | |
| 1008 | 		 int remain; | |
| 1009 | ||
| 1010 | 		 if (base != 10 || (flags & USE_GROUP) == 0) | |
| 1011 | 		 break; | |
| 1012 | 		 remain = width > 0 ? width : INT_MAX; | |
| 1013 | 		 while ((unsigned char) *p == c && remain >= 0) | |
| 1014 | 		 { | |
| 1015 | 		 /* As our conversion routines aren't supporting thousands | |
| 1016 | 			 separators, we are filtering them here. */ | |
| 1017 | ||
| 1018 | 		 ++p; | |
| 1019 | 		 if (*p == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1020 | 			break; | |
| 1021 | 		 --remain; | |
| 1022 | 		 } | |
| 1023 | ||
| 1024 | 		 if (*p != 0) | |
| 1025 | 		 { | |
| 1026 | 		 if (p > lc_thousands_sep) | |
| 1027 | 			{ | |
| 1028 | 			 back_ch (c, s, &read_in, 0); | |
| 1029 | 			 while (--p > lc_thousands_sep) | |
| 1030 | 			 back_ch ((unsigned char) *p, s, &read_in, 1); | |
| 1031 | 			 c = (unsigned char) *p; | |
| 1032 | 			} | |
| 1033 | 		 break; | |
| 1034 | 		 } | |
| 1035 | ||
| 1036 | 		 if (width > 0) | |
| 1037 | 		 width = remain; | |
| 1038 | 		 --wbuf_cur_sz; | |
| 1039 | 		} | |
| 1040 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1041 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1042 | 	 if (width > 0) | |
| 1043 | 		--width; | |
| 1044 | ||
| 1045 | 	 c = in_ch (s, &read_in); | |
| 1046 | 	 } | |
| 1047 | ||
| 1048 | 	 if (!wbuf_cur_sz || (wbuf_cur_sz == 1 && (wbuf[0] == '+' || wbuf[0] == '-'))) | |
| 1049 | 	 { | |
| 1050 | 	 if (!wbuf_cur_sz && (flags & IS_POINTER) != 0 | |
| 1051 | 	 && match_string (s, &read_in, &c, "(nil)")) | |
| 1052 | 		{ | |
| 1053 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1054 | 		 wbuf[wbuf_cur_sz++] = '0'; | |
| 1055 | 		} | |
| 1056 | 	 else | |
| 1057 | 		{ | |
| 1058 | 		 back_ch (c, s, &read_in, 0); | |
| 1059 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1060 | 		} | |
| 1061 | 	 } | |
| 1062 | 	 else | |
| 1063 | 	 back_ch (c, s, &read_in, 0); | |
| 1064 | ||
| 1065 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1066 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1067 | ||
| 1068 | 	 if ((flags & IS_LL)) | |
| 1069 | 	 { | |
| 1070 | 	 if (flags & IS_SIGNED_NUM) | |
| 1071 | 		cv_val.ll = strtoll (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1072 | 	 else | |
| 1073 | 		cv_val.ull = strtoull (wbuf, &tmp_wbuf_ptr, base); | |
| 1074 | 	 } | |
| 1075 | 	 else | |
| 1076 | 	 { | |
| 1077 | 	 if (flags & IS_SIGNED_NUM) | |
| 1078 | 		cv_val.l = strtol (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1079 | 	 else | |
| 1080 | 		cv_val.ul = strtoul (wbuf, &tmp_wbuf_ptr, base); | |
| 1081 | 	 } | |
| 1082 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1083 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1084 | ||
| 1085 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1086 | 	 { | |
| 1087 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1088 | 		{ | |
| 1089 | 		 if ((flags & IS_LL) != 0) | |
| 1090 | 		 *(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = cv_val.ll; | |
| 1091 | 		 else if ((flags & IS_L) != 0) | |
| 1092 | 		 *(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = cv_val.l; | |
| 1093 | 		 else if ((flags & IS_S) != 0) | |
| 1094 | 		 *(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = (short) cv_val.l; | |
| 1095 | 		 else if ((flags & IS_C) != 0) | |
| 1096 | 		 *(npos != 0 ? (signed char *) get_va_nth (argp, npos) : va_arg (arg, signed char *)) = (signed char) cv_val.ul; | |
| 1097 | 		 else | |
| 1098 | 		 *(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = (int) cv_val.l; | |
| 1099 | 		} | |
| 1100 | 	 else | |
| 1101 | 		{ | |
| 1102 | 		 if ((flags & IS_LL) != 0) | |
| 1103 | 		 *(npos != 0 ? (unsigned long long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long long *)) = cv_val.ull; | |
| 1104 | 		 else if ((flags & IS_L) != 0) | |
| 1105 | 		 *(npos != 0 ? (unsigned long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long *)) = cv_val.ul; | |
| 1106 | 		 else if ((flags & IS_S) != 0) | |
| 1107 | 		 *(npos != 0 ? (unsigned short *) get_va_nth (argp, npos) : va_arg (arg, unsigned short *)) | |
| 1108 | 		 = (unsigned short) cv_val.ul; | |
| 1109 | 		 else if ((flags & IS_C) != 0) | |
| 1110 | 		 *(npos != 0 ? (unsigned char *) get_va_nth (argp, npos) : va_arg (arg, unsigned char *)) = (unsigned char) cv_val.ul; | |
| 1111 | 		 else | |
| 1112 | 		 *(npos != 0 ? (unsigned int *) get_va_nth (argp, npos) : va_arg (arg, unsigned int *)) = (unsigned int) cv_val.ul; | |
| 1113 | 		} | |
| 1114 | 	 ++rval; | |
| 1115 | 	 } | |
| 1116 | 	 break; | |
| 1117 | ||
| 1118 | 	case 'e': case 'E': | |
| 1119 | 	case 'f': case 'F': | |
| 1120 | 	case 'g': case 'G': | |
| 1121 | 	case 'a': case 'A': | |
| 1122 | 	 if (width > 0) | |
| 1123 | 	 --width; | |
| 1124 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1125 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1126 | ||
| 1127 | 	 seen_dot = seen_exp = 0; | |
| 1128 | 	 is_neg = (c == '-' ? 1 : 0); | |
| 1129 | ||
| 1130 | 	 if (c == '-' || c == '+') | |
| 1131 | 	 { | |
| 1132 | 	 if (width == 0 || (c = in_ch (s, &read_in)) == EOF) | |
| 1133 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1134 | 	 if (width > 0) | |
| 1135 | 		--width; | |
| 1136 | 	 } | |
| 1137 | ||
| 1138 | 	 if (tolower (c) == 'n') | |
| 1139 | 	 { | |
| 1140 | 	 const char *match_txt = "nan"; | |
| 1141 | ||
| 1142 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1143 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1144 | ||
| 1145 | 	 ++match_txt; | |
| 1146 | 	 do | |
| 1147 | 		{ | |
| 1148 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1149 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1150 | ||
| 1151 | 		 if (width > 0) | |
| 1152 | 		 --width; | |
| 1153 | ||
| 1154 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1155 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1156 | 		 ++match_txt; | |
| 1157 | 		} | |
| 1158 | 	 while (*match_txt != 0); | |
| 1159 | 	 } | |
| 1160 | 	 else if (tolower (c) == 'i') | |
| 1161 | 	 { | |
| 1162 | 	 const char *match_txt = "inf"; | |
| 1163 | ||
| 1164 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1165 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1166 | ||
| 1167 | 	 ++match_txt; | |
| 1168 | 	 do | |
| 1169 | 		{ | |
| 1170 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1171 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1172 | 		 if (width > 0) | |
| 1173 | 		 --width; | |
| 1174 | ||
| 1175 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1176 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1177 | 		 ++match_txt; | |
| 1178 | 		} | |
| 1179 | 	 while (*match_txt != 0); | |
| 1180 | ||
| 1181 | 	 if (width != 0 && (c = in_ch (s, &read_in)) != EOF && tolower (c) == 'i') | |
| 1182 | 		{ | |
| 1183 | 		 match_txt = "inity"; | |
| 1184 | ||
| 1185 | 		 if (width > 0) | |
| 1186 | 		 --width; | |
| 1187 | ||
| 1188 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1189 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1190 | 		 ++match_txt; | |
| 1191 | ||
| 1192 | 		 do | |
| 1193 | 		 { | |
| 1194 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1195 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1196 | 		 if (width > 0) | |
| 1197 | 			--width; | |
| 1198 | ||
| 1199 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1200 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1201 | 		 ++match_txt; | |
| 1202 | 		 } | |
| 1203 | 		 while (*match_txt != 0); | |
| 1204 | 		} | |
| 1205 | 	 else if (width != 0 && c != EOF) | |
| 1206 | 	 back_ch (c, s, &read_in, 0); | |
| 1207 | 	 } | |
| 1208 | 	 else | |
| 1209 | 	 { | |
| 1210 | 	 not_in = 'e'; | |
| 1211 | 	 if (width != 0 && c == '0') | |
| 1212 | 		{ | |
| 1213 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1214 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1215 | ||
| 1216 | 		 c = in_ch (s, &read_in); | |
| 1217 | 		 if (width > 0) | |
| 1218 | 		 --width; | |
| 1219 | 		 if (width != 0 && tolower (c) == 'x') | |
| 1220 | 		 { | |
| 1221 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1222 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1223 | ||
| 1224 | 		 flags |= IS_HEX_FLOAT; | |
| 1225 | 		 not_in = 'p'; | |
| 1226 | ||
| 1227 | 		 flags &= ~USE_GROUP; | |
| 1228 | 		 c = in_ch (s, &read_in); | |
| 1229 | 		 if (width > 0) | |
| 1230 | 			--width; | |
| 1231 | 		 } | |
| 1232 | 		} | |
| 1233 | ||
| 1234 | 	 while (1) | |
| 1235 | 		{ | |
| 1236 | 		 if (isdigit (c) || (!seen_exp && (flags & IS_HEX_FLOAT) != 0 && isxdigit (c)) | |
| 1237 | 		 || (seen_exp && wbuf[wbuf_cur_sz - 1] == not_in && (c == '-' || c == '+'))) | |
| 1238 | 		 { | |
| 1239 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1240 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1241 | 		 } | |
| 1242 | 		 else if (wbuf_cur_sz > 0 && !seen_exp && (char) tolower (c) == not_in) | |
| 1243 | 		 { | |
| 1244 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1245 | 		 wbuf[wbuf_cur_sz++] = not_in; | |
| 1246 | 		 seen_exp = seen_dot = 1; | |
| 1247 | 		 } | |
| 1248 | 		 else | |
| 1249 | 		 { | |
| 1250 | 		 const char *p = lc_decimal_point; | |
| 1251 | 		 int remain = width > 0 ? width : INT_MAX; | |
| 1252 | ||
| 1253 | 		 if (! seen_dot) | |
| 1254 | 			{ | |
| 1255 | 			 while ((unsigned char) *p == c && remain >= 0) | |
| 1256 | 			 { | |
| 1257 | 			 ++p; | |
| 1258 | 			 if (*p == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1259 | 				break; | |
| 1260 | 			 --remain; | |
| 1261 | 			 } | |
| 1262 | 			} | |
| 1263 | ||
| 1264 | 		 if (*p == 0) | |
| 1265 | 			{ | |
| 1266 | 			 for (p = lc_decimal_point; *p != 0; ++p) | |
| 1267 | 			 { | |
| 1268 | 			 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1269 | 			 wbuf[wbuf_cur_sz++] = (unsigned char) *p; | |
| 1270 | 			 } | |
| 1271 | 			 if (width > 0) | |
| 1272 | 			 width = remain; | |
| 1273 | 			 seen_dot = 1; | |
| 1274 | 			} | |
| 1275 | 		 else | |
| 1276 | 			{ | |
| 1277 | 			 const char *pp = lc_thousands_sep; | |
| 1278 | ||
| 1279 | 			 if (!seen_dot && (flags & USE_GROUP) != 0) | |
| 1280 | 			 { | |
| 1281 | 			 while ((pp - lc_thousands_sep) < (p - lc_decimal_point) | |
| 1282 | 				 && *pp == lc_decimal_point[(pp - lc_thousands_sep)]) | |
| 1283 | 				++pp; | |
| 1284 | 			 if ((pp - lc_thousands_sep) == (p - lc_decimal_point)) | |
| 1285 | 				{ | |
| 1286 | 				 while ((unsigned char) *pp == c && remain >= 0) | |
| 1287 | 				 { | |
| 1288 | 				 ++pp; | |
| 1289 | 				 if (*pp == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1290 | 					break; | |
| 1291 | 				 --remain; | |
| 1292 | 				 } | |
| 1293 | 				} | |
| 1294 | 			 } | |
| 1295 | ||
| 1296 | 			 if (pp != NULL && *pp == 0) | |
| 1297 | 			 { | |
| 1298 | 			 /* As our conversion routines aren't supporting thousands | |
| 1299 | 				 separators, we are filtering them here. */ | |
| 1300 | 			 if (width > 0) | |
| 1301 | 				width = remain; | |
| 1302 | 			 } | |
| 1303 | 			 else | |
| 1304 | 			 { | |
| 1305 | 			 back_ch (c, s, &read_in, 0); | |
| 1306 | 			 break; | |
| 1307 | 			 } | |
| 1308 | 			} | |
| 1309 | 		 } | |
| 1310 | ||
| 1311 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF) | |
| 1312 | 		 break; | |
| 1313 | ||
| 1314 | 		 if (width > 0) | |
| 1315 | 		 --width; | |
| 1316 | 		} | |
| 1317 | ||
| 1318 | 	 if (!wbuf_cur_sz || ((flags & IS_HEX_FLOAT) != 0 && wbuf_cur_sz == 2)) | |
| 1319 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1320 | 	 } | |
| 1321 | ||
| 1322 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1323 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1324 | ||
| 1325 | 	 if ((flags & IS_LL) != 0) | |
| 1326 | 	 { | |
| 1327 | 	 long double ld; | |
| 1328 | 	 ld = __mingw_strtold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1329 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1330 | 	 *(npos != 0 ? (long double *) get_va_nth (argp, npos) : va_arg (arg, long double *)) = is_neg ? -ld : ld; | |
| 1331 | 	 } | |
| 1332 | 	 else if ((flags & IS_L) != 0) | |
| 1333 | 	 { | |
| 1334 | 	 double d; | |
| 1335 | 	 d = (double) __mingw_strtold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1336 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1337 | 		*(npos != 0 ? (double *) get_va_nth (argp, npos) : va_arg (arg, double *)) = is_neg ? -d : d; | |
| 1338 | 	 } | |
| 1339 | 	 else | |
| 1340 | 	 { | |
| 1341 | 	 float d = __mingw_strtof (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1342 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1343 | 		*(npos != 0 ? (float *) get_va_nth (argp, npos) : va_arg (arg, float *)) = is_neg ? -d : d; | |
| 1344 | 	 } | |
| 1345 | ||
| 1346 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1347 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1348 | ||
| 1349 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1350 | 	 ++rval; | |
| 1351 | 	 break; | |
| 1352 | ||
| 1353 | 	case '[': | |
| 1354 | 	 if ((flags & IS_L) != 0) | |
| 1355 | 	 { | |
| 1356 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1357 | 		{ | |
| 1358 | 		 if ((flags & IS_ALLOC_USED) != 0) | |
| 1359 | 		 { | |
| 1360 | 		 if (npos != 0) | |
| 1361 | 			pstr = (char **) get_va_nth (argp, npos); | |
| 1362 | 		 else | |
| 1363 | 			pstr = va_arg (arg, char **); | |
| 1364 | ||
| 1365 | 		 if (!pstr) | |
| 1366 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1367 | ||
| 1368 | 		 str_sz = 100; | |
| 1369 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 1370 | ||
| 1371 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 1372 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1373 | 		 gcollect = resize_gcollect (gcollect); | |
| 1374 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1375 | 		 } | |
| 1376 | 		 else | |
| 1377 | 		 { | |
| 1378 | 		 if (npos != 0) | |
| 1379 | 			wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 1380 | 		 else | |
| 1381 | 			wstr = va_arg (arg, wchar_t *); | |
| 1382 | 		 if (!wstr) | |
| 1383 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1384 | 		 } | |
| 1385 | 		} | |
| 1386 | 	 } | |
| 1387 | 	 else if ((flags & IS_SUPPRESSED) == 0) | |
| 1388 | 	 { | |
| 1389 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 1390 | 		{ | |
| 1391 | 		 if (npos != 0) | |
| 1392 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1393 | 		 else | |
| 1394 | 		 pstr = va_arg (arg, char **); | |
| 1395 | ||
| 1396 | 		 if (!pstr) | |
| 1397 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1398 | ||
| 1399 | 		 str_sz = 100; | |
| 1400 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 1401 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1402 | ||
| 1403 | 		 gcollect = resize_gcollect (gcollect); | |
| 1404 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1405 | 		} | |
| 1406 | 	 else | |
| 1407 | 		{ | |
| 1408 | 		 if (npos != 0) | |
| 1409 | 		 str = (char *) get_va_nth (argp, npos); | |
| 1410 | 		 else | |
| 1411 | 		 str = va_arg (arg, char *); | |
| 1412 | 		 if (!str) | |
| 1413 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1414 | 		} | |
| 1415 | 	 } | |
| 1416 | ||
| 1417 | 	 not_in = (*f == '^' ? 1 : 0); | |
| 1418 | 	 if (*f == '^') | |
| 1419 | 	 f++; | |
| 1420 | ||
| 1421 | 	 if (width < 0) | |
| 1422 | 	 width = INT_MAX; | |
| 1423 | ||
| 1424 | 	 if (wbuf_max_sz < 256) | |
| 1425 | 	 { | |
| 1426 | 	 wbuf_max_sz = 256; | |
| 1427 | 	 if (wbuf) | |
| 1428 | 	 free (wbuf); | |
| 1429 | 	 wbuf = (char *) malloc (wbuf_max_sz); | |
| 1430 | 	 } | |
| 1431 | 	 memset (wbuf, 0, 256); | |
| 1432 | ||
| 1433 | 	 fc = *f; | |
| 1434 | 	 if (fc == ']' || fc == '-') | |
| 1435 | 	 { | |
| 1436 | 	 wbuf[fc] = 1; | |
| 1437 | 	 ++f; | |
| 1438 | 	 } | |
| 1439 | ||
| 1440 | 	 while ((fc = *f++) != 0 && fc != ']') | |
| 1441 | 	 { | |
| 1442 | 	 if (fc == '-' && *f != 0 && *f != ']' && (unsigned char) f[-2] <= (unsigned char) *f) | |
| 1443 | 		{ | |
| 1444 | 		 for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc) | |
| 1445 | 		 wbuf[fc] = 1; | |
| 1446 | 		} | |
| 1447 | 	 else | |
| 1448 | 		wbuf[fc] = 1; | |
| 1449 | 	 } | |
| 1450 | ||
| 1451 | 	 if (!fc) | |
| 1452 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1453 | ||
| 1454 | 	 if ((flags & IS_L) != 0) | |
| 1455 | 	 { | |
| 1456 | 	 read_in_sv = read_in; | |
| 1457 | 	 cnt = 0; | |
| 1458 | ||
| 1459 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1460 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1461 | ||
| 1462 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 1463 | ||
| 1464 | 	 do | |
| 1465 | 		{ | |
| 1466 | 		 if (wbuf[c] == not_in) | |
| 1467 | 		 { | |
| 1468 | 		 back_ch (c, s, &read_in, 1); | |
| 1469 | 		 break; | |
| 1470 | 		 } | |
| 1471 | ||
| 1472 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1473 | 		 { | |
| 1474 | 		 buf[0] = c; | |
| 1475 | 		 n = mbrtowc (wstr, buf, 1, &cstate); | |
| 1476 | ||
| 1477 | 		 if (n == (size_t) -2) | |
| 1478 | 			{ | |
| 1479 | 			 ++cnt; | |
| 1480 | 			 continue; | |
| 1481 | 			} | |
| 1482 | 		 cnt = 0; | |
| 1483 | ||
| 1484 | 		 ++wstr; | |
| 1485 | 		 if ((flags & IS_ALLOC_USED) != 0 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 1486 | 			{ | |
| 1487 | 			 new_sz = str_sz * 2; | |
| 1488 | 			 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 1489 | 			 	 && new_sz > (size_t) (str_sz + 1)) | |
| 1490 | 			 new_sz = str_sz + 1; | |
| 1491 | 			 if (!wstr) | |
| 1492 | 			 { | |
| 1493 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1494 | 				{ | |
| 1495 | 				 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 1496 | 				 pstr = NULL; | |
| 1497 | 				 ++rval; | |
| 1498 | 				} | |
| 1499 | 			 else | |
| 1500 | 				rval = EOF; | |
| 1501 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1502 | 			 } | |
| 1503 | 			 *pstr = (char *) wstr; | |
| 1504 | 			 wstr += str_sz; | |
| 1505 | 			 str_sz = new_sz; | |
| 1506 | 			} | |
| 1507 | 		 } | |
| 1508 | ||
| 1509 | 		 if (--width <= 0) | |
| 1510 | 		 break; | |
| 1511 | 		} | |
| 1512 | 	 while ((c = in_ch (s, &read_in)) != EOF); | |
| 1513 | ||
| 1514 | 	 if (cnt != 0) | |
| 1515 | 		{ | |
| 1516 | 		 errno = EILSEQ; | |
| 1517 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1518 | 		} | |
| 1519 | ||
| 1520 | 	 if (read_in_sv == read_in) | |
| 1521 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1522 | ||
| 1523 | ||
| 1524 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1525 | 		{ | |
| 1526 | 		 *wstr++ = 0; | |
| 1527 | 		 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 1528 | 		 pstr = NULL; | |
| 1529 | 		 ++rval; | |
| 1530 | 		} | |
| 1531 | 	 } | |
| 1532 | 	 else | |
| 1533 | 	 { | |
| 1534 | 	 read_in_sv = read_in; | |
| 1535 | ||
| 1536 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1537 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1538 | ||
| 1539 | 	 do | |
| 1540 | 		{ | |
| 1541 | 		 if (wbuf[c] == not_in) | |
| 1542 | 		 { | |
| 1543 | 		 back_ch (c, s, &read_in, 1); | |
| 1544 | 		 break; | |
| 1545 | 		 } | |
| 1546 | ||
| 1547 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1548 | 		 { | |
| 1549 | 		 *str++ = c; | |
| 1550 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 1551 | 			{ | |
| 1552 | 			 new_sz = str_sz * 2; | |
| 1553 | ||
| 1554 | 			 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 1555 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 1556 | 			 new_sz = str_sz + 1; | |
| 1557 | 			 if (!str) | |
| 1558 | 			 { | |
| 1559 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1560 | 				{ | |
| 1561 | 				 (*pstr)[str_sz - 1] = 0; | |
| 1562 | 				 pstr = NULL; | |
| 1563 | 				 ++rval; | |
| 1564 | 				} | |
| 1565 | 			 else | |
| 1566 | 			 rval = EOF; | |
| 1567 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1568 | 			 } | |
| 1569 | 			 *pstr = str; | |
| 1570 | 			 str += str_sz; | |
| 1571 | 			 str_sz = new_sz; | |
| 1572 | 			} | |
| 1573 | 		 } | |
| 1574 | 		} | |
| 1575 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 1576 | ||
| 1577 | 	 if (read_in_sv == read_in) | |
| 1578 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1579 | ||
| 1580 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1581 | 		{ | |
| 1582 | 		 *str++ = 0; | |
| 1583 | 		 optimize_alloc (pstr, str, str_sz); | |
| 1584 | 		 pstr = NULL; | |
| 1585 | 		 ++rval; | |
| 1586 | 		} | |
| 1587 | 	 } | |
| 1588 | 	 break; | |
| 1589 | ||
| 1590 | 	default: | |
| 1591 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1592 | 	} | |
| 1593 | } | |
| 1594 | ||
| 1595 | if (ignore_ws) | |
| 1596 | { | |
| 1597 | while (isspace ((c = in_ch (s, &read_in)))); | |
| 1598 | back_ch (c, s, &read_in, 0); | |
| 1599 | } | |
| 1600 | ||
| 1601 | return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1602 | } |
lib/libc/mingw/stdio/mingw_sformat.h created+63| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #ifndef SFORMAT_H | |
| 46 | #define SFORMAT_H | |
| 47 | ||
| 48 | /* internal stream structure with back-buffer. */ | |
| 49 | typedef struct _IFP | |
| 50 | { | |
| 51 | __extension__ union { | |
| 52 | void *fp; | |
| 53 | const char *str; | |
| 54 | }; | |
| 55 | int bch[1024]; | |
| 56 | unsigned int is_string : 1; | |
| 57 | int back_top; | |
| 58 | unsigned int seen_eof : 1; | |
| 59 | } _IFP; | |
| 60 | ||
| 61 | int __cdecl __mingw_sformat(_IFP *, const char *, va_list) __MINGW_NOTHROW; | |
| 62 | ||
| 63 | #endif /* !defined SFORMAT_H */ |
lib/libc/mingw/stdio/mingw_snprintfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_snprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_snwprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_snprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_sprintfw.c deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | #define _CRT_NON_CONFORMING_SWPRINTFS 1 | |
| 8 | ||
| 9 | #include "mingw_sprintf.c" | |
| 10 |
lib/libc/mingw/stdio/mingw_swformat.c created+1601| ... | ... | @@ -0,0 +1,1601 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #define __LARGE_MBSTATE_T | |
| 46 | ||
| 47 | #include <limits.h> | |
| 48 | #include <stddef.h> | |
| 49 | #include <stdarg.h> | |
| 50 | #include <stdio.h> | |
| 51 | #include <stdint.h> | |
| 52 | #include <stdlib.h> | |
| 53 | #include <string.h> | |
| 54 | #include <wchar.h> | |
| 55 | #include <ctype.h> | |
| 56 | #include <wctype.h> | |
| 57 | #include <locale.h> | |
| 58 | #include <errno.h> | |
| 59 | ||
| 60 | #include "mingw_swformat.h" | |
| 61 | ||
| 62 | #ifndef CP_UTF8 | |
| 63 | #define CP_UTF8 65001 | |
| 64 | #endif | |
| 65 | ||
| 66 | #ifndef MB_ERR_INVALID_CHARS | |
| 67 | #define MB_ERR_INVALID_CHARS 0x00000008 | |
| 68 | #endif | |
| 69 | ||
| 70 | /* Helper flags for conversion. */ | |
| 71 | #define IS_C		0x0001 | |
| 72 | #define IS_S		0x0002 | |
| 73 | #define IS_L		0x0004 | |
| 74 | #define IS_LL		0x0008 | |
| 75 | #define IS_SIGNED_NUM	0x0010 | |
| 76 | #define IS_POINTER	0x0020 | |
| 77 | #define IS_HEX_FLOAT	0x0040 | |
| 78 | #define IS_SUPPRESSED	0x0080 | |
| 79 | #define USE_GROUP	0x0100 | |
| 80 | #define USE_GNU_ALLOC	0x0200 | |
| 81 | #define USE_POSIX_ALLOC	0x0400 | |
| 82 | ||
| 83 | #define IS_ALLOC_USED	(USE_GNU_ALLOC | USE_POSIX_ALLOC) | |
| 84 | ||
| 85 | static void * | |
| 86 | get_va_nth (va_list argp, unsigned int n) | |
| 87 | { | |
| 88 | va_list ap; | |
| 89 | if (!n) | |
| 90 | abort (); | |
| 91 | va_copy (ap, argp); | |
| 92 | while (--n > 0) | |
| 93 | (void) va_arg(ap, void *); | |
| 94 | return va_arg (ap, void *); | |
| 95 | } | |
| 96 | ||
| 97 | static void | |
| 98 | optimize_alloc (char **p, char *end, size_t alloc_sz) | |
| 99 | { | |
| 100 | size_t need_sz; | |
| 101 | char *h; | |
| 102 | ||
| 103 | if (!p || !*p) | |
| 104 | return; | |
| 105 | ||
| 106 | need_sz = end - *p; | |
| 107 | if (need_sz == alloc_sz) | |
| 108 | return; | |
| 109 | ||
| 110 | if ((h = (char *) realloc (*p, need_sz)) != NULL) | |
| 111 | *p = h; | |
| 112 | } | |
| 113 | ||
| 114 | static void | |
| 115 | back_ch (int c, _IFPW *s, size_t *rin, int not_eof) | |
| 116 | { | |
| 117 | if (!not_eof && c == WEOF) | |
| 118 | return; | |
| 119 | if (s->is_string == 0) | |
| 120 | { | |
| 121 | FILE *fp = s->fp; | |
| 122 | ungetwc (c, fp); | |
| 123 | rin[0] -= 1; | |
| 124 | return; | |
| 125 | } | |
| 126 | rin[0] -= 1; | |
| 127 | s->bch[s->back_top] = c; | |
| 128 | s->back_top += 1; | |
| 129 | } | |
| 130 | ||
| 131 | static int | |
| 132 | in_ch (_IFPW *s, size_t *rin) | |
| 133 | { | |
| 134 | int r; | |
| 135 | if (s->back_top) | |
| 136 | { | |
| 137 | s->back_top -= 1; | |
| 138 | r = s->bch[s->back_top]; | |
| 139 | rin[0] += 1; | |
| 140 | } | |
| 141 | else if (s->seen_eof) | |
| 142 | { | |
| 143 | return WEOF; | |
| 144 | } | |
| 145 | else if (s->is_string) | |
| 146 | { | |
| 147 | const wchar_t *ps = s->str; | |
| 148 | r = ((int) *ps) & 0xffff; | |
| 149 | ps++; | |
| 150 | if (r != 0) | |
| 151 | { | |
| 152 | rin[0] += 1; | |
| 153 | s->str = ps; | |
| 154 | return r; | |
| 155 | } | |
| 156 | s->seen_eof = 1; | |
| 157 | return WEOF; | |
| 158 | } | |
| 159 | else | |
| 160 | { | |
| 161 | FILE *fp = (FILE *) s->fp; | |
| 162 | r = getwc (fp); | |
| 163 | if (r != WEOF) | |
| 164 | rin[0] += 1; | |
| 165 | else s->seen_eof = 1; | |
| 166 | } | |
| 167 | return r; | |
| 168 | } | |
| 169 | ||
| 170 | static int | |
| 171 | match_string (_IFPW *s, size_t *rin, wint_t *c, const wchar_t *str) | |
| 172 | { | |
| 173 | int ch = *c; | |
| 174 | ||
| 175 | if (*str == 0) | |
| 176 | return 1; | |
| 177 | ||
| 178 | if (*str != (wchar_t) towlower (ch)) | |
| 179 | return 0; | |
| 180 | ++str; | |
| 181 | while (*str != 0) | |
| 182 | { | |
| 183 | if ((ch = in_ch (s, rin)) == WEOF) | |
| 184 | { | |
| 185 | c[0] = ch; | |
| 186 | return 0; | |
| 187 | } | |
| 188 | ||
| 189 | if (*str != (wchar_t) towlower (ch)) | |
| 190 | { | |
| 191 | c[0] = ch; | |
| 192 | return 0; | |
| 193 | } | |
| 194 | ++str; | |
| 195 | } | |
| 196 | c[0] = ch; | |
| 197 | return 1; | |
| 198 | } | |
| 199 | ||
| 200 | struct gcollect | |
| 201 | { | |
| 202 | size_t count; | |
| 203 | struct gcollect *next; | |
| 204 | char **ptrs[32]; | |
| 205 | }; | |
| 206 | ||
| 207 | static void | |
| 208 | release_ptrs (struct gcollect **pt, wchar_t **wbuf) | |
| 209 | { | |
| 210 | struct gcollect *pf; | |
| 211 | size_t cnt; | |
| 212 | ||
| 213 | if (wbuf) | |
| 214 | { | |
| 215 | free (*wbuf); | |
| 216 | *wbuf = NULL; | |
| 217 | } | |
| 218 | if (!pt || (pf = *pt) == NULL) | |
| 219 | return; | |
| 220 | while (pf != NULL) | |
| 221 | { | |
| 222 | struct gcollect *pf_sv = pf; | |
| 223 | for (cnt = 0; cnt < pf->count; ++cnt) | |
| 224 | 	{ | |
| 225 | 	 free (*pf->ptrs[cnt]); | |
| 226 | 	 *pf->ptrs[cnt] = NULL; | |
| 227 | 	} | |
| 228 | pf = pf->next; | |
| 229 | free (pf_sv); | |
| 230 | } | |
| 231 | *pt = NULL; | |
| 232 | } | |
| 233 | ||
| 234 | static int | |
| 235 | cleanup_return (int rval, struct gcollect **pfree, char **strp, wchar_t **wbuf) | |
| 236 | { | |
| 237 | if (rval == EOF) | |
| 238 | release_ptrs (pfree, wbuf); | |
| 239 | else | |
| 240 | { | |
| 241 | if (pfree) | |
| 242 | { | |
| 243 | struct gcollect *pf = *pfree, *pf_sv; | |
| 244 | while (pf != NULL) | |
| 245 | { | |
| 246 | pf_sv = pf; | |
| 247 | pf = pf->next; | |
| 248 | free (pf_sv); | |
| 249 | } | |
| 250 | *pfree = NULL; | |
| 251 | } | |
| 252 | if (strp != NULL) | |
| 253 | 	{ | |
| 254 | 	 free (*strp); | |
| 255 | 	 *strp = NULL; | |
| 256 | 	} | |
| 257 | if (wbuf) | |
| 258 | 	{ | |
| 259 | 	 free (*wbuf); | |
| 260 | 	 *wbuf = NULL; | |
| 261 | 	} | |
| 262 | } | |
| 263 | return rval; | |
| 264 | } | |
| 265 | ||
| 266 | static struct gcollect * | |
| 267 | resize_gcollect (struct gcollect *pf) | |
| 268 | { | |
| 269 | struct gcollect *np; | |
| 270 | if (pf && pf->count < 32) | |
| 271 | return pf; | |
| 272 | np = malloc (sizeof (struct gcollect)); | |
| 273 | np->count = 0; | |
| 274 | np->next = pf; | |
| 275 | return np; | |
| 276 | } | |
| 277 | ||
| 278 | static wchar_t * | |
| 279 | resize_wbuf (size_t wpsz, size_t *wbuf_max_sz, wchar_t *old) | |
| 280 | { | |
| 281 | wchar_t *wbuf; | |
| 282 | size_t nsz; | |
| 283 | if (*wbuf_max_sz != wpsz) | |
| 284 | return old; | |
| 285 | nsz = (256 > (2 * wbuf_max_sz[0]) ? 256 : (2 * wbuf_max_sz[0])); | |
| 286 | if (!old) | |
| 287 | wbuf = (wchar_t *) malloc (nsz * sizeof (wchar_t)); | |
| 288 | else | |
| 289 | wbuf = (wchar_t *) realloc (old, nsz * sizeof (wchar_t)); | |
| 290 | if (!wbuf) | |
| 291 | { | |
| 292 | if (old) | |
| 293 | free (old); | |
| 294 | } | |
| 295 | else | |
| 296 | *wbuf_max_sz = nsz; | |
| 297 | return wbuf; | |
| 298 | } | |
| 299 | ||
| 300 | int | |
| 301 | __cdecl | |
| 302 | __mingw_swformat (_IFPW *s, const wchar_t *format, va_list argp) | |
| 303 | { | |
| 304 | const wchar_t *f = format; | |
| 305 | struct gcollect *gcollect = NULL; | |
| 306 | size_t read_in = 0, wbuf_max_sz = 0; | |
| 307 | ssize_t str_sz = 0; | |
| 308 | char *str = NULL, **pstr = NULL;; | |
| 309 | wchar_t *wstr = NULL, *wbuf = NULL; | |
| 310 | wint_t c = 0, rval = 0; | |
| 311 | int ignore_ws = 0; | |
| 312 | va_list arg; | |
| 313 | size_t wbuf_cur_sz, str_len, read_in_sv, new_sz, n; | |
| 314 | unsigned int fc, npos; | |
| 315 | int width, flags, base = 0, errno_sv, clen; | |
| 316 | char seen_dot, seen_exp, is_neg, *nstr, buf[MB_LEN_MAX]; | |
| 317 | wchar_t wc, not_in, *tmp_wbuf_ptr, *temp_wbuf_end, *wbuf_iter; | |
| 318 | wint_t lc_decimal_point, lc_thousands_sep; | |
| 319 | mbstate_t state; | |
| 320 | union { | |
| 321 | unsigned long long ull; | |
| 322 | unsigned long ul; | |
| 323 | long long ll; | |
| 324 | long l; | |
| 325 | } cv_val; | |
| 326 | ||
| 327 | arg = argp; | |
| 328 | ||
| 329 | if (!s || s->fp == NULL || !format) | |
| 330 | { | |
| 331 | errno = EINVAL; | |
| 332 | return EOF; | |
| 333 | } | |
| 334 | ||
| 335 | memset (&state, 0, sizeof(state)); | |
| 336 | clen = mbrtowc( &wc, localeconv()->decimal_point, 16, &state); | |
| 337 | lc_decimal_point = (clen > 0 ? wc : '.'); | |
| 338 | memset( &state, 0, sizeof( state ) ); | |
| 339 | clen = mbrtowc( &wc, localeconv()->thousands_sep, 16, &state); | |
| 340 | lc_thousands_sep = (clen > 0 ? wc : 0); | |
| 341 | ||
| 342 | while (*f != 0) | |
| 343 | { | |
| 344 | fc = *f++; | |
| 345 | if (fc != '%') | |
| 346 | { | |
| 347 | if (iswspace (fc)) | |
| 348 | 	 ignore_ws = 1; | |
| 349 | 	 else | |
| 350 | 	 { | |
| 351 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 352 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 353 | ||
| 354 | 	 if (ignore_ws) | |
| 355 | 		{ | |
| 356 | 		 ignore_ws = 0; | |
| 357 | 		 if (iswspace (c)) | |
| 358 | 		 { | |
| 359 | 		 do | |
| 360 | 			{ | |
| 361 | 			 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 362 | 			 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 363 | 			} | |
| 364 | 		 while (iswspace (c)); | |
| 365 | 		 } | |
| 366 | 		} | |
| 367 | ||
| 368 | 	 if (c != fc) | |
| 369 | 		{ | |
| 370 | 		 back_ch (c, s, &read_in, 0); | |
| 371 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 372 | 		} | |
| 373 | 	 } | |
| 374 | ||
| 375 | 	 continue; | |
| 376 | 	} | |
| 377 | ||
| 378 | width = flags = 0; | |
| 379 | npos = 0; | |
| 380 | wbuf_cur_sz = 0; | |
| 381 | ||
| 382 | if (iswdigit ((unsigned int) *f)) | |
| 383 | 	{ | |
| 384 | 	 const wchar_t *svf = f; | |
| 385 | 	 npos = (unsigned int) *f++ - '0'; | |
| 386 | 	 while (iswdigit ((unsigned int) *f)) | |
| 387 | 	 npos = npos * 10 + ((unsigned int) *f++ - '0'); | |
| 388 | 	 if (*f != '$') | |
| 389 | 	 { | |
| 390 | 	 npos = 0; | |
| 391 | 	 f = svf; | |
| 392 | 	 } | |
| 393 | 	 else | |
| 394 | 	 f++; | |
| 395 | 	} | |
| 396 | ||
| 397 | do | |
| 398 | 	{ | |
| 399 | 	 if (*f == '*') | |
| 400 | 	 flags |= IS_SUPPRESSED; | |
| 401 | 	 else if (*f == '\'') | |
| 402 | 	 { | |
| 403 | 	 if (lc_thousands_sep) | |
| 404 | 		flags |= USE_GROUP; | |
| 405 | 	 } | |
| 406 | 	 else if (*f == 'I') | |
| 407 | 	 { | |
| 408 | 	 /* we don't support locale's digits (i18N), but ignore it for now silently. */ | |
| 409 | 	 ; | |
| 410 | #ifdef _WIN32 | |
| 411 | if (f[1] == '6' && f[2] == '4') | |
| 412 | { | |
| 413 | 		 flags |= IS_LL | IS_L; | |
| 414 | 		 f += 2; | |
| 415 | 		} | |
| 416 | 	 else if (f[1] == '3' && f[2] == '2') | |
| 417 | 		{ | |
| 418 | 		 flags |= IS_L; | |
| 419 | 		 f += 2; | |
| 420 | 		} | |
| 421 | 	 else | |
| 422 | 	 { | |
| 423 | #ifdef _WIN64 | |
| 424 | 		 flags |= IS_LL | IS_L; | |
| 425 | #else | |
| 426 | 		 flags |= IS_L; | |
| 427 | #endif | |
| 428 | 		} | |
| 429 | #endif | |
| 430 | 	 } | |
| 431 | 	 else | |
| 432 | 	 break; | |
| 433 | 	 ++f; | |
| 434 | } | |
| 435 | while (1); | |
| 436 | ||
| 437 | while (iswdigit ((unsigned char) *f)) | |
| 438 | 	width = width * 10 + ((unsigned char) *f++ - '0'); | |
| 439 | ||
| 440 | if (!width) | |
| 441 | 	width = -1; | |
| 442 | ||
| 443 | switch (*f) | |
| 444 | 	{ | |
| 445 | 	case 'h': | |
| 446 | 	 ++f; | |
| 447 | 	 flags |= (*f == 'h' ? IS_C : IS_S); | |
| 448 | 	 if (*f == 'h') | |
| 449 | 	 ++f; | |
| 450 | 	 break; | |
| 451 | 	case 'l': | |
| 452 | 	 ++f; | |
| 453 | 	 flags |= (*f == 'l' ? IS_LL : 0) | IS_L; | |
| 454 | 	 if (*f == 'l') | |
| 455 | 	 ++f; | |
| 456 | 	 break; | |
| 457 | 	case 'q': case 'L': | |
| 458 | 	 ++f; | |
| 459 | 	 flags |= IS_LL | IS_L; | |
| 460 | 	 break; | |
| 461 | 	case 'a': | |
| 462 | 	 if (f[1] != 's' && f[1] != 'S' && f[1] != '[') | |
| 463 | 	 break; | |
| 464 | 	 ++f; | |
| 465 | 	 flags |= USE_GNU_ALLOC; | |
| 466 | 	 break; | |
| 467 | 	case 'm': | |
| 468 | 	 flags |= USE_POSIX_ALLOC; | |
| 469 | 	 ++f; | |
| 470 | 	 if (*f == 'l') | |
| 471 | 	 { | |
| 472 | 	 flags |= IS_L; | |
| 473 | 	 ++f; | |
| 474 | 	 } | |
| 475 | 	 break; | |
| 476 | 	case 'z': | |
| 477 | #ifdef _WIN64 | |
| 478 | 	 flags |= IS_LL | IS_L; | |
| 479 | #else | |
| 480 | 	 flags |= IS_L; | |
| 481 | #endif | |
| 482 | 	 ++f; | |
| 483 | 	 break; | |
| 484 | 	case 'j': | |
| 485 | 	 if (sizeof (uintmax_t) > sizeof (unsigned long)) | |
| 486 | 	 flags |= IS_LL; | |
| 487 | 	 else if (sizeof (uintmax_t) > sizeof (unsigned int)) | |
| 488 | 	 flags |= IS_L; | |
| 489 | 	 ++f; | |
| 490 | 	 break; | |
| 491 | 	case 't': | |
| 492 | #ifdef _WIN64 | |
| 493 | 	 flags |= IS_LL; | |
| 494 | #else | |
| 495 | 	 flags |= IS_L; | |
| 496 | #endif | |
| 497 | 	 ++f; | |
| 498 | 	 break; | |
| 499 | 	case 0: | |
| 500 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 501 | 	default: | |
| 502 | 	 break; | |
| 503 | 	} | |
| 504 | ||
| 505 | if (*f == 0) | |
| 506 | 	return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 507 | ||
| 508 | fc = *f++; | |
| 509 | if (ignore_ws || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n')) | |
| 510 | 	{ | |
| 511 | 	 errno_sv = errno; | |
| 512 | 	 errno = 0; | |
| 513 | 	 do | |
| 514 | 	 { | |
| 515 | 	 if ((c == WEOF || (c = in_ch (s, &read_in)) == WEOF) && errno == EINTR) | |
| 516 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 517 | 	 } | |
| 518 | 	 while (iswspace (c)); | |
| 519 | ||
| 520 | 	 ignore_ws = 0; | |
| 521 | 	 errno = errno_sv; | |
| 522 | 	 back_ch (c, s, &read_in, 0); | |
| 523 | 	} | |
| 524 | ||
| 525 | switch (fc) | |
| 526 | { | |
| 527 | case 'c': | |
| 528 | if ((flags & IS_L) != 0) | |
| 529 | fc = 'C'; | |
| 530 | break; | |
| 531 | case 's': | |
| 532 | if ((flags & IS_L) != 0) | |
| 533 | fc = 'S'; | |
| 534 | break; | |
| 535 | } | |
| 536 | ||
| 537 | switch (fc) | |
| 538 | 	{ | |
| 539 | 	case '%': | |
| 540 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 541 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 542 | 	 if (c != fc) | |
| 543 | 	 { | |
| 544 | 	 back_ch (c, s, &read_in, 1); | |
| 545 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 546 | 	 } | |
| 547 | 	 break; | |
| 548 | ||
| 549 | 	case 'n': | |
| 550 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 551 | 	 { | |
| 552 | 	 if ((flags & IS_LL) != 0) | |
| 553 | 		*(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = read_in; | |
| 554 | 	 else if ((flags & IS_L) != 0) | |
| 555 | 		*(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = read_in; | |
| 556 | 	 else if ((flags & IS_S) != 0) | |
| 557 | 		*(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = read_in; | |
| 558 | 	 else if ((flags & IS_C) != 0) | |
| 559 | 	 *(npos != 0 ? (char *) get_va_nth (argp, npos) : va_arg (arg, char *)) = read_in; | |
| 560 | 	 else | |
| 561 | 		*(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = read_in; | |
| 562 | 	 } | |
| 563 | 	 break; | |
| 564 | ||
| 565 | 	case 'c': | |
| 566 | 	 if (width == -1) | |
| 567 | 	 width = 1; | |
| 568 | ||
| 569 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 570 | 	 { | |
| 571 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 572 | 		{ | |
| 573 | 		 if (npos != 0) | |
| 574 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 575 | 		 else | |
| 576 | 		 pstr = va_arg (arg, char **); | |
| 577 | ||
| 578 | 		 if (!pstr) | |
| 579 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 580 | 		 str_sz = 100; | |
| 581 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 582 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 583 | 		 gcollect = resize_gcollect (gcollect); | |
| 584 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 585 | 		} | |
| 586 | 	 else | |
| 587 | 		{ | |
| 588 | 		 if (npos != 0) | |
| 589 | 		 str = (char *) get_va_nth (argp, npos); | |
| 590 | 		 else | |
| 591 | 		 str = va_arg (arg, char *); | |
| 592 | 		 if (!str) | |
| 593 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 594 | 		} | |
| 595 | 	 } | |
| 596 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 597 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 598 | ||
| 599 | 	 memset (&state, 0, sizeof (state)); | |
| 600 | ||
| 601 | 	 do | |
| 602 | 	 { | |
| 603 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & USE_POSIX_ALLOC) != 0 | |
| 604 | 		 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 605 | 		{ | |
| 606 | 		 new_sz = str_sz * 2; | |
| 607 | 		 str_len = (str - *pstr); | |
| 608 | 		 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 609 | 			 && new_sz > (str_len + MB_CUR_MAX)) | |
| 610 | 		 new_sz = str_len + MB_CUR_MAX; | |
| 611 | 		 if (!nstr) | |
| 612 | 		 { | |
| 613 | 		 release_ptrs (&gcollect, &wbuf); | |
| 614 | 		 return EOF; | |
| 615 | 		 } | |
| 616 | 		 *pstr = nstr; | |
| 617 | 		 str = nstr + str_len; | |
| 618 | 		 str_sz = new_sz; | |
| 619 | 		} | |
| 620 | ||
| 621 | 	 n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, &state); | |
| 622 | 	 if (n == (size_t) -1LL) | |
| 623 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 624 | 	 str += n; | |
| 625 | 	 } | |
| 626 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 627 | ||
| 628 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 629 | 	 { | |
| 630 | 	 optimize_alloc (pstr, str, str_sz); | |
| 631 | 	 pstr = NULL; | |
| 632 | 	 ++rval; | |
| 633 | 	 } | |
| 634 | ||
| 635 | 	 break; | |
| 636 | ||
| 637 | 	case 'C': | |
| 638 | 	 if (width == -1) | |
| 639 | 	 width = 1; | |
| 640 | ||
| 641 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 642 | 	 { | |
| 643 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 644 | 		{ | |
| 645 | 		 if (npos != 0) | |
| 646 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 647 | 		 else | |
| 648 | 		 pstr = va_arg (arg, char **); | |
| 649 | ||
| 650 | 		 if (!pstr) | |
| 651 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 652 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 653 | 		 *pstr = (char *) malloc (str_sz * sizeof (wchar_t)); | |
| 654 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 655 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 656 | ||
| 657 | 		 if ((wstr = (wchar_t *) *pstr) != NULL) | |
| 658 | 		 { | |
| 659 | 		 gcollect = resize_gcollect (gcollect); | |
| 660 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 661 | 		 } | |
| 662 | 		} | |
| 663 | 	 else | |
| 664 | 		{ | |
| 665 | 		 if (npos != 0) | |
| 666 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 667 | 		 else | |
| 668 | 		 wstr = va_arg (arg, wchar_t *); | |
| 669 | 		 if (!wstr) | |
| 670 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 671 | 		} | |
| 672 | 	 } | |
| 673 | ||
| 674 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 675 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 676 | ||
| 677 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 678 | 	 { | |
| 679 | 	 do | |
| 680 | 		{ | |
| 681 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 682 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 683 | 		 { | |
| 684 | 		 new_sz = str_sz + (str_sz > width ? width - 1 : str_sz); | |
| 685 | 		 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 686 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 687 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 688 | 			new_sz = str_sz + 1; | |
| 689 | 		 if (!wstr) | |
| 690 | 			{ | |
| 691 | 			 release_ptrs (&gcollect, &wbuf); | |
| 692 | 			 return EOF; | |
| 693 | 			} | |
| 694 | 		 *pstr = (char *) wstr; | |
| 695 | 		 wstr += str_sz; | |
| 696 | 		 str_sz = new_sz; | |
| 697 | 		 } | |
| 698 | 		 *wstr++ = c; | |
| 699 | 		} | |
| 700 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 701 | 	 } | |
| 702 | 	 else | |
| 703 | 	 { | |
| 704 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 705 | 	 } | |
| 706 | ||
| 707 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 708 | 	 { | |
| 709 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 710 | 	 pstr = NULL; | |
| 711 | 	 ++rval; | |
| 712 | 	 } | |
| 713 | 	 break; | |
| 714 | ||
| 715 | 	case 's': | |
| 716 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 717 | 	 { | |
| 718 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 719 | 		{ | |
| 720 | 		 if (npos != 0) | |
| 721 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 722 | 		 else | |
| 723 | 		 pstr = va_arg (arg, char **); | |
| 724 | ||
| 725 | 		 if (!pstr) | |
| 726 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 727 | 		 str_sz = 100; | |
| 728 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 729 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 730 | 		 gcollect = resize_gcollect (gcollect); | |
| 731 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 732 | 		} | |
| 733 | 	 else | |
| 734 | 		{ | |
| 735 | 		 if (npos != 0) | |
| 736 | 		 str = (char *) get_va_nth (argp, npos); | |
| 737 | 		 else | |
| 738 | 		 str = va_arg (arg, char *); | |
| 739 | 		 if (!str) | |
| 740 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 741 | 		} | |
| 742 | 	 } | |
| 743 | ||
| 744 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 745 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 746 | ||
| 747 | 	 memset (&state, 0, sizeof (state)); | |
| 748 | ||
| 749 | 	 do | |
| 750 | 	 { | |
| 751 | 	 if (iswspace (c)) | |
| 752 | 		{ | |
| 753 | 		 back_ch (c, s, &read_in, 1); | |
| 754 | 		 break; | |
| 755 | 		} | |
| 756 | ||
| 757 | 	 { | |
| 758 | 		if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 759 | 		 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 760 | 		 { | |
| 761 | 		 new_sz = str_sz * 2; | |
| 762 | 		 str_len = (str - *pstr); | |
| 763 | ||
| 764 | 		 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 765 | 			 && new_sz > (str_len + MB_CUR_MAX)) | |
| 766 | 		 new_sz = str_len + MB_CUR_MAX; | |
| 767 | 		 if (!nstr) | |
| 768 | 		 { | |
| 769 | 			if ((flags & USE_POSIX_ALLOC) == 0) | |
| 770 | 			 { | |
| 771 | 			 (*pstr)[str_len] = 0; | |
| 772 | 			 pstr = NULL; | |
| 773 | 			 ++rval; | |
| 774 | 			 } | |
| 775 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 776 | 		 } | |
| 777 | 		 *pstr = nstr; | |
| 778 | 		 str = nstr + str_len; | |
| 779 | 		 str_sz = new_sz; | |
| 780 | 		 } | |
| 781 | ||
| 782 | 		n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, | |
| 783 | 			 &state); | |
| 784 | 		if (n == (size_t) -1LL) | |
| 785 | 		{ | |
| 786 | 		 errno = EILSEQ; | |
| 787 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 788 | 		} | |
| 789 | ||
| 790 | 		str += n; | |
| 791 | 	 } | |
| 792 | 	 } | |
| 793 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != WEOF); | |
| 794 | ||
| 795 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 796 | 	 { | |
| 797 | 	 n = wcrtomb (buf, 0, &state); | |
| 798 | 	 if (n > 0 && (flags & IS_ALLOC_USED) != 0 | |
| 799 | 		 && (str + n) >= (*pstr + str_sz)) | |
| 800 | 		{ | |
| 801 | 		 str_len = (str - *pstr); | |
| 802 | ||
| 803 | 		 if ((nstr = (char *) realloc (*pstr, str_len + n + 1)) == NULL) | |
| 804 | 		 { | |
| 805 | 		 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 806 | 			{ | |
| 807 | 			 (*pstr)[str_len] = 0; | |
| 808 | 			 pstr = NULL; | |
| 809 | 			 ++rval; | |
| 810 | 			} | |
| 811 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 812 | 		 } | |
| 813 | 		 *pstr = nstr; | |
| 814 | 		 str = nstr + str_len; | |
| 815 | 		 str_sz = str_len + n + 1; | |
| 816 | 		} | |
| 817 | ||
| 818 | 	 if (n) | |
| 819 | 	 { | |
| 820 | 		memcpy (str, buf, n); | |
| 821 | 		str += n; | |
| 822 | 	 } | |
| 823 | 	 *str++ = 0; | |
| 824 | ||
| 825 | 	 optimize_alloc (pstr, str, str_sz); | |
| 826 | 	 pstr = NULL; | |
| 827 | 	 ++rval; | |
| 828 | 	 } | |
| 829 | 	 break; | |
| 830 | ||
| 831 | 	case 'S': | |
| 832 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 833 | 	 { | |
| 834 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 835 | 		{ | |
| 836 | 		 if (npos != 0) | |
| 837 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 838 | 		 else | |
| 839 | 		 pstr = va_arg (arg, char **); | |
| 840 | ||
| 841 | 		 if (!pstr) | |
| 842 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 843 | 		 str_sz = 100; | |
| 844 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 845 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 846 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 847 | 		 gcollect = resize_gcollect (gcollect); | |
| 848 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 849 | 		} | |
| 850 | 	 else | |
| 851 | 		{ | |
| 852 | 		 if (npos != 0) | |
| 853 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 854 | 		 else | |
| 855 | 		 wstr = va_arg (arg, wchar_t *); | |
| 856 | 		 if (!wstr) | |
| 857 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 858 | 		} | |
| 859 | 	 } | |
| 860 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 861 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 862 | ||
| 863 | 	 do | |
| 864 | 	 { | |
| 865 | 	 if (iswspace (c)) | |
| 866 | 		{ | |
| 867 | 		 back_ch (c, s, &read_in, 1); | |
| 868 | 		 break; | |
| 869 | 		} | |
| 870 | ||
| 871 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 872 | 		{ | |
| 873 | 		 *wstr++ = c; | |
| 874 | 		 if ((flags & IS_ALLOC_USED) != 0 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 875 | 		 { | |
| 876 | 		 new_sz = str_sz * 2; | |
| 877 | ||
| 878 | 		 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 879 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 880 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 881 | 			new_sz = str_sz + 1; | |
| 882 | 		 if (!wstr) | |
| 883 | 			{ | |
| 884 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 885 | 			 { | |
| 886 | 			 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 887 | 			 pstr = NULL; | |
| 888 | 			 ++rval; | |
| 889 | 			 } | |
| 890 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 891 | 			} | |
| 892 | 		 *pstr = (char *) wstr; | |
| 893 | 		 wstr += str_sz; | |
| 894 | 		 str_sz = new_sz; | |
| 895 | 		 } | |
| 896 | 		} | |
| 897 | 	 } | |
| 898 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != WEOF); | |
| 899 | ||
| 900 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 901 | 	 { | |
| 902 | 	 *wstr++ = 0; | |
| 903 | ||
| 904 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 905 | 	 pstr = NULL; | |
| 906 | 	 ++rval; | |
| 907 | 	 } | |
| 908 | 	 break; | |
| 909 | ||
| 910 | 	case 'd': case 'i': | |
| 911 | 	case 'o': case 'p': | |
| 912 | 	case 'u': | |
| 913 | 	case 'x': case 'X': | |
| 914 | 	 switch (fc) | |
| 915 | 	 { | |
| 916 | 	 case 'd': | |
| 917 | 	 flags |= IS_SIGNED_NUM; | |
| 918 | 	 base = 10; | |
| 919 | 	 break; | |
| 920 | 	 case 'i': | |
| 921 | 	 flags |= IS_SIGNED_NUM; | |
| 922 | 	 base = 0; | |
| 923 | 	 break; | |
| 924 | 	 case 'o': | |
| 925 | 	 base = 8; | |
| 926 | 	 break; | |
| 927 | 	 case 'p': | |
| 928 | 	 base = 16; | |
| 929 | 	 flags &= ~(IS_S | IS_LL | IS_L); | |
| 930 | #ifdef _WIN64 | |
| 931 | 	 flags |= IS_LL; | |
| 932 | #endif | |
| 933 | 	 flags |= IS_L | IS_POINTER; | |
| 934 | 	 break; | |
| 935 | 	 case 'u': | |
| 936 | 	 base = 10; | |
| 937 | 	 break; | |
| 938 | 	 case 'x': case 'X': | |
| 939 | 	 base = 16; | |
| 940 | 	 break; | |
| 941 | 	 } | |
| 942 | ||
| 943 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 944 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 945 | ||
| 946 | 	 if (c == '+' || c == '-') | |
| 947 | 	 { | |
| 948 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 949 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 950 | ||
| 951 | 	 if (width > 0) | |
| 952 | 		--width; | |
| 953 | 	 c = in_ch (s, &read_in); | |
| 954 | 	 } | |
| 955 | ||
| 956 | 	 if (width != 0 && c == '0') | |
| 957 | 	 { | |
| 958 | 	 if (width > 0) | |
| 959 | 		--width; | |
| 960 | ||
| 961 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 962 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 963 | ||
| 964 | 	 c = in_ch (s, &read_in); | |
| 965 | ||
| 966 | 	 if (width != 0 && towlower (c) == 'x') | |
| 967 | 		{ | |
| 968 | 		 if (!base) | |
| 969 | 		 base = 16; | |
| 970 | 		 if (base == 16) | |
| 971 | 		 { | |
| 972 | 		 if (width > 0) | |
| 973 | 			--width; | |
| 974 | 		 c = in_ch (s, &read_in); | |
| 975 | 		 } | |
| 976 | 		} | |
| 977 | 	 else if (!base) | |
| 978 | 		base = 8; | |
| 979 | 	 } | |
| 980 | ||
| 981 | 	 if (!base) | |
| 982 | 	 base = 10; | |
| 983 | ||
| 984 | 	 while (c != WEOF && width != 0) | |
| 985 | 	 { | |
| 986 | 	 if (base == 16) | |
| 987 | 		{ | |
| 988 | 		 if (!iswxdigit (c)) | |
| 989 | 		 break; | |
| 990 | 		} | |
| 991 | 	 else if (!iswdigit (c) || (int) (c - '0') >= base) | |
| 992 | 		{ | |
| 993 | 		 if (base != 10 || (flags & USE_GROUP) == 0 || c != lc_thousands_sep) | |
| 994 | 		 break; | |
| 995 | 		} | |
| 996 | 	 if (c != lc_thousands_sep) | |
| 997 | 	 { | |
| 998 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 999 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1000 | 		} | |
| 1001 | ||
| 1002 | 	 if (width > 0) | |
| 1003 | 		--width; | |
| 1004 | ||
| 1005 | 	 c = in_ch (s, &read_in); | |
| 1006 | 	 } | |
| 1007 | ||
| 1008 | 	 if (!wbuf_cur_sz || (wbuf_cur_sz == 1 && (wbuf[0] == '+' || wbuf[0] == '-'))) | |
| 1009 | 	 { | |
| 1010 | 	 if (!wbuf_cur_sz && (flags & IS_POINTER) != 0 | |
| 1011 | 		 && match_string (s, &read_in, &c, L"(nil)")) | |
| 1012 | 		{ | |
| 1013 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1014 | 		 wbuf[wbuf_cur_sz++] = '0'; | |
| 1015 | 		} | |
| 1016 | 	 else | |
| 1017 | 		{ | |
| 1018 | 		 back_ch (c, s, &read_in, 0); | |
| 1019 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1020 | 		} | |
| 1021 | 	 } | |
| 1022 | 	 else | |
| 1023 | 	 back_ch (c, s, &read_in, 0); | |
| 1024 | ||
| 1025 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1026 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1027 | ||
| 1028 | 	 if ((flags & IS_LL) != 0) | |
| 1029 | 	 { | |
| 1030 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1031 | 		cv_val.ll = wcstoll (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1032 | 	 else | |
| 1033 | 		cv_val.ull = wcstoull (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1034 | 	 } | |
| 1035 | 	 else | |
| 1036 | 	 { | |
| 1037 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1038 | 		cv_val.l = wcstol (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1039 | 	 else | |
| 1040 | 		cv_val.ul = wcstoul (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1041 | 	 } | |
| 1042 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1043 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1044 | ||
| 1045 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1046 | 	 { | |
| 1047 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1048 | 		{ | |
| 1049 | 		 if ((flags & IS_LL) != 0) | |
| 1050 | 		 *(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = cv_val.ll; | |
| 1051 | 		 else if ((flags & IS_L) != 0) | |
| 1052 | 		 *(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = cv_val.l; | |
| 1053 | 		 else if ((flags & IS_S) != 0) | |
| 1054 | 		 *(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = (short) cv_val.l; | |
| 1055 | 		 else if ((flags & IS_C) != 0) | |
| 1056 | 		 *(npos != 0 ? (signed char *) get_va_nth (argp, npos) : va_arg (arg, signed char *)) = (signed char) cv_val.ul; | |
| 1057 | 		 else | |
| 1058 | 		 *(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = (int) cv_val.l; | |
| 1059 | 		} | |
| 1060 | 	 else | |
| 1061 | 		{ | |
| 1062 | 		 if ((flags & IS_LL) != 0) | |
| 1063 | 		 *(npos != 0 ? (unsigned long long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long long *)) = cv_val.ull; | |
| 1064 | 		 else if ((flags & IS_L) != 0) | |
| 1065 | 		 *(npos != 0 ? (unsigned long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long *)) = cv_val.ul; | |
| 1066 | 		 else if ((flags & IS_S) != 0) | |
| 1067 | 		 *(npos != 0 ? (unsigned short *) get_va_nth (argp, npos) : va_arg (arg, unsigned short *)) | |
| 1068 | 		 = (unsigned short) cv_val.ul; | |
| 1069 | 		 else if ((flags & IS_C) != 0) | |
| 1070 | 		 *(npos != 0 ? (unsigned char *) get_va_nth (argp, npos) : va_arg (arg, unsigned char *)) = (unsigned char) cv_val.ul; | |
| 1071 | 		 else | |
| 1072 | 		 *(npos != 0 ? (unsigned int *) get_va_nth (argp, npos) : va_arg (arg, unsigned int *)) = (unsigned int) cv_val.ul; | |
| 1073 | 		} | |
| 1074 | 	 ++rval; | |
| 1075 | 	 } | |
| 1076 | 	 break; | |
| 1077 | ||
| 1078 | 	case 'e': case 'E': | |
| 1079 | 	case 'f': case 'F': | |
| 1080 | 	case 'g': case 'G': | |
| 1081 | 	case 'a': case 'A': | |
| 1082 | 	 if (width > 0) | |
| 1083 | 	 --width; | |
| 1084 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1085 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1086 | ||
| 1087 | 	 seen_dot = seen_exp = 0; | |
| 1088 | 	 is_neg = (c == '-' ? 1 : 0); | |
| 1089 | ||
| 1090 | 	 if (c == '-' || c == '+') | |
| 1091 | 	 { | |
| 1092 | 	 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF) | |
| 1093 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1094 | 	 if (width > 0) | |
| 1095 | 		--width; | |
| 1096 | 	 } | |
| 1097 | ||
| 1098 | 	 if (towlower (c) == 'n') | |
| 1099 | 	 { | |
| 1100 | 	 const wchar_t *match_txt = L"nan"; | |
| 1101 | ||
| 1102 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1103 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1104 | 	 | |
| 1105 | 	 ++match_txt; | |
| 1106 | 	 do | |
| 1107 | 		{ | |
| 1108 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1109 | 		 || towlower (c) != match_txt[0]) | |
| 1110 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1111 | 		 if (width > 0) | |
| 1112 | 		 --width; | |
| 1113 | ||
| 1114 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1115 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1116 | 		 ++match_txt; | |
| 1117 | 		} | |
| 1118 | 	 while (*match_txt != 0); | |
| 1119 | 	 } | |
| 1120 | 	 else if (towlower (c) == 'i') | |
| 1121 | 	 { | |
| 1122 | 	 const wchar_t *match_txt = L"inf"; | |
| 1123 | ||
| 1124 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1125 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1126 | ||
| 1127 | 	 ++match_txt; | |
| 1128 | 	 do | |
| 1129 | 		{ | |
| 1130 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1131 | 		 || towlower (c) != match_txt[0]) | |
| 1132 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1133 | 		 if (width > 0) | |
| 1134 | 		 --width; | |
| 1135 | ||
| 1136 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1137 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1138 | 		 ++match_txt; | |
| 1139 | 		} | |
| 1140 | 	 while (*match_txt != 0); | |
| 1141 | ||
| 1142 | 	 if (width != 0 && (c = in_ch (s, &read_in)) != WEOF && towlower (c) == 'i') | |
| 1143 | 		{ | |
| 1144 | 		 match_txt = L"inity"; | |
| 1145 | 		 if (width > 0) | |
| 1146 | 		 --width; | |
| 1147 | ||
| 1148 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1149 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1150 | ||
| 1151 | 		 ++match_txt; | |
| 1152 | 		 do | |
| 1153 | 		 { | |
| 1154 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1155 | 			 || towlower (c) != match_txt[0]) | |
| 1156 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1157 | 		 if (width > 0) | |
| 1158 | 			--width; | |
| 1159 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1160 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1161 | 		 ++match_txt; | |
| 1162 | 		 } | |
| 1163 | 		 while (*match_txt != 0); | |
| 1164 | 		} | |
| 1165 | 	 else if (width != 0 && c != WEOF) | |
| 1166 | 	 back_ch (c, s, &read_in, 0); | |
| 1167 | 	 } | |
| 1168 | 	 else | |
| 1169 | 	 { | |
| 1170 | 	 not_in = 'e'; | |
| 1171 | 	 if (width != 0 && c == '0') | |
| 1172 | 		{ | |
| 1173 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1174 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1175 | ||
| 1176 | 		 c = in_ch (s, &read_in); | |
| 1177 | 		 if (width > 0) | |
| 1178 | 		 --width; | |
| 1179 | 		 if (width != 0 && towlower (c) == 'x') | |
| 1180 | 		 { | |
| 1181 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1182 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1183 | 		 flags |= IS_HEX_FLOAT; | |
| 1184 | 		 not_in = 'p'; | |
| 1185 | ||
| 1186 | 		 flags &= ~USE_GROUP; | |
| 1187 | 		 c = in_ch (s, &read_in); | |
| 1188 | 		 if (width > 0) | |
| 1189 | 			--width; | |
| 1190 | 		 } | |
| 1191 | 		} | |
| 1192 | ||
| 1193 | 	 while (1) | |
| 1194 | 		{ | |
| 1195 | 		 if (iswdigit (c)) | |
| 1196 | 		 { | |
| 1197 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1198 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1199 | 		 } | |
| 1200 | 		 else if (!seen_exp && (flags & IS_HEX_FLOAT) != 0 && iswxdigit (c)) | |
| 1201 | 		 { | |
| 1202 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1203 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1204 | 		 } | |
| 1205 | 		 else if (seen_exp && wbuf[wbuf_cur_sz - 1] == not_in | |
| 1206 | 			 && (c == '-' || c == '+')) | |
| 1207 | 		 { | |
| 1208 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1209 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1210 | 		 } | |
| 1211 | 		 else if (wbuf_cur_sz > 0 && !seen_exp | |
| 1212 | 			 && (wchar_t) towlower (c) == not_in) | |
| 1213 | 		 { | |
| 1214 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1215 | 		 wbuf[wbuf_cur_sz++] = not_in; | |
| 1216 | ||
| 1217 | 		 seen_exp = seen_dot = 1; | |
| 1218 | 		 } | |
| 1219 | 		 else | |
| 1220 | 		 { | |
| 1221 | 		 if (!seen_dot && c == lc_decimal_point) | |
| 1222 | 			{ | |
| 1223 | 			 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1224 | 			 wbuf[wbuf_cur_sz++] = c; | |
| 1225 | ||
| 1226 | 			 seen_dot = 1; | |
| 1227 | 			} | |
| 1228 | 		 else if ((flags & USE_GROUP) != 0 && !seen_dot && c == lc_thousands_sep) | |
| 1229 | 			{ | |
| 1230 | 			 /* As our conversion routines aren't supporting thousands | |
| 1231 | 			 separators, we are filtering them here. */ | |
| 1232 | 			} | |
| 1233 | 		 else | |
| 1234 | 			{ | |
| 1235 | 			 back_ch (c, s, &read_in, 0); | |
| 1236 | 			 break; | |
| 1237 | 			} | |
| 1238 | 		 } | |
| 1239 | ||
| 1240 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF) | |
| 1241 | 		 break; | |
| 1242 | ||
| 1243 | 		 if (width > 0) | |
| 1244 | 		 --width; | |
| 1245 | 		} | |
| 1246 | ||
| 1247 | 	 if (wbuf_cur_sz == 0 || ((flags & IS_HEX_FLOAT) != 0 && wbuf_cur_sz == 2)) | |
| 1248 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1249 | 	 } | |
| 1250 | ||
| 1251 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1252 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1253 | ||
| 1254 | 	 if ((flags & IS_LL) != 0) | |
| 1255 | 	 { | |
| 1256 | 	 long double d = __mingw_wcstold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1257 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1258 | 		*(npos != 0 ? (long double *) get_va_nth (argp, npos) : va_arg (arg, long double *)) = is_neg ? -d : d; | |
| 1259 | 	 } | |
| 1260 | 	 else if ((flags & IS_L) != 0) | |
| 1261 | 	 { | |
| 1262 | 	 double d = __mingw_wcstod (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1263 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1264 | 		*(npos != 0 ? (double *) get_va_nth (argp, npos) : va_arg (arg, double *)) = is_neg ? -d : d; | |
| 1265 | 	 } | |
| 1266 | 	 else | |
| 1267 | 	 { | |
| 1268 | 	 float d = __mingw_wcstof (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1269 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1270 | 		*(npos != 0 ? (float *) get_va_nth (argp, npos) : va_arg (arg, float *)) = is_neg ? -d : d; | |
| 1271 | 	 } | |
| 1272 | ||
| 1273 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1274 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1275 | ||
| 1276 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1277 | 	 ++rval; | |
| 1278 | 	 break; | |
| 1279 | ||
| 1280 | 	case '[': | |
| 1281 | 	 if ((flags & IS_L) != 0) | |
| 1282 | 	 { | |
| 1283 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1284 | 		{ | |
| 1285 | 		 if ((flags & IS_ALLOC_USED) != 0) | |
| 1286 | 		 { | |
| 1287 | 		 if (npos != 0) | |
| 1288 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1289 | 		 else | |
| 1290 | 		 pstr = va_arg (arg, char **); | |
| 1291 | ||
| 1292 | 		 if (!pstr) | |
| 1293 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1294 | 		 str_sz = 100; | |
| 1295 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 1296 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 1297 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1298 | ||
| 1299 | 		 gcollect = resize_gcollect (gcollect); | |
| 1300 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1301 | 		 } | |
| 1302 | 		 else | |
| 1303 | 		 { | |
| 1304 | 		 if (npos != 0) | |
| 1305 | 			wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 1306 | 		 else | |
| 1307 | 			wstr = va_arg (arg, wchar_t *); | |
| 1308 | 		 if (!wstr) | |
| 1309 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1310 | 		 } | |
| 1311 | 		} | |
| 1312 | ||
| 1313 | 	 } | |
| 1314 | 	 else if ((flags & IS_SUPPRESSED) == 0) | |
| 1315 | 	 { | |
| 1316 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 1317 | 		{ | |
| 1318 | 		 if (npos != 0) | |
| 1319 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1320 | 		 else | |
| 1321 | 		 pstr = va_arg (arg, char **); | |
| 1322 | ||
| 1323 | 		 if (!pstr) | |
| 1324 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1325 | 		 str_sz = 100; | |
| 1326 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 1327 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1328 | 		 gcollect = resize_gcollect (gcollect); | |
| 1329 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1330 | 		} | |
| 1331 | 	 else | |
| 1332 | 		{ | |
| 1333 | 		 if (npos != 0) | |
| 1334 | 		 str = (char *) get_va_nth (argp, npos); | |
| 1335 | 		 else | |
| 1336 | 		 str = va_arg (arg, char *); | |
| 1337 | 		 if (!str) | |
| 1338 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1339 | 		} | |
| 1340 | 	 } | |
| 1341 | ||
| 1342 | 	 not_in = (*f == '^' ? 1 : 0); | |
| 1343 | 	 if (*f == '^') | |
| 1344 | 	 f++; | |
| 1345 | ||
| 1346 | 	 if (width < 0) | |
| 1347 | 	 width = INT_MAX; | |
| 1348 | ||
| 1349 | 	 tmp_wbuf_ptr = (wchar_t *) f; | |
| 1350 | ||
| 1351 | 	 if (*f == L']') | |
| 1352 | 	 ++f; | |
| 1353 | ||
| 1354 | 	 while ((fc = *f++) != 0 && fc != L']'); | |
| 1355 | ||
| 1356 | 	 if (fc == 0) | |
| 1357 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1358 | 	 temp_wbuf_end = (wchar_t *) f - 1; | |
| 1359 | ||
| 1360 | 	 if ((flags & IS_L) != 0) | |
| 1361 | 	 { | |
| 1362 | 	 read_in_sv = read_in; | |
| 1363 | ||
| 1364 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1365 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1366 | ||
| 1367 | 	 do | |
| 1368 | 		{ | |
| 1369 | 		 int ended = 0; | |
| 1370 | 		 for (wbuf_iter = tmp_wbuf_ptr; wbuf_iter < temp_wbuf_end;) | |
| 1371 | 		 { | |
| 1372 | 		 if (wbuf_iter[0] == '-' && wbuf_iter[1] != 0 | |
| 1373 | 			 && (wbuf_iter + 1) != temp_wbuf_end | |
| 1374 | 			 && wbuf_iter != tmp_wbuf_ptr | |
| 1375 | 			 && (unsigned int) wbuf_iter[-1] <= (unsigned int) wbuf_iter[1]) | |
| 1376 | 			{ | |
| 1377 | 			 for (wc = wbuf_iter[-1] + 1; wc <= wbuf_iter[1] && (wint_t) wc != c; ++wc); | |
| 1378 | ||
| 1379 | 			 if (wc <= wbuf_iter[1] && !not_in) | |
| 1380 | 			 break; | |
| 1381 | 			 if (wc <= wbuf_iter[1] && not_in) | |
| 1382 | 			 { | |
| 1383 | 			 back_ch (c, s, &read_in, 0); | |
| 1384 | 			 ended = 1; | |
| 1385 | 			 break; | |
| 1386 | 			 } | |
| 1387 | ||
| 1388 | 			 wbuf_iter += 2; | |
| 1389 | 			} | |
| 1390 | 		 else | |
| 1391 | 			{ | |
| 1392 | 			 if ((wint_t) *wbuf_iter == c && !not_in) | |
| 1393 | 			 break; | |
| 1394 | 			 if ((wint_t) *wbuf_iter == c && not_in) | |
| 1395 | 			 { | |
| 1396 | 			 back_ch (c, s, &read_in, 0); | |
| 1397 | 			 ended = 1; | |
| 1398 | 			 break; | |
| 1399 | 			 } | |
| 1400 | ||
| 1401 | 			 ++wbuf_iter; | |
| 1402 | 			} | |
| 1403 | 		 } | |
| 1404 | 		 if (ended) | |
| 1405 | 		 break; | |
| 1406 | ||
| 1407 | 		 if (wbuf_iter == temp_wbuf_end && !not_in) | |
| 1408 | 		 { | |
| 1409 | 		 back_ch (c, s, &read_in, 0); | |
| 1410 | 		 break; | |
| 1411 | 		 } | |
| 1412 | ||
| 1413 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1414 | 		 { | |
| 1415 | 		 *wstr++ = c; | |
| 1416 | ||
| 1417 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 1418 | 			 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 1419 | 			{ | |
| 1420 | 			 new_sz = str_sz * 2; | |
| 1421 | 			 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 1422 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 1423 | 				 && new_sz > (size_t) (str_sz + 1)) | |
| 1424 | 			 new_sz = str_sz + 1; | |
| 1425 | 			 if (!wstr) | |
| 1426 | 			 { | |
| 1427 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1428 | 				{ | |
| 1429 | 				 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 1430 | 				 pstr = NULL; | |
| 1431 | 				 ++rval; | |
| 1432 | 				} | |
| 1433 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1434 | 			 } | |
| 1435 | 			 *pstr = (char *) wstr; | |
| 1436 | 			 wstr += str_sz; | |
| 1437 | 			 str_sz = new_sz; | |
| 1438 | 			} | |
| 1439 | 		 } | |
| 1440 | 		} | |
| 1441 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 1442 | ||
| 1443 | 	 if (read_in_sv == read_in) | |
| 1444 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1445 | ||
| 1446 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1447 | 		{ | |
| 1448 | 		 *wstr++ = 0; | |
| 1449 | ||
| 1450 | 		 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 1451 | 		 pstr = NULL; | |
| 1452 | 		 ++rval; | |
| 1453 | 		} | |
| 1454 | 	 } | |
| 1455 | 	 else | |
| 1456 | 	 { | |
| 1457 | 	 read_in_sv = read_in; | |
| 1458 | ||
| 1459 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1460 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1461 | ||
| 1462 | 	 memset (&state, 0, sizeof (state)); | |
| 1463 | ||
| 1464 | 	 do | |
| 1465 | 		{ | |
| 1466 | 		 int ended = 0; | |
| 1467 | 		 wbuf_iter = tmp_wbuf_ptr; | |
| 1468 | 		 while (wbuf_iter < temp_wbuf_end) | |
| 1469 | 		 { | |
| 1470 | 		 if (wbuf_iter[0] == '-' && wbuf_iter[1] != 0 | |
| 1471 | 			 && (wbuf_iter + 1) != temp_wbuf_end | |
| 1472 | 			 && wbuf_iter != tmp_wbuf_ptr | |
| 1473 | 			 && (unsigned int) wbuf_iter[-1] <= (unsigned int) wbuf_iter[1]) | |
| 1474 | 			{ | |
| 1475 | 			 for (wc = wbuf_iter[-1] + 1; wc <= wbuf_iter[1] && (wint_t) wc != c; ++wc); | |
| 1476 | ||
| 1477 | 			 if (wc <= wbuf_iter[1] && !not_in) | |
| 1478 | 			 break; | |
| 1479 | 			 if (wc <= wbuf_iter[1] && not_in) | |
| 1480 | 			 { | |
| 1481 | 			 back_ch (c, s, &read_in, 0); | |
| 1482 | 			 ended = 1; | |
| 1483 | 			 break; | |
| 1484 | 			 } | |
| 1485 | ||
| 1486 | 			 wbuf_iter += 2; | |
| 1487 | 			} | |
| 1488 | 		 else | |
| 1489 | 			{ | |
| 1490 | 			 if ((wint_t) *wbuf_iter == c && !not_in) | |
| 1491 | 			 break; | |
| 1492 | 			 if ((wint_t) *wbuf_iter == c && not_in) | |
| 1493 | 			 { | |
| 1494 | 			 back_ch (c, s, &read_in, 0); | |
| 1495 | 			 ended = 1; | |
| 1496 | 			 break; | |
| 1497 | 			 } | |
| 1498 | ||
| 1499 | 			 ++wbuf_iter; | |
| 1500 | 			} | |
| 1501 | 		 } | |
| 1502 | ||
| 1503 | 		 if (ended) | |
| 1504 | 		 break; | |
| 1505 | 		 if (wbuf_iter == temp_wbuf_end && !not_in) | |
| 1506 | 		 { | |
| 1507 | 		 back_ch (c, s, &read_in, 0); | |
| 1508 | 		 break; | |
| 1509 | 		 } | |
| 1510 | ||
| 1511 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1512 | 		 { | |
| 1513 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 1514 | 			 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 1515 | 			{ | |
| 1516 | 			 new_sz = str_sz * 2; | |
| 1517 | 			 str_len = (str - *pstr); | |
| 1518 | ||
| 1519 | 			 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 1520 | 			 	 && new_sz > (str_len + MB_CUR_MAX)) | |
| 1521 | 			 new_sz = str_len + MB_CUR_MAX; | |
| 1522 | 			 if (!nstr) | |
| 1523 | 			 { | |
| 1524 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1525 | 				{ | |
| 1526 | 				 ((*pstr))[str_len] = 0; | |
| 1527 | 				 pstr = NULL; | |
| 1528 | 				 ++rval; | |
| 1529 | 				} | |
| 1530 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1531 | 			 } | |
| 1532 | 			 *pstr = nstr; | |
| 1533 | 			 str = nstr + str_len; | |
| 1534 | 			 str_sz = new_sz; | |
| 1535 | 			} | |
| 1536 | 		 } | |
| 1537 | ||
| 1538 | 		 n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, &state); | |
| 1539 | 		 if (n == (size_t) -1LL) | |
| 1540 | 		 { | |
| 1541 | 		 errno = EILSEQ; | |
| 1542 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1543 | 		 } | |
| 1544 | ||
| 1545 | 		 str += n; | |
| 1546 | 		} | |
| 1547 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 1548 | ||
| 1549 | 	 if (read_in_sv == read_in) | |
| 1550 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1551 | ||
| 1552 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1553 | 		{ | |
| 1554 | 		 n = wcrtomb (buf, 0, &state); | |
| 1555 | 		 if (n > 0 && (flags & IS_ALLOC_USED) != 0 | |
| 1556 | 		 && (str + n) >= (*pstr + str_sz)) | |
| 1557 | 		 { | |
| 1558 | 		 str_len = (str - *pstr); | |
| 1559 | ||
| 1560 | 		 if ((nstr = (char *) realloc (*pstr, str_len + n + 1)) == NULL) | |
| 1561 | 			{ | |
| 1562 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1563 | 			 { | |
| 1564 | 			 (*pstr)[str_len] = 0; | |
| 1565 | 			 pstr = NULL; | |
| 1566 | 			 ++rval; | |
| 1567 | 			 } | |
| 1568 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1569 | 			} | |
| 1570 | 		 *pstr = nstr; | |
| 1571 | 		 str = nstr + str_len; | |
| 1572 | 		 str_sz = str_len + n + 1; | |
| 1573 | 		 } | |
| 1574 | ||
| 1575 | 		 if (n) | |
| 1576 | 		 { | |
| 1577 | 		 memcpy (str, buf, n); | |
| 1578 | 		 str += n; | |
| 1579 | 		 } | |
| 1580 | 		 *str++ = 0; | |
| 1581 | ||
| 1582 | 		 optimize_alloc (pstr, str, str_sz); | |
| 1583 | 		 pstr = NULL; | |
| 1584 | 		 ++rval; | |
| 1585 | 		} | |
| 1586 | 	 } | |
| 1587 | 	 break; | |
| 1588 | ||
| 1589 | 	default: | |
| 1590 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1591 | 	} | |
| 1592 | } | |
| 1593 | ||
| 1594 | if (ignore_ws) | |
| 1595 | { | |
| 1596 | while (iswspace ((c = in_ch (s, &read_in)))); | |
| 1597 | back_ch (c, s, &read_in, 0); | |
| 1598 | } | |
| 1599 | ||
| 1600 | return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1601 | } |
lib/libc/mingw/stdio/mingw_swformat.h created+63| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #ifndef SWFORMAT_H | |
| 46 | #define SWFORMAT_H | |
| 47 | ||
| 48 | /* internal stream structure with back-buffer. */ | |
| 49 | typedef struct _IFPW | |
| 50 | { | |
| 51 | __extension__ union { | |
| 52 | void *fp; | |
| 53 | const wchar_t *str; | |
| 54 | }; | |
| 55 | int bch[1024]; | |
| 56 | unsigned int is_string : 1; | |
| 57 | int back_top; | |
| 58 | unsigned int seen_eof : 1; | |
| 59 | } _IFPW; | |
| 60 | ||
| 61 | int __cdecl __mingw_swformat(_IFPW *, const wchar_t *, va_list) __MINGW_NOTHROW; | |
| 62 | ||
| 63 | #endif /* !defined SWFORMAT_H */ |
lib/libc/mingw/stdio/mingw_swprintf.c created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | #define __BUILD_WIDEAPI_ISO 1 | |
| 8 | ||
| 9 | #include "mingw_snprintf.c" | |
| 10 |
lib/libc/mingw/stdio/mingw_vfprintfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vfprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_vfscanf.c+1-1619| ... | ... | @@ -1,1615 +1,8 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #define __LARGE_MBSTATE_T | |
| 46 | ||
| 47 | #include <limits.h> | |
| 48 | #include <stddef.h> | |
| 49 | 1 | #include <stdarg.h> |
| 50 | 2 | #include <stdio.h> |
| 51 | #include <stdint.h> | |
| 52 | #include <stdlib.h> | |
| 53 | 3 | #include <string.h> |
| 54 | #include <wchar.h> | |
| 55 | #include <ctype.h> | |
| 56 | #include <wctype.h> | |
| 57 | #include <locale.h> | |
| 58 | #include <errno.h> | |
| 59 | ||
| 60 | /* Helper flags for conversion. */ | |
| 61 | #define IS_C		0x0001 | |
| 62 | #define IS_S		0x0002 | |
| 63 | #define IS_L		0x0004 | |
| 64 | #define IS_LL		0x0008 | |
| 65 | #define IS_SIGNED_NUM	0x0010 | |
| 66 | #define IS_POINTER	0x0020 | |
| 67 | #define IS_HEX_FLOAT	0x0040 | |
| 68 | #define IS_SUPPRESSED	0x0080 | |
| 69 | #define USE_GROUP	0x0100 | |
| 70 | #define USE_GNU_ALLOC	0x0200 | |
| 71 | #define USE_POSIX_ALLOC	0x0400 | |
| 72 | ||
| 73 | #define IS_ALLOC_USED	(USE_GNU_ALLOC | USE_POSIX_ALLOC) | |
| 74 | ||
| 75 | /* internal stream structure with back-buffer. */ | |
| 76 | typedef struct _IFP | |
| 77 | { | |
| 78 | __extension__ union { | |
| 79 | void *fp; | |
| 80 | const char *str; | |
| 81 | }; | |
| 82 | int bch[1024]; | |
| 83 | unsigned int is_string : 1; | |
| 84 | int back_top; | |
| 85 | unsigned int seen_eof : 1; | |
| 86 | } _IFP; | |
| 87 | ||
| 88 | static void * | |
| 89 | get_va_nth (va_list argp, unsigned int n) | |
| 90 | { | |
| 91 | va_list ap; | |
| 92 | if (!n) abort (); | |
| 93 | va_copy (ap, argp); | |
| 94 | while (--n > 0) | |
| 95 | (void) va_arg(ap, void *); | |
| 96 | return va_arg (ap, void *); | |
| 97 | } | |
| 98 | ||
| 99 | static void | |
| 100 | optimize_alloc (char **p, char *end, size_t alloc_sz) | |
| 101 | { | |
| 102 | size_t need_sz; | |
| 103 | char *h; | |
| 104 | ||
| 105 | if (!p || !*p) | |
| 106 | return; | |
| 107 | ||
| 108 | need_sz = end - *p; | |
| 109 | if (need_sz == alloc_sz) | |
| 110 | return; | |
| 111 | ||
| 112 | if ((h = (char *) realloc (*p, need_sz)) != NULL) | |
| 113 | *p = h; | |
| 114 | } | |
| 115 | ||
| 116 | static void | |
| 117 | back_ch (int c, _IFP *s, size_t *rin, int not_eof) | |
| 118 | { | |
| 119 | if (!not_eof && c == EOF) | |
| 120 | return; | |
| 121 | if (s->is_string == 0) | |
| 122 | { | |
| 123 | FILE *fp = s->fp; | |
| 124 | ungetc (c, fp); | |
| 125 | rin[0] -= 1; | |
| 126 | return; | |
| 127 | } | |
| 128 | rin[0] -= 1; | |
| 129 | s->bch[s->back_top] = c; | |
| 130 | s->back_top += 1; | |
| 131 | } | |
| 132 | ||
| 133 | static int | |
| 134 | in_ch (_IFP *s, size_t *rin) | |
| 135 | { | |
| 136 | int r; | |
| 137 | if (s->back_top) | |
| 138 | { | |
| 139 | s->back_top -= 1; | |
| 140 | r = s->bch[s->back_top]; | |
| 141 | rin[0] += 1; | |
| 142 | } | |
| 143 | else if (s->seen_eof) | |
| 144 | { | |
| 145 | return EOF; | |
| 146 | } | |
| 147 | else if (s->is_string) | |
| 148 | { | |
| 149 | const char *ps = s->str; | |
| 150 | r = ((int) *ps) & 0xff; | |
| 151 | ps++; | |
| 152 | if (r != 0) | |
| 153 | { | |
| 154 | rin[0] += 1; | |
| 155 | s->str = ps; | |
| 156 | return r; | |
| 157 | } | |
| 158 | s->seen_eof = 1; | |
| 159 | return EOF; | |
| 160 | } | |
| 161 | else | |
| 162 | { | |
| 163 | FILE *fp = (FILE *) s->fp; | |
| 164 | r = getc (fp); | |
| 165 | if (r != EOF) | |
| 166 | rin[0] += 1; | |
| 167 | else s->seen_eof = 1; | |
| 168 | } | |
| 169 | return r; | |
| 170 | } | |
| 171 | ||
| 172 | static int | |
| 173 | match_string (_IFP *s, size_t *rin, int *c, const char *str) | |
| 174 | { | |
| 175 | int ch = *c; | |
| 176 | ||
| 177 | if (*str == 0) | |
| 178 | return 1; | |
| 179 | ||
| 180 | if (*str != (char) tolower (ch)) | |
| 181 | return 0; | |
| 182 | ++str; | |
| 183 | while (*str != 0) | |
| 184 | { | |
| 185 | if ((ch = in_ch (s, rin)) == EOF) | |
| 186 | { | |
| 187 | c[0] = ch; | |
| 188 | return 0; | |
| 189 | } | |
| 190 | ||
| 191 | if (*str != (char) tolower (ch)) | |
| 192 | { | |
| 193 | c[0] = ch; | |
| 194 | return 0; | |
| 195 | } | |
| 196 | ++str; | |
| 197 | } | |
| 198 | c[0] = ch; | |
| 199 | return 1; | |
| 200 | } | |
| 201 | ||
| 202 | struct gcollect | |
| 203 | { | |
| 204 | size_t count; | |
| 205 | struct gcollect *next; | |
| 206 | char **ptrs[32]; | |
| 207 | }; | |
| 208 | ||
| 209 | static void | |
| 210 | release_ptrs (struct gcollect **pt, char **wbuf) | |
| 211 | { | |
| 212 | struct gcollect *pf; | |
| 213 | size_t cnt; | |
| 214 | ||
| 215 | if (wbuf) | |
| 216 | { | |
| 217 | free (*wbuf); | |
| 218 | *wbuf = NULL; | |
| 219 | } | |
| 220 | if (!pt || (pf = *pt) == NULL) | |
| 221 | return; | |
| 222 | while (pf != NULL) | |
| 223 | { | |
| 224 | struct gcollect *pf_sv = pf; | |
| 225 | for (cnt = 0; cnt < pf->count; ++cnt) | |
| 226 | 	{ | |
| 227 | 	 free (*pf->ptrs[cnt]); | |
| 228 | 	 *pf->ptrs[cnt] = NULL; | |
| 229 | 	} | |
| 230 | pf = pf->next; | |
| 231 | free (pf_sv); | |
| 232 | } | |
| 233 | *pt = NULL; | |
| 234 | } | |
| 235 | ||
| 236 | static int | |
| 237 | cleanup_return (int rval, struct gcollect **pfree, char **strp, char **wbuf) | |
| 238 | { | |
| 239 | if (rval == EOF) | |
| 240 | release_ptrs (pfree, wbuf); | |
| 241 | else | |
| 242 | { | |
| 243 | if (pfree) | |
| 244 | { | |
| 245 | struct gcollect *pf = *pfree, *pf_sv; | |
| 246 | while (pf != NULL) | |
| 247 | { | |
| 248 | pf_sv = pf; | |
| 249 | pf = pf->next; | |
| 250 | free (pf_sv); | |
| 251 | } | |
| 252 | *pfree = NULL; | |
| 253 | } | |
| 254 | if (strp != NULL) | |
| 255 | 	{ | |
| 256 | 	 free (*strp); | |
| 257 | 	 *strp = NULL; | |
| 258 | 	} | |
| 259 | if (wbuf) | |
| 260 | 	{ | |
| 261 | 	 free (*wbuf); | |
| 262 | 	 *wbuf = NULL; | |
| 263 | 	} | |
| 264 | } | |
| 265 | return rval; | |
| 266 | } | |
| 267 | ||
| 268 | static struct gcollect * | |
| 269 | resize_gcollect (struct gcollect *pf) | |
| 270 | { | |
| 271 | struct gcollect *np; | |
| 272 | if (pf && pf->count < 32) | |
| 273 | return pf; | |
| 274 | np = malloc (sizeof (struct gcollect)); | |
| 275 | np->count = 0; | |
| 276 | np->next = pf; | |
| 277 | return np; | |
| 278 | } | |
| 279 | ||
| 280 | static char * | |
| 281 | resize_wbuf (size_t wpsz, size_t *wbuf_max_sz, char *old) | |
| 282 | { | |
| 283 | char *wbuf; | |
| 284 | size_t nsz; | |
| 285 | if (*wbuf_max_sz != wpsz) | |
| 286 | return old; | |
| 287 | nsz = (256 > (2 * wbuf_max_sz[0]) ? 256 : (2 * wbuf_max_sz[0])); | |
| 288 | if (!old) | |
| 289 | wbuf = (char *) malloc (nsz); | |
| 290 | else | |
| 291 | wbuf = (char *) realloc (old, nsz); | |
| 292 | if (!wbuf) | |
| 293 | { | |
| 294 | if (old) | |
| 295 | free (old); | |
| 296 | } | |
| 297 | else | |
| 298 | *wbuf_max_sz = nsz; | |
| 299 | return wbuf; | |
| 300 | } | |
| 301 | ||
| 302 | static int | |
| 303 | __mingw_sformat (_IFP *s, const char *format, va_list argp) | |
| 304 | { | |
| 305 | const char *f = format; | |
| 306 | struct gcollect *gcollect = NULL; | |
| 307 | size_t read_in = 0, wbuf_max_sz = 0, cnt; | |
| 308 | ssize_t str_sz = 0; | |
| 309 | char *str = NULL, **pstr = NULL, *wbuf = NULL; | |
| 310 | wchar_t *wstr = NULL; | |
| 311 | int rval = 0, c = 0, ignore_ws = 0; | |
| 312 | va_list arg; | |
| 313 | unsigned char fc; | |
| 314 | unsigned int npos; | |
| 315 | int width, flags, base = 0, errno_sv; | |
| 316 | size_t wbuf_cur_sz, read_in_sv, new_sz, n; | |
| 317 | char seen_dot, seen_exp, is_neg, not_in; | |
| 318 | char *tmp_wbuf_ptr, buf[MB_LEN_MAX]; | |
| 319 | const char *lc_decimal_point, *lc_thousands_sep; | |
| 320 | mbstate_t state, cstate; | |
| 321 | union { | |
| 322 | unsigned long long ull; | |
| 323 | unsigned long ul; | |
| 324 | long long ll; | |
| 325 | long l; | |
| 326 | } cv_val; | |
| 327 | ||
| 328 | arg = argp; | |
| 329 | ||
| 330 | if (!s || s->fp == NULL || !format) | |
| 331 | { | |
| 332 | errno = EINVAL; | |
| 333 | return EOF; | |
| 334 | } | |
| 335 | ||
| 336 | memset (&state, 0, sizeof (state)); | |
| 337 | ||
| 338 | lc_decimal_point = localeconv()->decimal_point; | |
| 339 | lc_thousands_sep = localeconv()->thousands_sep; | |
| 340 | if (lc_thousands_sep != NULL && *lc_thousands_sep == 0) | |
| 341 | lc_thousands_sep = NULL; | |
| 342 | ||
| 343 | while (*f != 0) | |
| 344 | { | |
| 345 | if (!isascii ((unsigned char) *f)) | |
| 346 | 	{ | |
| 347 | 	 int len; | |
| 348 | ||
| 349 | 	 if ((len = mbrlen (f, strlen (f), &state)) > 0) | |
| 350 | 	 { | |
| 351 | 	 do | |
| 352 | 		{ | |
| 353 | 		 if ((c = in_ch (s, &read_in)) == EOF || c != (unsigned char) *f++) | |
| 354 | 		 { | |
| 355 | 		 back_ch (c, s, &read_in, 1); | |
| 356 | 		 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 357 | 		 } | |
| 358 | 		} | |
| 359 | 	 while (--len > 0); | |
| 360 | ||
| 361 | 	 continue; | |
| 362 | 	 } | |
| 363 | 	} | |
| 364 | ||
| 365 | fc = *f++; | |
| 366 | if (fc != '%') | |
| 367 | { | |
| 368 | if (isspace (fc)) | |
| 369 | ignore_ws = 1; | |
| 370 | else | |
| 371 | 	 { | |
| 372 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 373 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 374 | ||
| 375 | 	 if (ignore_ws) | |
| 376 | 		{ | |
| 377 | 		 ignore_ws = 0; | |
| 378 | 		 if (isspace (c)) | |
| 379 | 		 { | |
| 380 | 		 do | |
| 381 | 			{ | |
| 382 | 			 if ((c = in_ch (s, &read_in)) == EOF) | |
| 383 | 			 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 384 | 			} | |
| 385 | 		 while (isspace (c)); | |
| 386 | 		 } | |
| 387 | 		} | |
| 388 | ||
| 389 | 	 if (c != fc) | |
| 390 | 		{ | |
| 391 | 		 back_ch (c, s, &read_in, 0); | |
| 392 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 393 | 		} | |
| 394 | 	 } | |
| 395 | ||
| 396 | 	 continue; | |
| 397 | 	} | |
| 398 | ||
| 399 | width = flags = 0; | |
| 400 | npos = 0; | |
| 401 | wbuf_cur_sz = 0; | |
| 402 | ||
| 403 | if (isdigit ((unsigned char) *f)) | |
| 404 | 	{ | |
| 405 | 	 const char *svf = f; | |
| 406 | 	 npos = (unsigned char) *f++ - '0'; | |
| 407 | 	 while (isdigit ((unsigned char) *f)) | |
| 408 | 	 npos = npos * 10 + ((unsigned char) *f++ - '0'); | |
| 409 | 	 if (*f != '$') | |
| 410 | 	 { | |
| 411 | 	 npos = 0; | |
| 412 | 	 f = svf; | |
| 413 | 	 } | |
| 414 | 	 else | |
| 415 | 	 f++; | |
| 416 | 	} | |
| 417 | ||
| 418 | do | |
| 419 | 	{ | |
| 420 | 	 if (*f == '*') | |
| 421 | 	 flags |= IS_SUPPRESSED; | |
| 422 | 	 else if (*f == '\'') | |
| 423 | 	 { | |
| 424 | 	 if (lc_thousands_sep) | |
| 425 | 		flags |= USE_GROUP; | |
| 426 | 	 } | |
| 427 | 	 else if (*f == 'I') | |
| 428 | 	 { | |
| 429 | 	 /* we don't support locale's digits (i18N), but ignore it for now silently. */ | |
| 430 | 	 ; | |
| 431 | #ifdef _WIN32 | |
| 432 | if (f[1] == '6' && f[2] == '4') | |
| 433 | { | |
| 434 | 		 flags |= IS_LL | IS_L; | |
| 435 | 		 f += 2; | |
| 436 | 		} | |
| 437 | 	 else if (f[1] == '3' && f[2] == '2') | |
| 438 | 		{ | |
| 439 | 		 flags |= IS_L; | |
| 440 | 		 f += 2; | |
| 441 | 		} | |
| 442 | 	 else | |
| 443 | 	 { | |
| 444 | #ifdef _WIN64 | |
| 445 | 		 flags |= IS_LL | IS_L; | |
| 446 | #else | |
| 447 | 		 flags |= IS_L; | |
| 448 | #endif | |
| 449 | 		} | |
| 450 | #endif | |
| 451 | 	 } | |
| 452 | 	 else | |
| 453 | 	 break; | |
| 454 | 	 ++f; | |
| 455 | } | |
| 456 | while (1); | |
| 457 | ||
| 458 | while (isdigit ((unsigned char) *f)) | |
| 459 | 	width = width * 10 + ((unsigned char) *f++ - '0'); | |
| 460 | ||
| 461 | if (!width) | |
| 462 | 	width = -1; | |
| 463 | ||
| 464 | switch (*f) | |
| 465 | 	{ | |
| 466 | 	case 'h': | |
| 467 | 	 ++f; | |
| 468 | 	 flags |= (*f == 'h' ? IS_C : IS_S); | |
| 469 | 	 if (*f == 'h') | |
| 470 | 	 ++f; | |
| 471 | 	 break; | |
| 472 | 	case 'l': | |
| 473 | 	 ++f; | |
| 474 | 	 flags |= (*f == 'l' ? IS_LL : 0) | IS_L; | |
| 475 | 	 if (*f == 'l') | |
| 476 | 	 ++f; | |
| 477 | 	 break; | |
| 478 | 	case 'q': case 'L': | |
| 479 | 	 ++f; | |
| 480 | 	 flags |= IS_LL | IS_L; | |
| 481 | 	 break; | |
| 482 | 	case 'a': | |
| 483 | 	 if (f[1] != 's' && f[1] != 'S' && f[1] != '[') | |
| 484 | 	 break; | |
| 485 | 	 ++f; | |
| 486 | 	 flags |= USE_GNU_ALLOC; | |
| 487 | 	 break; | |
| 488 | 	case 'm': | |
| 489 | 	 flags |= USE_POSIX_ALLOC; | |
| 490 | 	 ++f; | |
| 491 | 	 if (*f == 'l') | |
| 492 | 	 { | |
| 493 | 	 flags |= IS_L; | |
| 494 | 	 f++; | |
| 495 | 	 } | |
| 496 | 	 break; | |
| 497 | 	case 'z': | |
| 498 | #ifdef _WIN64 | |
| 499 | 	 flags |= IS_LL | IS_L; | |
| 500 | #else | |
| 501 | 	 flags |= IS_L; | |
| 502 | #endif | |
| 503 | 	 ++f; | |
| 504 | 	 break; | |
| 505 | 	case 'j': | |
| 506 | 	 if (sizeof (uintmax_t) > sizeof (unsigned long)) | |
| 507 | 	 flags |= IS_LL; | |
| 508 | 	 else if (sizeof (uintmax_t) > sizeof (unsigned int)) | |
| 509 | 	 flags |= IS_L; | |
| 510 | 	 ++f; | |
| 511 | 	 break; | |
| 512 | 	case 't': | |
| 513 | #ifdef _WIN64 | |
| 514 | 	 flags |= IS_LL; | |
| 515 | #else | |
| 516 | 	 flags |= IS_L; | |
| 517 | #endif | |
| 518 | 	 ++f; | |
| 519 | 	 break; | |
| 520 | 	case 0: | |
| 521 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 522 | 	default: | |
| 523 | 	 break; | |
| 524 | 	} | |
| 525 | ||
| 526 | if (*f == 0) | |
| 527 | 	return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 528 | ||
| 529 | fc = *f++; | |
| 530 | if (ignore_ws || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n')) | |
| 531 | 	{ | |
| 532 | 	 errno_sv = errno; | |
| 533 | 	 errno = 0; | |
| 534 | 	 do | |
| 535 | 	 { | |
| 536 | 	 if ((c == EOF || (c = in_ch (s, &read_in)) == EOF) | |
| 537 | 	 && errno == EINTR) | |
| 538 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 539 | 	 } | |
| 540 | 	 while (isspace (c)); | |
| 541 | ||
| 542 | 	 ignore_ws = 0; | |
| 543 | 	 errno = errno_sv; | |
| 544 | 	 back_ch (c, s, &read_in, 0); | |
| 545 | 	} | |
| 546 | ||
| 547 | switch (fc) | |
| 548 | { | |
| 549 | case 'c': | |
| 550 | if ((flags & IS_L) != 0) | |
| 551 | fc = 'C'; | |
| 552 | break; | |
| 553 | case 's': | |
| 554 | if ((flags & IS_L) != 0) | |
| 555 | fc = 'S'; | |
| 556 | break; | |
| 557 | } | |
| 558 | ||
| 559 | switch (fc) | |
| 560 | 	{ | |
| 561 | 	case '%': | |
| 562 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 563 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 564 | 	 if (c != fc) | |
| 565 | 	 { | |
| 566 | 	 back_ch (c, s, &read_in, 1); | |
| 567 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 568 | 	 } | |
| 569 | 	 break; | |
| 570 | ||
| 571 | 	case 'n': | |
| 572 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 573 | 	 { | |
| 574 | 	 if ((flags & IS_LL) != 0) | |
| 575 | 		*(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = read_in; | |
| 576 | 	 else if ((flags & IS_L) != 0) | |
| 577 | 		*(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = read_in; | |
| 578 | 	 else if ((flags & IS_S) != 0) | |
| 579 | 		*(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = read_in; | |
| 580 | 	 else if ((flags & IS_C) != 0) | |
| 581 | 	 *(npos != 0 ? (char *) get_va_nth (argp, npos) : va_arg (arg, char *)) = read_in; | |
| 582 | 	 else | |
| 583 | 		*(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = read_in; | |
| 584 | 	 } | |
| 585 | 	 break; | |
| 586 | ||
| 587 | 	case 'c': | |
| 588 | 	 if (width == -1) | |
| 589 | 	 width = 1; | |
| 590 | ||
| 591 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 592 | 	 { | |
| 593 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 594 | 		{ | |
| 595 | 		 if (npos != 0) | |
| 596 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 597 | 		 else | |
| 598 | 		 pstr = va_arg (arg, char **); | |
| 599 | ||
| 600 | 		 if (!pstr) | |
| 601 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 602 | ||
| 603 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 604 | 		 if ((str = *pstr = (char *) malloc (str_sz)) == NULL) | |
| 605 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 606 | ||
| 607 | 		 gcollect = resize_gcollect (gcollect); | |
| 608 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 609 | 		} | |
| 610 | 	 else | |
| 611 | 		{ | |
| 612 | 		 if (npos != 0) | |
| 613 | 		 str = (char *) get_va_nth (argp, npos); | |
| 614 | 		 else | |
| 615 | 		 str = va_arg (arg, char *); | |
| 616 | 		 if (!str) | |
| 617 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 618 | 		} | |
| 619 | 	 } | |
| 620 | ||
| 621 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 622 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 623 | ||
| 624 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 625 | 	 { | |
| 626 | 	 do | |
| 627 | 		{ | |
| 628 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 629 | 		 { | |
| 630 | 		 new_sz = str_sz + (str_sz >= width ? width - 1 : str_sz); | |
| 631 | 		 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 632 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 633 | 			new_sz = str_sz + 1; | |
| 634 | 		 if (!str) | |
| 635 | 			{ | |
| 636 | 			 release_ptrs (&gcollect, &wbuf); | |
| 637 | 			 return EOF; | |
| 638 | 			} | |
| 639 | 		 *pstr = str; | |
| 640 | 		 str += str_sz; | |
| 641 | 		 str_sz = new_sz; | |
| 642 | 		 } | |
| 643 | 		 *str++ = c; | |
| 644 | 		} | |
| 645 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 646 | 	 } | |
| 647 | 	 else | |
| 648 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 649 | ||
| 650 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 651 | 	 { | |
| 652 | 	 optimize_alloc (pstr, str, str_sz); | |
| 653 | 	 pstr = NULL; | |
| 654 | 	 ++rval; | |
| 655 | 	 } | |
| 656 | ||
| 657 | 	 break; | |
| 658 | ||
| 659 | 	case 'C': | |
| 660 | 	 if (width == -1) | |
| 661 | 	 width = 1; | |
| 662 | ||
| 663 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 664 | 	 { | |
| 665 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 666 | 		{ | |
| 667 | 		 if (npos != 0) | |
| 668 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 669 | 		 else | |
| 670 | 		 pstr = va_arg (arg, char **); | |
| 671 | ||
| 672 | 		 if (!pstr) | |
| 673 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 674 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 675 | 		 *pstr = (char *) malloc (str_sz * sizeof (wchar_t)); | |
| 676 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 677 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 678 | 		 gcollect = resize_gcollect (gcollect); | |
| 679 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 680 | 		} | |
| 681 | 	 else | |
| 682 | 		{ | |
| 683 | 		 if (npos != 0) | |
| 684 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 685 | 		 else | |
| 686 | 		 wstr = va_arg (arg, wchar_t *); | |
| 687 | 		 if (!wstr) | |
| 688 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 689 | 		} | |
| 690 | 	 } | |
| 691 | ||
| 692 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 693 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 694 | ||
| 695 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 696 | ||
| 697 | 	 do | |
| 698 | 	 { | |
| 699 | 	 buf[0] = c; | |
| 700 | ||
| 701 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 702 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 703 | 		{ | |
| 704 | 		 new_sz = str_sz + (str_sz > width ? width - 1 : str_sz); | |
| 705 | ||
| 706 | 		 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 707 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 708 | 		 new_sz = str_sz + 1; | |
| 709 | 		 if (!wstr) | |
| 710 | 		 { | |
| 711 | 		 release_ptrs (&gcollect, &wbuf); | |
| 712 | 		 return EOF; | |
| 713 | 		 } | |
| 714 | 		 *pstr = (char *) wstr; | |
| 715 | 		 wstr += str_sz; | |
| 716 | 		 str_sz = new_sz; | |
| 717 | 		} | |
| 718 | ||
| 719 | 	 while (1) | |
| 720 | 		{ | |
| 721 | 		 n = mbrtowc ((flags & IS_SUPPRESSED) == 0 ? wstr : NULL, buf, 1, &cstate); | |
| 722 | ||
| 723 | 		 if (n == (size_t) -2) | |
| 724 | 		 { | |
| 725 | 		 if ((c = in_ch (s, &read_in)) == EOF) | |
| 726 | 			{ | |
| 727 | 			 errno = EILSEQ; | |
| 728 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 729 | 			} | |
| 730 | ||
| 731 | 		 buf[0] = c; | |
| 732 | 		 continue; | |
| 733 | 		 } | |
| 734 | ||
| 735 | 		 if (n != 1) | |
| 736 | 		 { | |
| 737 | 			errno = EILSEQ; | |
| 738 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 739 | 		 } | |
| 740 | 		 break; | |
| 741 | 		} | |
| 742 | ||
| 743 | 	 ++wstr; | |
| 744 | 	 } | |
| 745 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 746 | ||
| 747 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 748 | 	 { | |
| 749 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 750 | 	 pstr = NULL; | |
| 751 | 	 ++rval; | |
| 752 | 	 } | |
| 753 | 	 break; | |
| 754 | ||
| 755 | 	case 's': | |
| 756 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 757 | 	 { | |
| 758 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 759 | 		{ | |
| 760 | 		 if (npos != 0) | |
| 761 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 762 | 		 else | |
| 763 | 		 pstr = va_arg (arg, char **); | |
| 764 | ||
| 765 | 		 if (!pstr) | |
| 766 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 767 | ||
| 768 | 		 str_sz = 100; | |
| 769 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 770 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 771 | 		 gcollect = resize_gcollect (gcollect); | |
| 772 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 773 | 		} | |
| 774 | 	 else | |
| 775 | 		{ | |
| 776 | 		 if (npos != 0) | |
| 777 | 		 str = (char *) get_va_nth (argp, npos); | |
| 778 | 		 else | |
| 779 | 		 str = va_arg (arg, char *); | |
| 780 | 		 if (!str) | |
| 781 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 782 | 		} | |
| 783 | 	 } | |
| 784 | ||
| 785 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 786 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 787 | ||
| 788 | 	 do | |
| 789 | 	 { | |
| 790 | 	 if (isspace (c)) | |
| 791 | 		{ | |
| 792 | 		 back_ch (c, s, &read_in, 1); | |
| 793 | 		 break; | |
| 794 | 		} | |
| 795 | ||
| 796 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 797 | 		{ | |
| 798 | 		 *str++ = c; | |
| 799 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 800 | 		 { | |
| 801 | 		 new_sz = str_sz * 2; | |
| 802 | ||
| 803 | 		 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 804 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 805 | 			new_sz = str_sz + 1; | |
| 806 | 		 if (!str) | |
| 807 | 			{ | |
| 808 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 809 | 			 { | |
| 810 | 			 (*pstr)[str_sz - 1] = 0; | |
| 811 | 			 pstr = NULL; | |
| 812 | 			 ++rval; | |
| 813 | 			 } | |
| 814 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 815 | 			} | |
| 816 | 		 *pstr = str; | |
| 817 | 		 str += str_sz; | |
| 818 | 		 str_sz = new_sz; | |
| 819 | 		 } | |
| 820 | 		} | |
| 821 | 	 } | |
| 822 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != EOF); | |
| 823 | 4 | |
| 824 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 825 | 	 { | |
| 826 | 	 *str++ = 0; | |
| 827 | 	 optimize_alloc (pstr, str, str_sz); | |
| 828 | 	 pstr = NULL; | |
| 829 | 	 ++rval; | |
| 830 | 	 } | |
| 831 | 	 break; | |
| 832 | ||
| 833 | 	case 'S': | |
| 834 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 835 | 	 { | |
| 836 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 837 | 		{ | |
| 838 | 		 if (npos != 0) | |
| 839 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 840 | 		 else | |
| 841 | 		 pstr = va_arg (arg, char **); | |
| 842 | ||
| 843 | 		 if (!pstr) | |
| 844 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 845 | ||
| 846 | 		 str_sz = 100; | |
| 847 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 848 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 849 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 850 | 		 gcollect = resize_gcollect (gcollect); | |
| 851 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 852 | 		} | |
| 853 | 	 else | |
| 854 | 		{ | |
| 855 | 		 if (npos != 0) | |
| 856 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 857 | 		 else | |
| 858 | 		 wstr = va_arg (arg, wchar_t *); | |
| 859 | 		 if (!wstr) | |
| 860 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 861 | 		} | |
| 862 | 	 } | |
| 863 | ||
| 864 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 865 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 866 | ||
| 867 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 868 | ||
| 869 | 	 do | |
| 870 | 	 { | |
| 871 | 	 if (isspace (c)) | |
| 872 | 		{ | |
| 873 | 		 back_ch (c, s, &read_in, 1); | |
| 874 | 		 break; | |
| 875 | 		} | |
| 876 | ||
| 877 | 	 buf[0] = c; | |
| 878 | ||
| 879 | 	 while (1) | |
| 880 | 		{ | |
| 881 | 		 n = mbrtowc ((flags & IS_SUPPRESSED) == 0 ? wstr : NULL, buf, 1, &cstate); | |
| 882 | ||
| 883 | 		 if (n == (size_t) -2) | |
| 884 | 		 { | |
| 885 | 		 if ((c = in_ch (s, &read_in)) == EOF) | |
| 886 | 			{ | |
| 887 | 			 errno = EILSEQ; | |
| 888 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 889 | 			} | |
| 890 | ||
| 891 | 		 buf[0] = c; | |
| 892 | 		 continue; | |
| 893 | 		 } | |
| 894 | ||
| 895 | 		 if (n != 1) | |
| 896 | 		 { | |
| 897 | 		 errno = EILSEQ; | |
| 898 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 899 | 		 } | |
| 900 | ||
| 901 | 		 ++wstr; | |
| 902 | 		 break; | |
| 903 | 		} | |
| 904 | ||
| 905 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 906 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 907 | 		{ | |
| 908 | 		 new_sz = str_sz * 2; | |
| 909 | 		 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 910 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 911 | 		 new_sz = str_sz + 1; | |
| 912 | 		 if (!wstr) | |
| 913 | 		 { | |
| 914 | 		 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 915 | 			{ | |
| 916 | 			 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 917 | 			 pstr = NULL; | |
| 918 | 			 ++rval; | |
| 919 | 			} | |
| 920 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 921 | 		 } | |
| 922 | 		 *pstr = (char *) wstr; | |
| 923 | 		 wstr += str_sz; | |
| 924 | 		 str_sz = new_sz; | |
| 925 | 		} | |
| 926 | 	 } | |
| 927 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != EOF); | |
| 928 | ||
| 929 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 930 | 	 { | |
| 931 | 	 *wstr++ = 0; | |
| 932 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 933 | 	 pstr = NULL; | |
| 934 | 	 ++rval; | |
| 935 | 	 } | |
| 936 | 	 break; | |
| 937 | ||
| 938 | 	case 'd': case 'i': | |
| 939 | 	case 'o': case 'p': | |
| 940 | 	case 'u': | |
| 941 | 	case 'x': case 'X': | |
| 942 | 	 switch (fc) | |
| 943 | 	 { | |
| 944 | 	 case 'd': | |
| 945 | 	 flags |= IS_SIGNED_NUM; | |
| 946 | 	 base = 10; | |
| 947 | 	 break; | |
| 948 | 	 case 'i': | |
| 949 | 	 flags |= IS_SIGNED_NUM; | |
| 950 | 	 base = 0; | |
| 951 | 	 break; | |
| 952 | 	 case 'o': | |
| 953 | 	 base = 8; | |
| 954 | 	 break; | |
| 955 | 	 case 'p': | |
| 956 | 	 base = 16; | |
| 957 | 	 flags &= ~(IS_S | IS_LL | IS_L); | |
| 958 | #ifdef _WIN64 | |
| 959 | 	 flags |= IS_LL; | |
| 960 | #endif | |
| 961 | 	 flags |= IS_L | IS_POINTER; | |
| 962 | 	 break; | |
| 963 | 	 case 'u': | |
| 964 | 	 base = 10; | |
| 965 | 	 break; | |
| 966 | 	 case 'x': case 'X': | |
| 967 | 	 base = 16; | |
| 968 | 	 break; | |
| 969 | 	 } | |
| 970 | ||
| 971 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 972 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 973 | 	 if (c == '+' || c == '-') | |
| 974 | 	 { | |
| 975 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 976 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 977 | 	 if (width > 0) | |
| 978 | 		--width; | |
| 979 | 	 c = in_ch (s, &read_in); | |
| 980 | 	 } | |
| 981 | 	 if (width != 0 && c == '0') | |
| 982 | 	 { | |
| 983 | 	 if (width > 0) | |
| 984 | 		--width; | |
| 985 | ||
| 986 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 987 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 988 | 	 c = in_ch (s, &read_in); | |
| 989 | ||
| 990 | 	 if (width != 0 && tolower (c) == 'x') | |
| 991 | 		{ | |
| 992 | 		 if (!base) | |
| 993 | 		 base = 16; | |
| 994 | 		 if (base == 16) | |
| 995 | 		 { | |
| 996 | 		 if (width > 0) | |
| 997 | 			--width; | |
| 998 | 		 c = in_ch (s, &read_in); | |
| 999 | 		 } | |
| 1000 | 		} | |
| 1001 | 	 else if (!base) | |
| 1002 | 		base = 8; | |
| 1003 | 	 } | |
| 1004 | ||
| 1005 | 	 if (!base) | |
| 1006 | 	 base = 10; | |
| 1007 | ||
| 1008 | 	 while (c != EOF && width != 0) | |
| 1009 | 	 { | |
| 1010 | 	 if (base == 16) | |
| 1011 | 		{ | |
| 1012 | 		 if (!isxdigit (c)) | |
| 1013 | 		 break; | |
| 1014 | 		} | |
| 1015 | 	 else if (!isdigit (c) || (int) (c - '0') >= base) | |
| 1016 | 		{ | |
| 1017 | 		 const char *p = lc_thousands_sep; | |
| 1018 | 		 int remain; | |
| 1019 | ||
| 1020 | 		 if (base != 10 || (flags & USE_GROUP) == 0) | |
| 1021 | 		 break; | |
| 1022 | 		 remain = width > 0 ? width : INT_MAX; | |
| 1023 | 		 while ((unsigned char) *p == c && remain >= 0) | |
| 1024 | 		 { | |
| 1025 | 		 /* As our conversion routines aren't supporting thousands | |
| 1026 | 			 separators, we are filtering them here. */ | |
| 1027 | ||
| 1028 | 		 ++p; | |
| 1029 | 		 if (*p == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1030 | 			break; | |
| 1031 | 		 --remain; | |
| 1032 | 		 } | |
| 1033 | ||
| 1034 | 		 if (*p != 0) | |
| 1035 | 		 { | |
| 1036 | 		 if (p > lc_thousands_sep) | |
| 1037 | 			{ | |
| 1038 | 			 back_ch (c, s, &read_in, 0); | |
| 1039 | 			 while (--p > lc_thousands_sep) | |
| 1040 | 			 back_ch ((unsigned char) *p, s, &read_in, 1); | |
| 1041 | 			 c = (unsigned char) *p; | |
| 1042 | 			} | |
| 1043 | 		 break; | |
| 1044 | 		 } | |
| 1045 | ||
| 1046 | 		 if (width > 0) | |
| 1047 | 		 width = remain; | |
| 1048 | 		 --wbuf_cur_sz; | |
| 1049 | 		} | |
| 1050 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1051 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1052 | 	 if (width > 0) | |
| 1053 | 		--width; | |
| 1054 | ||
| 1055 | 	 c = in_ch (s, &read_in); | |
| 1056 | 	 } | |
| 1057 | ||
| 1058 | 	 if (!wbuf_cur_sz || (wbuf_cur_sz == 1 && (wbuf[0] == '+' || wbuf[0] == '-'))) | |
| 1059 | 	 { | |
| 1060 | 	 if (!wbuf_cur_sz && (flags & IS_POINTER) != 0 | |
| 1061 | 	 && match_string (s, &read_in, &c, "(nil)")) | |
| 1062 | 		{ | |
| 1063 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1064 | 		 wbuf[wbuf_cur_sz++] = '0'; | |
| 1065 | 		} | |
| 1066 | 	 else | |
| 1067 | 		{ | |
| 1068 | 		 back_ch (c, s, &read_in, 0); | |
| 1069 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1070 | 		} | |
| 1071 | 	 } | |
| 1072 | 	 else | |
| 1073 | 	 back_ch (c, s, &read_in, 0); | |
| 1074 | ||
| 1075 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1076 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1077 | ||
| 1078 | 	 if ((flags & IS_LL)) | |
| 1079 | 	 { | |
| 1080 | 	 if (flags & IS_SIGNED_NUM) | |
| 1081 | 		cv_val.ll = strtoll (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1082 | 	 else | |
| 1083 | 		cv_val.ull = strtoull (wbuf, &tmp_wbuf_ptr, base); | |
| 1084 | 	 } | |
| 1085 | 	 else | |
| 1086 | 	 { | |
| 1087 | 	 if (flags & IS_SIGNED_NUM) | |
| 1088 | 		cv_val.l = strtol (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1089 | 	 else | |
| 1090 | 		cv_val.ul = strtoul (wbuf, &tmp_wbuf_ptr, base); | |
| 1091 | 	 } | |
| 1092 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1093 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1094 | ||
| 1095 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1096 | 	 { | |
| 1097 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1098 | 		{ | |
| 1099 | 		 if ((flags & IS_LL) != 0) | |
| 1100 | 		 *(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = cv_val.ll; | |
| 1101 | 		 else if ((flags & IS_L) != 0) | |
| 1102 | 		 *(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = cv_val.l; | |
| 1103 | 		 else if ((flags & IS_S) != 0) | |
| 1104 | 		 *(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = (short) cv_val.l; | |
| 1105 | 		 else if ((flags & IS_C) != 0) | |
| 1106 | 		 *(npos != 0 ? (signed char *) get_va_nth (argp, npos) : va_arg (arg, signed char *)) = (signed char) cv_val.ul; | |
| 1107 | 		 else | |
| 1108 | 		 *(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = (int) cv_val.l; | |
| 1109 | 		} | |
| 1110 | 	 else | |
| 1111 | 		{ | |
| 1112 | 		 if ((flags & IS_LL) != 0) | |
| 1113 | 		 *(npos != 0 ? (unsigned long long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long long *)) = cv_val.ull; | |
| 1114 | 		 else if ((flags & IS_L) != 0) | |
| 1115 | 		 *(npos != 0 ? (unsigned long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long *)) = cv_val.ul; | |
| 1116 | 		 else if ((flags & IS_S) != 0) | |
| 1117 | 		 *(npos != 0 ? (unsigned short *) get_va_nth (argp, npos) : va_arg (arg, unsigned short *)) | |
| 1118 | 		 = (unsigned short) cv_val.ul; | |
| 1119 | 		 else if ((flags & IS_C) != 0) | |
| 1120 | 		 *(npos != 0 ? (unsigned char *) get_va_nth (argp, npos) : va_arg (arg, unsigned char *)) = (unsigned char) cv_val.ul; | |
| 1121 | 		 else | |
| 1122 | 		 *(npos != 0 ? (unsigned int *) get_va_nth (argp, npos) : va_arg (arg, unsigned int *)) = (unsigned int) cv_val.ul; | |
| 1123 | 		} | |
| 1124 | 	 ++rval; | |
| 1125 | 	 } | |
| 1126 | 	 break; | |
| 1127 | ||
| 1128 | 	case 'e': case 'E': | |
| 1129 | 	case 'f': case 'F': | |
| 1130 | 	case 'g': case 'G': | |
| 1131 | 	case 'a': case 'A': | |
| 1132 | 	 if (width > 0) | |
| 1133 | 	 --width; | |
| 1134 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1135 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1136 | ||
| 1137 | 	 seen_dot = seen_exp = 0; | |
| 1138 | 	 is_neg = (c == '-' ? 1 : 0); | |
| 1139 | ||
| 1140 | 	 if (c == '-' || c == '+') | |
| 1141 | 	 { | |
| 1142 | 	 if (width == 0 || (c = in_ch (s, &read_in)) == EOF) | |
| 1143 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1144 | 	 if (width > 0) | |
| 1145 | 		--width; | |
| 1146 | 	 } | |
| 1147 | ||
| 1148 | 	 if (tolower (c) == 'n') | |
| 1149 | 	 { | |
| 1150 | 	 const char *match_txt = "nan"; | |
| 1151 | ||
| 1152 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1153 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1154 | ||
| 1155 | 	 ++match_txt; | |
| 1156 | 	 do | |
| 1157 | 		{ | |
| 1158 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1159 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1160 | ||
| 1161 | 		 if (width > 0) | |
| 1162 | 		 --width; | |
| 1163 | ||
| 1164 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1165 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1166 | 		 ++match_txt; | |
| 1167 | 		} | |
| 1168 | 	 while (*match_txt != 0); | |
| 1169 | 	 } | |
| 1170 | 	 else if (tolower (c) == 'i') | |
| 1171 | 	 { | |
| 1172 | 	 const char *match_txt = "inf"; | |
| 1173 | ||
| 1174 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1175 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1176 | ||
| 1177 | 	 ++match_txt; | |
| 1178 | 	 do | |
| 1179 | 		{ | |
| 1180 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1181 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1182 | 		 if (width > 0) | |
| 1183 | 		 --width; | |
| 1184 | ||
| 1185 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1186 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1187 | 		 ++match_txt; | |
| 1188 | 		} | |
| 1189 | 	 while (*match_txt != 0); | |
| 1190 | ||
| 1191 | 	 if (width != 0 && (c = in_ch (s, &read_in)) != EOF && tolower (c) == 'i') | |
| 1192 | 		{ | |
| 1193 | 		 match_txt = "inity"; | |
| 1194 | ||
| 1195 | 		 if (width > 0) | |
| 1196 | 		 --width; | |
| 1197 | ||
| 1198 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1199 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1200 | 		 ++match_txt; | |
| 1201 | ||
| 1202 | 		 do | |
| 1203 | 		 { | |
| 1204 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF || tolower (c) != match_txt[0]) | |
| 1205 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1206 | 		 if (width > 0) | |
| 1207 | 			--width; | |
| 1208 | ||
| 1209 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1210 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1211 | 		 ++match_txt; | |
| 1212 | 		 } | |
| 1213 | 		 while (*match_txt != 0); | |
| 1214 | 		} | |
| 1215 | 	 else if (width != 0 && c != EOF) | |
| 1216 | 	 back_ch (c, s, &read_in, 0); | |
| 1217 | 	 } | |
| 1218 | 	 else | |
| 1219 | 	 { | |
| 1220 | 	 not_in = 'e'; | |
| 1221 | 	 if (width != 0 && c == '0') | |
| 1222 | 		{ | |
| 1223 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1224 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1225 | ||
| 1226 | 		 c = in_ch (s, &read_in); | |
| 1227 | 		 if (width > 0) | |
| 1228 | 		 --width; | |
| 1229 | 		 if (width != 0 && tolower (c) == 'x') | |
| 1230 | 		 { | |
| 1231 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1232 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1233 | ||
| 1234 | 		 flags |= IS_HEX_FLOAT; | |
| 1235 | 		 not_in = 'p'; | |
| 1236 | ||
| 1237 | 		 flags &= ~USE_GROUP; | |
| 1238 | 		 c = in_ch (s, &read_in); | |
| 1239 | 		 if (width > 0) | |
| 1240 | 			--width; | |
| 1241 | 		 } | |
| 1242 | 		} | |
| 1243 | ||
| 1244 | 	 while (1) | |
| 1245 | 		{ | |
| 1246 | 		 if (isdigit (c) || (!seen_exp && (flags & IS_HEX_FLOAT) != 0 && isxdigit (c)) | |
| 1247 | 		 || (seen_exp && wbuf[wbuf_cur_sz - 1] == not_in && (c == '-' || c == '+'))) | |
| 1248 | 		 { | |
| 1249 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1250 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1251 | 		 } | |
| 1252 | 		 else if (wbuf_cur_sz > 0 && !seen_exp && (char) tolower (c) == not_in) | |
| 1253 | 		 { | |
| 1254 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1255 | 		 wbuf[wbuf_cur_sz++] = not_in; | |
| 1256 | 		 seen_exp = seen_dot = 1; | |
| 1257 | 		 } | |
| 1258 | 		 else | |
| 1259 | 		 { | |
| 1260 | 		 const char *p = lc_decimal_point; | |
| 1261 | 		 int remain = width > 0 ? width : INT_MAX; | |
| 1262 | ||
| 1263 | 		 if (! seen_dot) | |
| 1264 | 			{ | |
| 1265 | 			 while ((unsigned char) *p == c && remain >= 0) | |
| 1266 | 			 { | |
| 1267 | 			 ++p; | |
| 1268 | 			 if (*p == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1269 | 				break; | |
| 1270 | 			 --remain; | |
| 1271 | 			 } | |
| 1272 | 			} | |
| 1273 | ||
| 1274 | 		 if (*p == 0) | |
| 1275 | 			{ | |
| 1276 | 			 for (p = lc_decimal_point; *p != 0; ++p) | |
| 1277 | 			 { | |
| 1278 | 			 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1279 | 			 wbuf[wbuf_cur_sz++] = (unsigned char) *p; | |
| 1280 | 			 } | |
| 1281 | 			 if (width > 0) | |
| 1282 | 			 width = remain; | |
| 1283 | 			 seen_dot = 1; | |
| 1284 | 			} | |
| 1285 | 		 else | |
| 1286 | 			{ | |
| 1287 | 			 const char *pp = lc_thousands_sep; | |
| 1288 | ||
| 1289 | 			 if (!seen_dot && (flags & USE_GROUP) != 0) | |
| 1290 | 			 { | |
| 1291 | 			 while ((pp - lc_thousands_sep) < (p - lc_decimal_point) | |
| 1292 | 				 && *pp == lc_decimal_point[(pp - lc_thousands_sep)]) | |
| 1293 | 				++pp; | |
| 1294 | 			 if ((pp - lc_thousands_sep) == (p - lc_decimal_point)) | |
| 1295 | 				{ | |
| 1296 | 				 while ((unsigned char) *pp == c && remain >= 0) | |
| 1297 | 				 { | |
| 1298 | 				 ++pp; | |
| 1299 | 				 if (*pp == 0 || !remain || (c = in_ch (s, &read_in)) == EOF) | |
| 1300 | 					break; | |
| 1301 | 				 --remain; | |
| 1302 | 				 } | |
| 1303 | 				} | |
| 1304 | 			 } | |
| 1305 | ||
| 1306 | 			 if (pp != NULL && *pp == 0) | |
| 1307 | 			 { | |
| 1308 | 			 /* As our conversion routines aren't supporting thousands | |
| 1309 | 				 separators, we are filtering them here. */ | |
| 1310 | 			 if (width > 0) | |
| 1311 | 				width = remain; | |
| 1312 | 			 } | |
| 1313 | 			 else | |
| 1314 | 			 { | |
| 1315 | 			 back_ch (c, s, &read_in, 0); | |
| 1316 | 			 break; | |
| 1317 | 			 } | |
| 1318 | 			} | |
| 1319 | 		 } | |
| 1320 | ||
| 1321 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == EOF) | |
| 1322 | 		 break; | |
| 1323 | ||
| 1324 | 		 if (width > 0) | |
| 1325 | 		 --width; | |
| 1326 | 		} | |
| 1327 | ||
| 1328 | 	 if (!wbuf_cur_sz || ((flags & IS_HEX_FLOAT) != 0 && wbuf_cur_sz == 2)) | |
| 1329 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1330 | 	 } | |
| 1331 | ||
| 1332 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1333 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1334 | ||
| 1335 | 	 if ((flags & IS_LL) != 0) | |
| 1336 | 	 { | |
| 1337 | 	 long double ld; | |
| 1338 | 	 ld = __mingw_strtold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1339 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1340 | 	 *(npos != 0 ? (long double *) get_va_nth (argp, npos) : va_arg (arg, long double *)) = is_neg ? -ld : ld; | |
| 1341 | 	 } | |
| 1342 | 	 else if ((flags & IS_L) != 0) | |
| 1343 | 	 { | |
| 1344 | 	 double d; | |
| 1345 | 	 d = (double) __mingw_strtold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1346 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1347 | 		*(npos != 0 ? (double *) get_va_nth (argp, npos) : va_arg (arg, double *)) = is_neg ? -d : d; | |
| 1348 | 	 } | |
| 1349 | 	 else | |
| 1350 | 	 { | |
| 1351 | 	 float d = __mingw_strtof (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1352 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1353 | 		*(npos != 0 ? (float *) get_va_nth (argp, npos) : va_arg (arg, float *)) = is_neg ? -d : d; | |
| 1354 | 	 } | |
| 1355 | ||
| 1356 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1357 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1358 | ||
| 1359 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1360 | 	 ++rval; | |
| 1361 | 	 break; | |
| 1362 | ||
| 1363 | 	case '[': | |
| 1364 | 	 if ((flags & IS_L) != 0) | |
| 1365 | 	 { | |
| 1366 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1367 | 		{ | |
| 1368 | 		 if ((flags & IS_ALLOC_USED) != 0) | |
| 1369 | 		 { | |
| 1370 | 		 if (npos != 0) | |
| 1371 | 			pstr = (char **) get_va_nth (argp, npos); | |
| 1372 | 		 else | |
| 1373 | 			pstr = va_arg (arg, char **); | |
| 1374 | ||
| 1375 | 		 if (!pstr) | |
| 1376 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1377 | ||
| 1378 | 		 str_sz = 100; | |
| 1379 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 1380 | ||
| 1381 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 1382 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1383 | 		 gcollect = resize_gcollect (gcollect); | |
| 1384 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1385 | 		 } | |
| 1386 | 		 else | |
| 1387 | 		 { | |
| 1388 | 		 if (npos != 0) | |
| 1389 | 			wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 1390 | 		 else | |
| 1391 | 			wstr = va_arg (arg, wchar_t *); | |
| 1392 | 		 if (!wstr) | |
| 1393 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1394 | 		 } | |
| 1395 | 		} | |
| 1396 | 	 } | |
| 1397 | 	 else if ((flags & IS_SUPPRESSED) == 0) | |
| 1398 | 	 { | |
| 1399 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 1400 | 		{ | |
| 1401 | 		 if (npos != 0) | |
| 1402 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1403 | 		 else | |
| 1404 | 		 pstr = va_arg (arg, char **); | |
| 1405 | ||
| 1406 | 		 if (!pstr) | |
| 1407 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1408 | ||
| 1409 | 		 str_sz = 100; | |
| 1410 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 1411 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1412 | ||
| 1413 | 		 gcollect = resize_gcollect (gcollect); | |
| 1414 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1415 | 		} | |
| 1416 | 	 else | |
| 1417 | 		{ | |
| 1418 | 		 if (npos != 0) | |
| 1419 | 		 str = (char *) get_va_nth (argp, npos); | |
| 1420 | 		 else | |
| 1421 | 		 str = va_arg (arg, char *); | |
| 1422 | 		 if (!str) | |
| 1423 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1424 | 		} | |
| 1425 | 	 } | |
| 1426 | ||
| 1427 | 	 not_in = (*f == '^' ? 1 : 0); | |
| 1428 | 	 if (*f == '^') | |
| 1429 | 	 f++; | |
| 1430 | ||
| 1431 | 	 if (width < 0) | |
| 1432 | 	 width = INT_MAX; | |
| 1433 | ||
| 1434 | 	 if (wbuf_max_sz < 256) | |
| 1435 | 	 { | |
| 1436 | 	 wbuf_max_sz = 256; | |
| 1437 | 	 if (wbuf) | |
| 1438 | 	 free (wbuf); | |
| 1439 | 	 wbuf = (char *) malloc (wbuf_max_sz); | |
| 1440 | 	 } | |
| 1441 | 	 memset (wbuf, 0, 256); | |
| 1442 | ||
| 1443 | 	 fc = *f; | |
| 1444 | 	 if (fc == ']' || fc == '-') | |
| 1445 | 	 { | |
| 1446 | 	 wbuf[fc] = 1; | |
| 1447 | 	 ++f; | |
| 1448 | 	 } | |
| 1449 | ||
| 1450 | 	 while ((fc = *f++) != 0 && fc != ']') | |
| 1451 | 	 { | |
| 1452 | 	 if (fc == '-' && *f != 0 && *f != ']' && (unsigned char) f[-2] <= (unsigned char) *f) | |
| 1453 | 		{ | |
| 1454 | 		 for (fc = (unsigned char) f[-2]; fc < (unsigned char) *f; ++fc) | |
| 1455 | 		 wbuf[fc] = 1; | |
| 1456 | 		} | |
| 1457 | 	 else | |
| 1458 | 		wbuf[fc] = 1; | |
| 1459 | 	 } | |
| 1460 | ||
| 1461 | 	 if (!fc) | |
| 1462 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1463 | ||
| 1464 | 	 if ((flags & IS_L) != 0) | |
| 1465 | 	 { | |
| 1466 | 	 read_in_sv = read_in; | |
| 1467 | 	 cnt = 0; | |
| 1468 | ||
| 1469 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1470 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1471 | ||
| 1472 | 	 memset (&cstate, 0, sizeof (cstate)); | |
| 1473 | ||
| 1474 | 	 do | |
| 1475 | 		{ | |
| 1476 | 		 if (wbuf[c] == not_in) | |
| 1477 | 		 { | |
| 1478 | 		 back_ch (c, s, &read_in, 1); | |
| 1479 | 		 break; | |
| 1480 | 		 } | |
| 1481 | ||
| 1482 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1483 | 		 { | |
| 1484 | 		 buf[0] = c; | |
| 1485 | 		 n = mbrtowc (wstr, buf, 1, &cstate); | |
| 1486 | ||
| 1487 | 		 if (n == (size_t) -2) | |
| 1488 | 			{ | |
| 1489 | 			 ++cnt; | |
| 1490 | 			 continue; | |
| 1491 | 			} | |
| 1492 | 		 cnt = 0; | |
| 1493 | ||
| 1494 | 		 ++wstr; | |
| 1495 | 		 if ((flags & IS_ALLOC_USED) != 0 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 1496 | 			{ | |
| 1497 | 			 new_sz = str_sz * 2; | |
| 1498 | 			 while ((wstr = (wchar_t *) realloc (*pstr, new_sz * sizeof (wchar_t))) == NULL | |
| 1499 | 			 	 && new_sz > (size_t) (str_sz + 1)) | |
| 1500 | 			 new_sz = str_sz + 1; | |
| 1501 | 			 if (!wstr) | |
| 1502 | 			 { | |
| 1503 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1504 | 				{ | |
| 1505 | 				 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 1506 | 				 pstr = NULL; | |
| 1507 | 				 ++rval; | |
| 1508 | 				} | |
| 1509 | 			 else | |
| 1510 | 				rval = EOF; | |
| 1511 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1512 | 			 } | |
| 1513 | 			 *pstr = (char *) wstr; | |
| 1514 | 			 wstr += str_sz; | |
| 1515 | 			 str_sz = new_sz; | |
| 1516 | 			} | |
| 1517 | 		 } | |
| 1518 | ||
| 1519 | 		 if (--width <= 0) | |
| 1520 | 		 break; | |
| 1521 | 		} | |
| 1522 | 	 while ((c = in_ch (s, &read_in)) != EOF); | |
| 1523 | ||
| 1524 | 	 if (cnt != 0) | |
| 1525 | 		{ | |
| 1526 | 		 errno = EILSEQ; | |
| 1527 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1528 | 		} | |
| 1529 | ||
| 1530 | 	 if (read_in_sv == read_in) | |
| 1531 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1532 | ||
| 1533 | ||
| 1534 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1535 | 		{ | |
| 1536 | 		 *wstr++ = 0; | |
| 1537 | 		 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 1538 | 		 pstr = NULL; | |
| 1539 | 		 ++rval; | |
| 1540 | 		} | |
| 1541 | 	 } | |
| 1542 | 	 else | |
| 1543 | 	 { | |
| 1544 | 	 read_in_sv = read_in; | |
| 1545 | ||
| 1546 | 	 if ((c = in_ch (s, &read_in)) == EOF) | |
| 1547 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1548 | ||
| 1549 | 	 do | |
| 1550 | 		{ | |
| 1551 | 		 if (wbuf[c] == not_in) | |
| 1552 | 		 { | |
| 1553 | 		 back_ch (c, s, &read_in, 1); | |
| 1554 | 		 break; | |
| 1555 | 		 } | |
| 1556 | ||
| 1557 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1558 | 		 { | |
| 1559 | 		 *str++ = c; | |
| 1560 | 		 if ((flags & IS_ALLOC_USED) != 0 && str == (*pstr + str_sz)) | |
| 1561 | 			{ | |
| 1562 | 			 new_sz = str_sz * 2; | |
| 1563 | ||
| 1564 | 			 while ((str = (char *) realloc (*pstr, new_sz)) == NULL | |
| 1565 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 1566 | 			 new_sz = str_sz + 1; | |
| 1567 | 			 if (!str) | |
| 1568 | 			 { | |
| 1569 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1570 | 				{ | |
| 1571 | 				 (*pstr)[str_sz - 1] = 0; | |
| 1572 | 				 pstr = NULL; | |
| 1573 | 				 ++rval; | |
| 1574 | 				} | |
| 1575 | 			 else | |
| 1576 | 			 rval = EOF; | |
| 1577 | 			 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1578 | 			 } | |
| 1579 | 			 *pstr = str; | |
| 1580 | 			 str += str_sz; | |
| 1581 | 			 str_sz = new_sz; | |
| 1582 | 			} | |
| 1583 | 		 } | |
| 1584 | 		} | |
| 1585 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != EOF); | |
| 1586 | ||
| 1587 | 	 if (read_in_sv == read_in) | |
| 1588 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1589 | ||
| 1590 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1591 | 		{ | |
| 1592 | 		 *str++ = 0; | |
| 1593 | 		 optimize_alloc (pstr, str, str_sz); | |
| 1594 | 		 pstr = NULL; | |
| 1595 | 		 ++rval; | |
| 1596 | 		} | |
| 1597 | 	 } | |
| 1598 | 	 break; | |
| 1599 | ||
| 1600 | 	default: | |
| 1601 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1602 | 	} | |
| 1603 | } | |
| 1604 | ||
| 1605 | if (ignore_ws) | |
| 1606 | { | |
| 1607 | while (isspace ((c = in_ch (s, &read_in)))); | |
| 1608 | back_ch (c, s, &read_in, 0); | |
| 1609 | } | |
| 1610 | ||
| 1611 | return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1612 | } | |
| 5 | #include "mingw_sformat.h" | |
| 1613 | 6 | |
| 1614 | 7 | int |
| 1615 | 8 | __mingw_vfscanf (FILE *s, const char *format, va_list argp) |
| ... | ... | @@ -1619,14 +12,3 @@ __mingw_vfscanf (FILE *s, const char *format, va_list argp) |
| 1619 | 12 | ifp.fp = s; |
| 1620 | 13 | return __mingw_sformat (&ifp, format, argp); |
| 1621 | 14 | } |
| 1622 | ||
| 1623 | int | |
| 1624 | __mingw_vsscanf (const char *s, const char *format, va_list argp) | |
| 1625 | { | |
| 1626 | _IFP ifp; | |
| 1627 | memset (&ifp, 0, sizeof (_IFP)); | |
| 1628 | ifp.str = s; | |
| 1629 | ifp.is_string = 1; | |
| 1630 | return __mingw_sformat (&ifp, format, argp); | |
| 1631 | } | |
| 1632 |
lib/libc/mingw/stdio/mingw_vfwprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vfprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_vfwscanf.c created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | #include <stdarg.h> | |
| 2 | #include <stdio.h> | |
| 3 | #include <string.h> | |
| 4 | ||
| 5 | #include "mingw_swformat.h" | |
| 6 | ||
| 7 | int | |
| 8 | __mingw_vfwscanf (FILE *s, const wchar_t *format, va_list argp) | |
| 9 | { | |
| 10 | _IFPW ifp; | |
| 11 | memset (&ifp, 0, sizeof (_IFPW)); | |
| 12 | ifp.fp = s; | |
| 13 | return __mingw_swformat (&ifp, format, argp); | |
| 14 | } |
lib/libc/mingw/stdio/mingw_vprintfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_vsnprintf.c+18| ... | ... | @@ -34,11 +34,20 @@ int __cdecl __vsnprintf(APICHAR *buf, size_t length, const APICHAR *fmt, va_list |
| 34 | 34 | register int retval; |
| 35 | 35 | |
| 36 | 36 | if( length == (size_t)(0) ) |
| 37 | { | |
| 38 | #if defined(__BUILD_WIDEAPI) && defined(__BUILD_WIDEAPI_ISO) | |
| 39 | /* No buffer; for wide api ISO C95+ vswprintf() function | |
| 40 | * simply returns negative value as required by ISO C95+. | |
| 41 | */ | |
| 42 | return -1; | |
| 43 | #else | |
| 37 | 44 | /* |
| 38 | 45 | * No buffer; simply compute and return the size required, |
| 39 | 46 | * without actually emitting any data. |
| 40 | 47 | */ |
| 41 | 48 | return __pformat( 0, buf, 0, fmt, argv); |
| 49 | #endif | |
| 50 | } | |
| 42 | 51 | |
| 43 | 52 | /* If we get to here, then we have a buffer... |
| 44 | 53 | * Emit data up to the limit of buffer length less one, |
| ... | ... | @@ -47,6 +56,15 @@ int __cdecl __vsnprintf(APICHAR *buf, size_t length, const APICHAR *fmt, va_list |
| 47 | 56 | retval = __pformat( 0, buf, --length, fmt, argv ); |
| 48 | 57 | buf[retval < (int) length ? retval : (int)length] = '\0'; |
| 49 | 58 | |
| 59 | #if defined(__BUILD_WIDEAPI) && defined(__BUILD_WIDEAPI_ISO) | |
| 60 | /* For wide api ISO C95+ vswprintf() when requested length | |
| 61 | * is equal or larger than buffer length, returns negative | |
| 62 | * value as required by ISO C95+. | |
| 63 | */ | |
| 64 | if( retval >= (int) length ) | |
| 65 | retval = -1; | |
| 66 | #endif | |
| 67 | ||
| 50 | 68 | return retval; |
| 51 | 69 | } |
| 52 | 70 |
lib/libc/mingw/stdio/mingw_vsnprintfw.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vsnprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_vsnwprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vsnprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_vsprintfw.c deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | #define _CRT_NON_CONFORMING_SWPRINTFS 1 | |
| 8 | ||
| 9 | #include "mingw_vsprintf.c" | |
| 10 |
lib/libc/mingw/stdio/mingw_vsscanf.c created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | #include <stdarg.h> | |
| 2 | #include <stdio.h> | |
| 3 | #include <string.h> | |
| 4 | ||
| 5 | #include "mingw_sformat.h" | |
| 6 | ||
| 7 | int | |
| 8 | __mingw_vsscanf (const char *s, const char *format, va_list argp) | |
| 9 | { | |
| 10 | _IFP ifp; | |
| 11 | memset (&ifp, 0, sizeof (_IFP)); | |
| 12 | ifp.str = s; | |
| 13 | ifp.is_string = 1; | |
| 14 | return __mingw_sformat (&ifp, format, argp); | |
| 15 | } |
lib/libc/mingw/stdio/mingw_vswprintf.c created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | #define __BUILD_WIDEAPI_ISO 1 | |
| 8 | ||
| 9 | #include "mingw_vsnprintf.c" | |
| 10 |
lib/libc/mingw/stdio/mingw_vswscanf.c created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | #include <stdarg.h> | |
| 2 | #include <stdio.h> | |
| 3 | #include <string.h> | |
| 4 | ||
| 5 | #include "mingw_swformat.h" | |
| 6 | ||
| 7 | int | |
| 8 | __mingw_vswscanf (const wchar_t *s, const wchar_t *format, va_list argp) | |
| 9 | { | |
| 10 | _IFPW ifp; | |
| 11 | memset (&ifp, 0, sizeof (_IFPW)); | |
| 12 | ifp.str = s; | |
| 13 | ifp.is_string = 1; | |
| 14 | return __mingw_swformat (&ifp, format, argp); | |
| 15 | } |
lib/libc/mingw/stdio/mingw_vwprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_vprintf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_wpformat.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_pformat.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_wprintf.c created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #define __BUILD_WIDEAPI 1 | |
| 7 | ||
| 8 | #include "mingw_printf.c" | |
| 9 |
lib/libc/mingw/stdio/mingw_wvfscanf.c deleted-1631| ... | ... | @@ -1,1631 +0,0 @@ |
| 1 | /* | |
| 2 | This Software is provided under the Zope Public License (ZPL) Version 2.1. | |
| 3 | ||
| 4 | Copyright (c) 2011 by the mingw-w64 project | |
| 5 | ||
| 6 | See the AUTHORS file for the list of contributors to the mingw-w64 project. | |
| 7 | ||
| 8 | This license has been certified as open source. It has also been designated | |
| 9 | as GPL compatible by the Free Software Foundation (FSF). | |
| 10 | ||
| 11 | Redistribution and use in source and binary forms, with or without | |
| 12 | modification, are permitted provided that the following conditions are met: | |
| 13 | ||
| 14 | 1. Redistributions in source code must retain the accompanying copyright | |
| 15 | notice, this list of conditions, and the following disclaimer. | |
| 16 | 2. Redistributions in binary form must reproduce the accompanying | |
| 17 | copyright notice, this list of conditions, and the following disclaimer | |
| 18 | in the documentation and/or other materials provided with the | |
| 19 | distribution. | |
| 20 | 3. Names of the copyright holders must not be used to endorse or promote | |
| 21 | products derived from this software without prior written permission | |
| 22 | from the copyright holders. | |
| 23 | 4. The right to distribute this software or to use it for any purpose does | |
| 24 | not give you the right to use Servicemarks (sm) or Trademarks (tm) of | |
| 25 | the copyright holders. Use of them is covered by separate agreement | |
| 26 | with the copyright holders. | |
| 27 | 5. If any files are modified, you must cause the modified files to carry | |
| 28 | prominent notices stating that you changed the files and the date of | |
| 29 | any change. | |
| 30 | ||
| 31 | Disclaimer | |
| 32 | ||
| 33 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED | |
| 34 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
| 35 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 36 | EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
| 37 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 38 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 39 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
| 42 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 43 | */ | |
| 44 | ||
| 45 | #define __LARGE_MBSTATE_T | |
| 46 | ||
| 47 | #include <limits.h> | |
| 48 | #include <stddef.h> | |
| 49 | #include <stdarg.h> | |
| 50 | #include <stdio.h> | |
| 51 | #include <stdint.h> | |
| 52 | #include <stdlib.h> | |
| 53 | #include <string.h> | |
| 54 | #include <wchar.h> | |
| 55 | #include <ctype.h> | |
| 56 | #include <wctype.h> | |
| 57 | #include <locale.h> | |
| 58 | #include <errno.h> | |
| 59 | ||
| 60 | #ifndef CP_UTF8 | |
| 61 | #define CP_UTF8 65001 | |
| 62 | #endif | |
| 63 | ||
| 64 | #ifndef MB_ERR_INVALID_CHARS | |
| 65 | #define MB_ERR_INVALID_CHARS 0x00000008 | |
| 66 | #endif | |
| 67 | ||
| 68 | /* Helper flags for conversion. */ | |
| 69 | #define IS_C		0x0001 | |
| 70 | #define IS_S		0x0002 | |
| 71 | #define IS_L		0x0004 | |
| 72 | #define IS_LL		0x0008 | |
| 73 | #define IS_SIGNED_NUM	0x0010 | |
| 74 | #define IS_POINTER	0x0020 | |
| 75 | #define IS_HEX_FLOAT	0x0040 | |
| 76 | #define IS_SUPPRESSED	0x0080 | |
| 77 | #define USE_GROUP	0x0100 | |
| 78 | #define USE_GNU_ALLOC	0x0200 | |
| 79 | #define USE_POSIX_ALLOC	0x0400 | |
| 80 | ||
| 81 | #define IS_ALLOC_USED	(USE_GNU_ALLOC | USE_POSIX_ALLOC) | |
| 82 | ||
| 83 | /* internal stream structure with back-buffer. */ | |
| 84 | typedef struct _IFP | |
| 85 | { | |
| 86 | __extension__ union { | |
| 87 | void *fp; | |
| 88 | const wchar_t *str; | |
| 89 | }; | |
| 90 | int bch[1024]; | |
| 91 | unsigned int is_string : 1; | |
| 92 | int back_top; | |
| 93 | unsigned int seen_eof : 1; | |
| 94 | } _IFP; | |
| 95 | ||
| 96 | static void * | |
| 97 | get_va_nth (va_list argp, unsigned int n) | |
| 98 | { | |
| 99 | va_list ap; | |
| 100 | if (!n) | |
| 101 | abort (); | |
| 102 | va_copy (ap, argp); | |
| 103 | while (--n > 0) | |
| 104 | (void) va_arg(ap, void *); | |
| 105 | return va_arg (ap, void *); | |
| 106 | } | |
| 107 | ||
| 108 | static void | |
| 109 | optimize_alloc (char **p, char *end, size_t alloc_sz) | |
| 110 | { | |
| 111 | size_t need_sz; | |
| 112 | char *h; | |
| 113 | ||
| 114 | if (!p || !*p) | |
| 115 | return; | |
| 116 | ||
| 117 | need_sz = end - *p; | |
| 118 | if (need_sz == alloc_sz) | |
| 119 | return; | |
| 120 | ||
| 121 | if ((h = (char *) realloc (*p, need_sz)) != NULL) | |
| 122 | *p = h; | |
| 123 | } | |
| 124 | ||
| 125 | static void | |
| 126 | back_ch (int c, _IFP *s, size_t *rin, int not_eof) | |
| 127 | { | |
| 128 | if (!not_eof && c == WEOF) | |
| 129 | return; | |
| 130 | if (s->is_string == 0) | |
| 131 | { | |
| 132 | FILE *fp = s->fp; | |
| 133 | ungetwc (c, fp); | |
| 134 | rin[0] -= 1; | |
| 135 | return; | |
| 136 | } | |
| 137 | rin[0] -= 1; | |
| 138 | s->bch[s->back_top] = c; | |
| 139 | s->back_top += 1; | |
| 140 | } | |
| 141 | ||
| 142 | static int | |
| 143 | in_ch (_IFP *s, size_t *rin) | |
| 144 | { | |
| 145 | int r; | |
| 146 | if (s->back_top) | |
| 147 | { | |
| 148 | s->back_top -= 1; | |
| 149 | r = s->bch[s->back_top]; | |
| 150 | rin[0] += 1; | |
| 151 | } | |
| 152 | else if (s->seen_eof) | |
| 153 | { | |
| 154 | return WEOF; | |
| 155 | } | |
| 156 | else if (s->is_string) | |
| 157 | { | |
| 158 | const wchar_t *ps = s->str; | |
| 159 | r = ((int) *ps) & 0xffff; | |
| 160 | ps++; | |
| 161 | if (r != 0) | |
| 162 | { | |
| 163 | rin[0] += 1; | |
| 164 | s->str = ps; | |
| 165 | return r; | |
| 166 | } | |
| 167 | s->seen_eof = 1; | |
| 168 | return WEOF; | |
| 169 | } | |
| 170 | else | |
| 171 | { | |
| 172 | FILE *fp = (FILE *) s->fp; | |
| 173 | r = getwc (fp); | |
| 174 | if (r != WEOF) | |
| 175 | rin[0] += 1; | |
| 176 | else s->seen_eof = 1; | |
| 177 | } | |
| 178 | return r; | |
| 179 | } | |
| 180 | ||
| 181 | static int | |
| 182 | match_string (_IFP *s, size_t *rin, wint_t *c, const wchar_t *str) | |
| 183 | { | |
| 184 | int ch = *c; | |
| 185 | ||
| 186 | if (*str == 0) | |
| 187 | return 1; | |
| 188 | ||
| 189 | if (*str != (wchar_t) towlower (ch)) | |
| 190 | return 0; | |
| 191 | ++str; | |
| 192 | while (*str != 0) | |
| 193 | { | |
| 194 | if ((ch = in_ch (s, rin)) == WEOF) | |
| 195 | { | |
| 196 | c[0] = ch; | |
| 197 | return 0; | |
| 198 | } | |
| 199 | ||
| 200 | if (*str != (wchar_t) towlower (ch)) | |
| 201 | { | |
| 202 | c[0] = ch; | |
| 203 | return 0; | |
| 204 | } | |
| 205 | ++str; | |
| 206 | } | |
| 207 | c[0] = ch; | |
| 208 | return 1; | |
| 209 | } | |
| 210 | ||
| 211 | struct gcollect | |
| 212 | { | |
| 213 | size_t count; | |
| 214 | struct gcollect *next; | |
| 215 | char **ptrs[32]; | |
| 216 | }; | |
| 217 | ||
| 218 | static void | |
| 219 | release_ptrs (struct gcollect **pt, wchar_t **wbuf) | |
| 220 | { | |
| 221 | struct gcollect *pf; | |
| 222 | size_t cnt; | |
| 223 | ||
| 224 | if (wbuf) | |
| 225 | { | |
| 226 | free (*wbuf); | |
| 227 | *wbuf = NULL; | |
| 228 | } | |
| 229 | if (!pt || (pf = *pt) == NULL) | |
| 230 | return; | |
| 231 | while (pf != NULL) | |
| 232 | { | |
| 233 | struct gcollect *pf_sv = pf; | |
| 234 | for (cnt = 0; cnt < pf->count; ++cnt) | |
| 235 | 	{ | |
| 236 | 	 free (*pf->ptrs[cnt]); | |
| 237 | 	 *pf->ptrs[cnt] = NULL; | |
| 238 | 	} | |
| 239 | pf = pf->next; | |
| 240 | free (pf_sv); | |
| 241 | } | |
| 242 | *pt = NULL; | |
| 243 | } | |
| 244 | ||
| 245 | static int | |
| 246 | cleanup_return (int rval, struct gcollect **pfree, char **strp, wchar_t **wbuf) | |
| 247 | { | |
| 248 | if (rval == EOF) | |
| 249 | release_ptrs (pfree, wbuf); | |
| 250 | else | |
| 251 | { | |
| 252 | if (pfree) | |
| 253 | { | |
| 254 | struct gcollect *pf = *pfree, *pf_sv; | |
| 255 | while (pf != NULL) | |
| 256 | { | |
| 257 | pf_sv = pf; | |
| 258 | pf = pf->next; | |
| 259 | free (pf_sv); | |
| 260 | } | |
| 261 | *pfree = NULL; | |
| 262 | } | |
| 263 | if (strp != NULL) | |
| 264 | 	{ | |
| 265 | 	 free (*strp); | |
| 266 | 	 *strp = NULL; | |
| 267 | 	} | |
| 268 | if (wbuf) | |
| 269 | 	{ | |
| 270 | 	 free (*wbuf); | |
| 271 | 	 *wbuf = NULL; | |
| 272 | 	} | |
| 273 | } | |
| 274 | return rval; | |
| 275 | } | |
| 276 | ||
| 277 | static struct gcollect * | |
| 278 | resize_gcollect (struct gcollect *pf) | |
| 279 | { | |
| 280 | struct gcollect *np; | |
| 281 | if (pf && pf->count < 32) | |
| 282 | return pf; | |
| 283 | np = malloc (sizeof (struct gcollect)); | |
| 284 | np->count = 0; | |
| 285 | np->next = pf; | |
| 286 | return np; | |
| 287 | } | |
| 288 | ||
| 289 | static wchar_t * | |
| 290 | resize_wbuf (size_t wpsz, size_t *wbuf_max_sz, wchar_t *old) | |
| 291 | { | |
| 292 | wchar_t *wbuf; | |
| 293 | size_t nsz; | |
| 294 | if (*wbuf_max_sz != wpsz) | |
| 295 | return old; | |
| 296 | nsz = (256 > (2 * wbuf_max_sz[0]) ? 256 : (2 * wbuf_max_sz[0])); | |
| 297 | if (!old) | |
| 298 | wbuf = (wchar_t *) malloc (nsz * sizeof (wchar_t)); | |
| 299 | else | |
| 300 | wbuf = (wchar_t *) realloc (old, nsz * sizeof (wchar_t)); | |
| 301 | if (!wbuf) | |
| 302 | { | |
| 303 | if (old) | |
| 304 | free (old); | |
| 305 | } | |
| 306 | else | |
| 307 | *wbuf_max_sz = nsz; | |
| 308 | return wbuf; | |
| 309 | } | |
| 310 | ||
| 311 | static int | |
| 312 | __mingw_swformat (_IFP *s, const wchar_t *format, va_list argp) | |
| 313 | { | |
| 314 | const wchar_t *f = format; | |
| 315 | struct gcollect *gcollect = NULL; | |
| 316 | size_t read_in = 0, wbuf_max_sz = 0; | |
| 317 | ssize_t str_sz = 0; | |
| 318 | char *str = NULL, **pstr = NULL;; | |
| 319 | wchar_t *wstr = NULL, *wbuf = NULL; | |
| 320 | wint_t c = 0, rval = 0; | |
| 321 | int ignore_ws = 0; | |
| 322 | va_list arg; | |
| 323 | size_t wbuf_cur_sz, str_len, read_in_sv, new_sz, n; | |
| 324 | unsigned int fc, npos; | |
| 325 | int width, flags, base = 0, errno_sv, clen; | |
| 326 | char seen_dot, seen_exp, is_neg, *nstr, buf[MB_LEN_MAX]; | |
| 327 | wchar_t wc, not_in, *tmp_wbuf_ptr, *temp_wbuf_end, *wbuf_iter; | |
| 328 | wint_t lc_decimal_point, lc_thousands_sep; | |
| 329 | mbstate_t state; | |
| 330 | union { | |
| 331 | unsigned long long ull; | |
| 332 | unsigned long ul; | |
| 333 | long long ll; | |
| 334 | long l; | |
| 335 | } cv_val; | |
| 336 | ||
| 337 | arg = argp; | |
| 338 | ||
| 339 | if (!s || s->fp == NULL || !format) | |
| 340 | { | |
| 341 | errno = EINVAL; | |
| 342 | return EOF; | |
| 343 | } | |
| 344 | ||
| 345 | memset (&state, 0, sizeof(state)); | |
| 346 | clen = mbrtowc( &wc, localeconv()->decimal_point, 16, &state); | |
| 347 | lc_decimal_point = (clen > 0 ? wc : '.'); | |
| 348 | memset( &state, 0, sizeof( state ) ); | |
| 349 | clen = mbrtowc( &wc, localeconv()->thousands_sep, 16, &state); | |
| 350 | lc_thousands_sep = (clen > 0 ? wc : 0); | |
| 351 | ||
| 352 | while (*f != 0) | |
| 353 | { | |
| 354 | fc = *f++; | |
| 355 | if (fc != '%') | |
| 356 | { | |
| 357 | if (iswspace (fc)) | |
| 358 | 	 ignore_ws = 1; | |
| 359 | 	 else | |
| 360 | 	 { | |
| 361 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 362 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 363 | ||
| 364 | 	 if (ignore_ws) | |
| 365 | 		{ | |
| 366 | 		 ignore_ws = 0; | |
| 367 | 		 if (iswspace (c)) | |
| 368 | 		 { | |
| 369 | 		 do | |
| 370 | 			{ | |
| 371 | 			 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 372 | 			 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 373 | 			} | |
| 374 | 		 while (iswspace (c)); | |
| 375 | 		 } | |
| 376 | 		} | |
| 377 | ||
| 378 | 	 if (c != fc) | |
| 379 | 		{ | |
| 380 | 		 back_ch (c, s, &read_in, 0); | |
| 381 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 382 | 		} | |
| 383 | 	 } | |
| 384 | ||
| 385 | 	 continue; | |
| 386 | 	} | |
| 387 | ||
| 388 | width = flags = 0; | |
| 389 | npos = 0; | |
| 390 | wbuf_cur_sz = 0; | |
| 391 | ||
| 392 | if (iswdigit ((unsigned int) *f)) | |
| 393 | 	{ | |
| 394 | 	 const wchar_t *svf = f; | |
| 395 | 	 npos = (unsigned int) *f++ - '0'; | |
| 396 | 	 while (iswdigit ((unsigned int) *f)) | |
| 397 | 	 npos = npos * 10 + ((unsigned int) *f++ - '0'); | |
| 398 | 	 if (*f != '$') | |
| 399 | 	 { | |
| 400 | 	 npos = 0; | |
| 401 | 	 f = svf; | |
| 402 | 	 } | |
| 403 | 	 else | |
| 404 | 	 f++; | |
| 405 | 	} | |
| 406 | ||
| 407 | do | |
| 408 | 	{ | |
| 409 | 	 if (*f == '*') | |
| 410 | 	 flags |= IS_SUPPRESSED; | |
| 411 | 	 else if (*f == '\'') | |
| 412 | 	 { | |
| 413 | 	 if (lc_thousands_sep) | |
| 414 | 		flags |= USE_GROUP; | |
| 415 | 	 } | |
| 416 | 	 else if (*f == 'I') | |
| 417 | 	 { | |
| 418 | 	 /* we don't support locale's digits (i18N), but ignore it for now silently. */ | |
| 419 | 	 ; | |
| 420 | #ifdef _WIN32 | |
| 421 | if (f[1] == '6' && f[2] == '4') | |
| 422 | { | |
| 423 | 		 flags |= IS_LL | IS_L; | |
| 424 | 		 f += 2; | |
| 425 | 		} | |
| 426 | 	 else if (f[1] == '3' && f[2] == '2') | |
| 427 | 		{ | |
| 428 | 		 flags |= IS_L; | |
| 429 | 		 f += 2; | |
| 430 | 		} | |
| 431 | 	 else | |
| 432 | 	 { | |
| 433 | #ifdef _WIN64 | |
| 434 | 		 flags |= IS_LL | IS_L; | |
| 435 | #else | |
| 436 | 		 flags |= IS_L; | |
| 437 | #endif | |
| 438 | 		} | |
| 439 | #endif | |
| 440 | 	 } | |
| 441 | 	 else | |
| 442 | 	 break; | |
| 443 | 	 ++f; | |
| 444 | } | |
| 445 | while (1); | |
| 446 | ||
| 447 | while (iswdigit ((unsigned char) *f)) | |
| 448 | 	width = width * 10 + ((unsigned char) *f++ - '0'); | |
| 449 | ||
| 450 | if (!width) | |
| 451 | 	width = -1; | |
| 452 | ||
| 453 | switch (*f) | |
| 454 | 	{ | |
| 455 | 	case 'h': | |
| 456 | 	 ++f; | |
| 457 | 	 flags |= (*f == 'h' ? IS_C : IS_S); | |
| 458 | 	 if (*f == 'h') | |
| 459 | 	 ++f; | |
| 460 | 	 break; | |
| 461 | 	case 'l': | |
| 462 | 	 ++f; | |
| 463 | 	 flags |= (*f == 'l' ? IS_LL : 0) | IS_L; | |
| 464 | 	 if (*f == 'l') | |
| 465 | 	 ++f; | |
| 466 | 	 break; | |
| 467 | 	case 'q': case 'L': | |
| 468 | 	 ++f; | |
| 469 | 	 flags |= IS_LL | IS_L; | |
| 470 | 	 break; | |
| 471 | 	case 'a': | |
| 472 | 	 if (f[1] != 's' && f[1] != 'S' && f[1] != '[') | |
| 473 | 	 break; | |
| 474 | 	 ++f; | |
| 475 | 	 flags |= USE_GNU_ALLOC; | |
| 476 | 	 break; | |
| 477 | 	case 'm': | |
| 478 | 	 flags |= USE_POSIX_ALLOC; | |
| 479 | 	 ++f; | |
| 480 | 	 if (*f == 'l') | |
| 481 | 	 { | |
| 482 | 	 flags |= IS_L; | |
| 483 | 	 ++f; | |
| 484 | 	 } | |
| 485 | 	 break; | |
| 486 | 	case 'z': | |
| 487 | #ifdef _WIN64 | |
| 488 | 	 flags |= IS_LL | IS_L; | |
| 489 | #else | |
| 490 | 	 flags |= IS_L; | |
| 491 | #endif | |
| 492 | 	 ++f; | |
| 493 | 	 break; | |
| 494 | 	case 'j': | |
| 495 | 	 if (sizeof (uintmax_t) > sizeof (unsigned long)) | |
| 496 | 	 flags |= IS_LL; | |
| 497 | 	 else if (sizeof (uintmax_t) > sizeof (unsigned int)) | |
| 498 | 	 flags |= IS_L; | |
| 499 | 	 ++f; | |
| 500 | 	 break; | |
| 501 | 	case 't': | |
| 502 | #ifdef _WIN64 | |
| 503 | 	 flags |= IS_LL; | |
| 504 | #else | |
| 505 | 	 flags |= IS_L; | |
| 506 | #endif | |
| 507 | 	 ++f; | |
| 508 | 	 break; | |
| 509 | 	case 0: | |
| 510 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 511 | 	default: | |
| 512 | 	 break; | |
| 513 | 	} | |
| 514 | ||
| 515 | if (*f == 0) | |
| 516 | 	return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 517 | ||
| 518 | fc = *f++; | |
| 519 | if (ignore_ws || (fc != '[' && fc != 'c' && fc != 'C' && fc != 'n')) | |
| 520 | 	{ | |
| 521 | 	 errno_sv = errno; | |
| 522 | 	 errno = 0; | |
| 523 | 	 do | |
| 524 | 	 { | |
| 525 | 	 if ((c == WEOF || (c = in_ch (s, &read_in)) == WEOF) && errno == EINTR) | |
| 526 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 527 | 	 } | |
| 528 | 	 while (iswspace (c)); | |
| 529 | ||
| 530 | 	 ignore_ws = 0; | |
| 531 | 	 errno = errno_sv; | |
| 532 | 	 back_ch (c, s, &read_in, 0); | |
| 533 | 	} | |
| 534 | ||
| 535 | switch (fc) | |
| 536 | { | |
| 537 | case 'c': | |
| 538 | if ((flags & IS_L) != 0) | |
| 539 | fc = 'C'; | |
| 540 | break; | |
| 541 | case 's': | |
| 542 | if ((flags & IS_L) != 0) | |
| 543 | fc = 'S'; | |
| 544 | break; | |
| 545 | } | |
| 546 | ||
| 547 | switch (fc) | |
| 548 | 	{ | |
| 549 | 	case '%': | |
| 550 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 551 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 552 | 	 if (c != fc) | |
| 553 | 	 { | |
| 554 | 	 back_ch (c, s, &read_in, 1); | |
| 555 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 556 | 	 } | |
| 557 | 	 break; | |
| 558 | ||
| 559 | 	case 'n': | |
| 560 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 561 | 	 { | |
| 562 | 	 if ((flags & IS_LL) != 0) | |
| 563 | 		*(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = read_in; | |
| 564 | 	 else if ((flags & IS_L) != 0) | |
| 565 | 		*(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = read_in; | |
| 566 | 	 else if ((flags & IS_S) != 0) | |
| 567 | 		*(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = read_in; | |
| 568 | 	 else if ((flags & IS_C) != 0) | |
| 569 | 	 *(npos != 0 ? (char *) get_va_nth (argp, npos) : va_arg (arg, char *)) = read_in; | |
| 570 | 	 else | |
| 571 | 		*(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = read_in; | |
| 572 | 	 } | |
| 573 | 	 break; | |
| 574 | ||
| 575 | 	case 'c': | |
| 576 | 	 if (width == -1) | |
| 577 | 	 width = 1; | |
| 578 | ||
| 579 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 580 | 	 { | |
| 581 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 582 | 		{ | |
| 583 | 		 if (npos != 0) | |
| 584 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 585 | 		 else | |
| 586 | 		 pstr = va_arg (arg, char **); | |
| 587 | ||
| 588 | 		 if (!pstr) | |
| 589 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 590 | 		 str_sz = 100; | |
| 591 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 592 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 593 | 		 gcollect = resize_gcollect (gcollect); | |
| 594 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 595 | 		} | |
| 596 | 	 else | |
| 597 | 		{ | |
| 598 | 		 if (npos != 0) | |
| 599 | 		 str = (char *) get_va_nth (argp, npos); | |
| 600 | 		 else | |
| 601 | 		 str = va_arg (arg, char *); | |
| 602 | 		 if (!str) | |
| 603 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 604 | 		} | |
| 605 | 	 } | |
| 606 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 607 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 608 | ||
| 609 | 	 memset (&state, 0, sizeof (state)); | |
| 610 | ||
| 611 | 	 do | |
| 612 | 	 { | |
| 613 | 	 if ((flags & IS_SUPPRESSED) == 0 && (flags & USE_POSIX_ALLOC) != 0 | |
| 614 | 		 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 615 | 		{ | |
| 616 | 		 new_sz = str_sz * 2; | |
| 617 | 		 str_len = (str - *pstr); | |
| 618 | 		 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 619 | 			 && new_sz > (str_len + MB_CUR_MAX)) | |
| 620 | 		 new_sz = str_len + MB_CUR_MAX; | |
| 621 | 		 if (!nstr) | |
| 622 | 		 { | |
| 623 | 		 release_ptrs (&gcollect, &wbuf); | |
| 624 | 		 return EOF; | |
| 625 | 		 } | |
| 626 | 		 *pstr = nstr; | |
| 627 | 		 str = nstr + str_len; | |
| 628 | 		 str_sz = new_sz; | |
| 629 | 		} | |
| 630 | ||
| 631 | 	 n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, &state); | |
| 632 | 	 if (n == (size_t) -1LL) | |
| 633 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 634 | 	 str += n; | |
| 635 | 	 } | |
| 636 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 637 | ||
| 638 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 639 | 	 { | |
| 640 | 	 optimize_alloc (pstr, str, str_sz); | |
| 641 | 	 pstr = NULL; | |
| 642 | 	 ++rval; | |
| 643 | 	 } | |
| 644 | ||
| 645 | 	 break; | |
| 646 | ||
| 647 | 	case 'C': | |
| 648 | 	 if (width == -1) | |
| 649 | 	 width = 1; | |
| 650 | ||
| 651 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 652 | 	 { | |
| 653 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 654 | 		{ | |
| 655 | 		 if (npos != 0) | |
| 656 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 657 | 		 else | |
| 658 | 		 pstr = va_arg (arg, char **); | |
| 659 | ||
| 660 | 		 if (!pstr) | |
| 661 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 662 | 		 str_sz = (width > 1024 ? 1024 : width); | |
| 663 | 		 *pstr = (char *) malloc (str_sz * sizeof (wchar_t)); | |
| 664 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 665 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 666 | ||
| 667 | 		 if ((wstr = (wchar_t *) *pstr) != NULL) | |
| 668 | 		 { | |
| 669 | 		 gcollect = resize_gcollect (gcollect); | |
| 670 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 671 | 		 } | |
| 672 | 		} | |
| 673 | 	 else | |
| 674 | 		{ | |
| 675 | 		 if (npos != 0) | |
| 676 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 677 | 		 else | |
| 678 | 		 wstr = va_arg (arg, wchar_t *); | |
| 679 | 		 if (!wstr) | |
| 680 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 681 | 		} | |
| 682 | 	 } | |
| 683 | ||
| 684 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 685 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 686 | ||
| 687 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 688 | 	 { | |
| 689 | 	 do | |
| 690 | 		{ | |
| 691 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 692 | 		 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 693 | 		 { | |
| 694 | 		 new_sz = str_sz + (str_sz > width ? width - 1 : str_sz); | |
| 695 | 		 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 696 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 697 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 698 | 			new_sz = str_sz + 1; | |
| 699 | 		 if (!wstr) | |
| 700 | 			{ | |
| 701 | 			 release_ptrs (&gcollect, &wbuf); | |
| 702 | 			 return EOF; | |
| 703 | 			} | |
| 704 | 		 *pstr = (char *) wstr; | |
| 705 | 		 wstr += str_sz; | |
| 706 | 		 str_sz = new_sz; | |
| 707 | 		 } | |
| 708 | 		 *wstr++ = c; | |
| 709 | 		} | |
| 710 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 711 | 	 } | |
| 712 | 	 else | |
| 713 | 	 { | |
| 714 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 715 | 	 } | |
| 716 | ||
| 717 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 718 | 	 { | |
| 719 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 720 | 	 pstr = NULL; | |
| 721 | 	 ++rval; | |
| 722 | 	 } | |
| 723 | 	 break; | |
| 724 | ||
| 725 | 	case 's': | |
| 726 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 727 | 	 { | |
| 728 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 729 | 		{ | |
| 730 | 		 if (npos != 0) | |
| 731 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 732 | 		 else | |
| 733 | 		 pstr = va_arg (arg, char **); | |
| 734 | ||
| 735 | 		 if (!pstr) | |
| 736 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 737 | 		 str_sz = 100; | |
| 738 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 739 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 740 | 		 gcollect = resize_gcollect (gcollect); | |
| 741 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 742 | 		} | |
| 743 | 	 else | |
| 744 | 		{ | |
| 745 | 		 if (npos != 0) | |
| 746 | 		 str = (char *) get_va_nth (argp, npos); | |
| 747 | 		 else | |
| 748 | 		 str = va_arg (arg, char *); | |
| 749 | 		 if (!str) | |
| 750 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 751 | 		} | |
| 752 | 	 } | |
| 753 | ||
| 754 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 755 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 756 | ||
| 757 | 	 memset (&state, 0, sizeof (state)); | |
| 758 | ||
| 759 | 	 do | |
| 760 | 	 { | |
| 761 | 	 if (iswspace (c)) | |
| 762 | 		{ | |
| 763 | 		 back_ch (c, s, &read_in, 1); | |
| 764 | 		 break; | |
| 765 | 		} | |
| 766 | ||
| 767 | 	 { | |
| 768 | 		if ((flags & IS_SUPPRESSED) == 0 && (flags & IS_ALLOC_USED) != 0 | |
| 769 | 		 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 770 | 		 { | |
| 771 | 		 new_sz = str_sz * 2; | |
| 772 | 		 str_len = (str - *pstr); | |
| 773 | ||
| 774 | 		 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 775 | 			 && new_sz > (str_len + MB_CUR_MAX)) | |
| 776 | 		 new_sz = str_len + MB_CUR_MAX; | |
| 777 | 		 if (!nstr) | |
| 778 | 		 { | |
| 779 | 			if ((flags & USE_POSIX_ALLOC) == 0) | |
| 780 | 			 { | |
| 781 | 			 (*pstr)[str_len] = 0; | |
| 782 | 			 pstr = NULL; | |
| 783 | 			 ++rval; | |
| 784 | 			 } | |
| 785 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 786 | 		 } | |
| 787 | 		 *pstr = nstr; | |
| 788 | 		 str = nstr + str_len; | |
| 789 | 		 str_sz = new_sz; | |
| 790 | 		 } | |
| 791 | ||
| 792 | 		n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, | |
| 793 | 			 &state); | |
| 794 | 		if (n == (size_t) -1LL) | |
| 795 | 		{ | |
| 796 | 		 errno = EILSEQ; | |
| 797 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 798 | 		} | |
| 799 | ||
| 800 | 		str += n; | |
| 801 | 	 } | |
| 802 | 	 } | |
| 803 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != WEOF); | |
| 804 | ||
| 805 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 806 | 	 { | |
| 807 | 	 n = wcrtomb (buf, 0, &state); | |
| 808 | 	 if (n > 0 && (flags & IS_ALLOC_USED) != 0 | |
| 809 | 		 && (str + n) >= (*pstr + str_sz)) | |
| 810 | 		{ | |
| 811 | 		 str_len = (str - *pstr); | |
| 812 | ||
| 813 | 		 if ((nstr = (char *) realloc (*pstr, str_len + n + 1)) == NULL) | |
| 814 | 		 { | |
| 815 | 		 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 816 | 			{ | |
| 817 | 			 (*pstr)[str_len] = 0; | |
| 818 | 			 pstr = NULL; | |
| 819 | 			 ++rval; | |
| 820 | 			} | |
| 821 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 822 | 		 } | |
| 823 | 		 *pstr = nstr; | |
| 824 | 		 str = nstr + str_len; | |
| 825 | 		 str_sz = str_len + n + 1; | |
| 826 | 		} | |
| 827 | ||
| 828 | 	 if (n) | |
| 829 | 	 { | |
| 830 | 		memcpy (str, buf, n); | |
| 831 | 		str += n; | |
| 832 | 	 } | |
| 833 | 	 *str++ = 0; | |
| 834 | ||
| 835 | 	 optimize_alloc (pstr, str, str_sz); | |
| 836 | 	 pstr = NULL; | |
| 837 | 	 ++rval; | |
| 838 | 	 } | |
| 839 | 	 break; | |
| 840 | ||
| 841 | 	case 'S': | |
| 842 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 843 | 	 { | |
| 844 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 845 | 		{ | |
| 846 | 		 if (npos != 0) | |
| 847 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 848 | 		 else | |
| 849 | 		 pstr = va_arg (arg, char **); | |
| 850 | ||
| 851 | 		 if (!pstr) | |
| 852 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 853 | 		 str_sz = 100; | |
| 854 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 855 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 856 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 857 | 		 gcollect = resize_gcollect (gcollect); | |
| 858 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 859 | 		} | |
| 860 | 	 else | |
| 861 | 		{ | |
| 862 | 		 if (npos != 0) | |
| 863 | 		 wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 864 | 		 else | |
| 865 | 		 wstr = va_arg (arg, wchar_t *); | |
| 866 | 		 if (!wstr) | |
| 867 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 868 | 		} | |
| 869 | 	 } | |
| 870 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 871 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 872 | ||
| 873 | 	 do | |
| 874 | 	 { | |
| 875 | 	 if (iswspace (c)) | |
| 876 | 		{ | |
| 877 | 		 back_ch (c, s, &read_in, 1); | |
| 878 | 		 break; | |
| 879 | 		} | |
| 880 | ||
| 881 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 882 | 		{ | |
| 883 | 		 *wstr++ = c; | |
| 884 | 		 if ((flags & IS_ALLOC_USED) != 0 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 885 | 		 { | |
| 886 | 		 new_sz = str_sz * 2; | |
| 887 | ||
| 888 | 		 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 889 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 890 | 			 && new_sz > (size_t) (str_sz + 1)) | |
| 891 | 			new_sz = str_sz + 1; | |
| 892 | 		 if (!wstr) | |
| 893 | 			{ | |
| 894 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 895 | 			 { | |
| 896 | 			 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 897 | 			 pstr = NULL; | |
| 898 | 			 ++rval; | |
| 899 | 			 } | |
| 900 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 901 | 			} | |
| 902 | 		 *pstr = (char *) wstr; | |
| 903 | 		 wstr += str_sz; | |
| 904 | 		 str_sz = new_sz; | |
| 905 | 		 } | |
| 906 | 		} | |
| 907 | 	 } | |
| 908 | 	 while ((width <= 0 || --width > 0) && (c = in_ch (s, &read_in)) != WEOF); | |
| 909 | ||
| 910 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 911 | 	 { | |
| 912 | 	 *wstr++ = 0; | |
| 913 | ||
| 914 | 	 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 915 | 	 pstr = NULL; | |
| 916 | 	 ++rval; | |
| 917 | 	 } | |
| 918 | 	 break; | |
| 919 | ||
| 920 | 	case 'd': case 'i': | |
| 921 | 	case 'o': case 'p': | |
| 922 | 	case 'u': | |
| 923 | 	case 'x': case 'X': | |
| 924 | 	 switch (fc) | |
| 925 | 	 { | |
| 926 | 	 case 'd': | |
| 927 | 	 flags |= IS_SIGNED_NUM; | |
| 928 | 	 base = 10; | |
| 929 | 	 break; | |
| 930 | 	 case 'i': | |
| 931 | 	 flags |= IS_SIGNED_NUM; | |
| 932 | 	 base = 0; | |
| 933 | 	 break; | |
| 934 | 	 case 'o': | |
| 935 | 	 base = 8; | |
| 936 | 	 break; | |
| 937 | 	 case 'p': | |
| 938 | 	 base = 16; | |
| 939 | 	 flags &= ~(IS_S | IS_LL | IS_L); | |
| 940 | #ifdef _WIN64 | |
| 941 | 	 flags |= IS_LL; | |
| 942 | #endif | |
| 943 | 	 flags |= IS_L | IS_POINTER; | |
| 944 | 	 break; | |
| 945 | 	 case 'u': | |
| 946 | 	 base = 10; | |
| 947 | 	 break; | |
| 948 | 	 case 'x': case 'X': | |
| 949 | 	 base = 16; | |
| 950 | 	 break; | |
| 951 | 	 } | |
| 952 | ||
| 953 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 954 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 955 | ||
| 956 | 	 if (c == '+' || c == '-') | |
| 957 | 	 { | |
| 958 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 959 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 960 | ||
| 961 | 	 if (width > 0) | |
| 962 | 		--width; | |
| 963 | 	 c = in_ch (s, &read_in); | |
| 964 | 	 } | |
| 965 | ||
| 966 | 	 if (width != 0 && c == '0') | |
| 967 | 	 { | |
| 968 | 	 if (width > 0) | |
| 969 | 		--width; | |
| 970 | ||
| 971 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 972 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 973 | ||
| 974 | 	 c = in_ch (s, &read_in); | |
| 975 | ||
| 976 | 	 if (width != 0 && towlower (c) == 'x') | |
| 977 | 		{ | |
| 978 | 		 if (!base) | |
| 979 | 		 base = 16; | |
| 980 | 		 if (base == 16) | |
| 981 | 		 { | |
| 982 | 		 if (width > 0) | |
| 983 | 			--width; | |
| 984 | 		 c = in_ch (s, &read_in); | |
| 985 | 		 } | |
| 986 | 		} | |
| 987 | 	 else if (!base) | |
| 988 | 		base = 8; | |
| 989 | 	 } | |
| 990 | ||
| 991 | 	 if (!base) | |
| 992 | 	 base = 10; | |
| 993 | ||
| 994 | 	 while (c != WEOF && width != 0) | |
| 995 | 	 { | |
| 996 | 	 if (base == 16) | |
| 997 | 		{ | |
| 998 | 		 if (!iswxdigit (c)) | |
| 999 | 		 break; | |
| 1000 | 		} | |
| 1001 | 	 else if (!iswdigit (c) || (int) (c - '0') >= base) | |
| 1002 | 		{ | |
| 1003 | 		 if (base != 10 || (flags & USE_GROUP) == 0 || c != lc_thousands_sep) | |
| 1004 | 		 break; | |
| 1005 | 		} | |
| 1006 | 	 if (c != lc_thousands_sep) | |
| 1007 | 	 { | |
| 1008 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1009 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1010 | 		} | |
| 1011 | ||
| 1012 | 	 if (width > 0) | |
| 1013 | 		--width; | |
| 1014 | ||
| 1015 | 	 c = in_ch (s, &read_in); | |
| 1016 | 	 } | |
| 1017 | ||
| 1018 | 	 if (!wbuf_cur_sz || (wbuf_cur_sz == 1 && (wbuf[0] == '+' || wbuf[0] == '-'))) | |
| 1019 | 	 { | |
| 1020 | 	 if (!wbuf_cur_sz && (flags & IS_POINTER) != 0 | |
| 1021 | 		 && match_string (s, &read_in, &c, L"(nil)")) | |
| 1022 | 		{ | |
| 1023 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1024 | 		 wbuf[wbuf_cur_sz++] = '0'; | |
| 1025 | 		} | |
| 1026 | 	 else | |
| 1027 | 		{ | |
| 1028 | 		 back_ch (c, s, &read_in, 0); | |
| 1029 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1030 | 		} | |
| 1031 | 	 } | |
| 1032 | 	 else | |
| 1033 | 	 back_ch (c, s, &read_in, 0); | |
| 1034 | ||
| 1035 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1036 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1037 | ||
| 1038 | 	 if ((flags & IS_LL) != 0) | |
| 1039 | 	 { | |
| 1040 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1041 | 		cv_val.ll = wcstoll (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1042 | 	 else | |
| 1043 | 		cv_val.ull = wcstoull (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1044 | 	 } | |
| 1045 | 	 else | |
| 1046 | 	 { | |
| 1047 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1048 | 		cv_val.l = wcstol (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1049 | 	 else | |
| 1050 | 		cv_val.ul = wcstoul (wbuf, &tmp_wbuf_ptr, base/*, flags & USE_GROUP*/); | |
| 1051 | 	 } | |
| 1052 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1053 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1054 | ||
| 1055 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1056 | 	 { | |
| 1057 | 	 if ((flags & IS_SIGNED_NUM) != 0) | |
| 1058 | 		{ | |
| 1059 | 		 if ((flags & IS_LL) != 0) | |
| 1060 | 		 *(npos != 0 ? (long long *) get_va_nth (argp, npos) : va_arg (arg, long long *)) = cv_val.ll; | |
| 1061 | 		 else if ((flags & IS_L) != 0) | |
| 1062 | 		 *(npos != 0 ? (long *) get_va_nth (argp, npos) : va_arg (arg, long *)) = cv_val.l; | |
| 1063 | 		 else if ((flags & IS_S) != 0) | |
| 1064 | 		 *(npos != 0 ? (short *) get_va_nth (argp, npos) : va_arg (arg, short *)) = (short) cv_val.l; | |
| 1065 | 		 else if ((flags & IS_C) != 0) | |
| 1066 | 		 *(npos != 0 ? (signed char *) get_va_nth (argp, npos) : va_arg (arg, signed char *)) = (signed char) cv_val.ul; | |
| 1067 | 		 else | |
| 1068 | 		 *(npos != 0 ? (int *) get_va_nth (argp, npos) : va_arg (arg, int *)) = (int) cv_val.l; | |
| 1069 | 		} | |
| 1070 | 	 else | |
| 1071 | 		{ | |
| 1072 | 		 if ((flags & IS_LL) != 0) | |
| 1073 | 		 *(npos != 0 ? (unsigned long long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long long *)) = cv_val.ull; | |
| 1074 | 		 else if ((flags & IS_L) != 0) | |
| 1075 | 		 *(npos != 0 ? (unsigned long *) get_va_nth (argp, npos) : va_arg (arg, unsigned long *)) = cv_val.ul; | |
| 1076 | 		 else if ((flags & IS_S) != 0) | |
| 1077 | 		 *(npos != 0 ? (unsigned short *) get_va_nth (argp, npos) : va_arg (arg, unsigned short *)) | |
| 1078 | 		 = (unsigned short) cv_val.ul; | |
| 1079 | 		 else if ((flags & IS_C) != 0) | |
| 1080 | 		 *(npos != 0 ? (unsigned char *) get_va_nth (argp, npos) : va_arg (arg, unsigned char *)) = (unsigned char) cv_val.ul; | |
| 1081 | 		 else | |
| 1082 | 		 *(npos != 0 ? (unsigned int *) get_va_nth (argp, npos) : va_arg (arg, unsigned int *)) = (unsigned int) cv_val.ul; | |
| 1083 | 		} | |
| 1084 | 	 ++rval; | |
| 1085 | 	 } | |
| 1086 | 	 break; | |
| 1087 | ||
| 1088 | 	case 'e': case 'E': | |
| 1089 | 	case 'f': case 'F': | |
| 1090 | 	case 'g': case 'G': | |
| 1091 | 	case 'a': case 'A': | |
| 1092 | 	 if (width > 0) | |
| 1093 | 	 --width; | |
| 1094 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1095 | 	 return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1096 | ||
| 1097 | 	 seen_dot = seen_exp = 0; | |
| 1098 | 	 is_neg = (c == '-' ? 1 : 0); | |
| 1099 | ||
| 1100 | 	 if (c == '-' || c == '+') | |
| 1101 | 	 { | |
| 1102 | 	 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF) | |
| 1103 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1104 | 	 if (width > 0) | |
| 1105 | 		--width; | |
| 1106 | 	 } | |
| 1107 | ||
| 1108 | 	 if (towlower (c) == 'n') | |
| 1109 | 	 { | |
| 1110 | 	 const wchar_t *match_txt = L"nan"; | |
| 1111 | ||
| 1112 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1113 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1114 | 	 | |
| 1115 | 	 ++match_txt; | |
| 1116 | 	 do | |
| 1117 | 		{ | |
| 1118 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1119 | 		 || towlower (c) != match_txt[0]) | |
| 1120 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1121 | 		 if (width > 0) | |
| 1122 | 		 --width; | |
| 1123 | ||
| 1124 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1125 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1126 | 		 ++match_txt; | |
| 1127 | 		} | |
| 1128 | 	 while (*match_txt != 0); | |
| 1129 | 	 } | |
| 1130 | 	 else if (towlower (c) == 'i') | |
| 1131 | 	 { | |
| 1132 | 	 const wchar_t *match_txt = L"inf"; | |
| 1133 | ||
| 1134 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1135 | 	 wbuf[wbuf_cur_sz++] = c; | |
| 1136 | ||
| 1137 | 	 ++match_txt; | |
| 1138 | 	 do | |
| 1139 | 		{ | |
| 1140 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1141 | 		 || towlower (c) != match_txt[0]) | |
| 1142 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1143 | 		 if (width > 0) | |
| 1144 | 		 --width; | |
| 1145 | ||
| 1146 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1147 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1148 | 		 ++match_txt; | |
| 1149 | 		} | |
| 1150 | 	 while (*match_txt != 0); | |
| 1151 | ||
| 1152 | 	 if (width != 0 && (c = in_ch (s, &read_in)) != WEOF && towlower (c) == 'i') | |
| 1153 | 		{ | |
| 1154 | 		 match_txt = L"inity"; | |
| 1155 | 		 if (width > 0) | |
| 1156 | 		 --width; | |
| 1157 | ||
| 1158 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1159 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1160 | ||
| 1161 | 		 ++match_txt; | |
| 1162 | 		 do | |
| 1163 | 		 { | |
| 1164 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF | |
| 1165 | 			 || towlower (c) != match_txt[0]) | |
| 1166 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1167 | 		 if (width > 0) | |
| 1168 | 			--width; | |
| 1169 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1170 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1171 | 		 ++match_txt; | |
| 1172 | 		 } | |
| 1173 | 		 while (*match_txt != 0); | |
| 1174 | 		} | |
| 1175 | 	 else if (width != 0 && c != WEOF) | |
| 1176 | 	 back_ch (c, s, &read_in, 0); | |
| 1177 | 	 } | |
| 1178 | 	 else | |
| 1179 | 	 { | |
| 1180 | 	 not_in = 'e'; | |
| 1181 | 	 if (width != 0 && c == '0') | |
| 1182 | 		{ | |
| 1183 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1184 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1185 | ||
| 1186 | 		 c = in_ch (s, &read_in); | |
| 1187 | 		 if (width > 0) | |
| 1188 | 		 --width; | |
| 1189 | 		 if (width != 0 && towlower (c) == 'x') | |
| 1190 | 		 { | |
| 1191 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1192 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1193 | 		 flags |= IS_HEX_FLOAT; | |
| 1194 | 		 not_in = 'p'; | |
| 1195 | ||
| 1196 | 		 flags &= ~USE_GROUP; | |
| 1197 | 		 c = in_ch (s, &read_in); | |
| 1198 | 		 if (width > 0) | |
| 1199 | 			--width; | |
| 1200 | 		 } | |
| 1201 | 		} | |
| 1202 | ||
| 1203 | 	 while (1) | |
| 1204 | 		{ | |
| 1205 | 		 if (iswdigit (c)) | |
| 1206 | 		 { | |
| 1207 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1208 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1209 | 		 } | |
| 1210 | 		 else if (!seen_exp && (flags & IS_HEX_FLOAT) != 0 && iswxdigit (c)) | |
| 1211 | 		 { | |
| 1212 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1213 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1214 | 		 } | |
| 1215 | 		 else if (seen_exp && wbuf[wbuf_cur_sz - 1] == not_in | |
| 1216 | 			 && (c == '-' || c == '+')) | |
| 1217 | 		 { | |
| 1218 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1219 | 		 wbuf[wbuf_cur_sz++] = c; | |
| 1220 | 		 } | |
| 1221 | 		 else if (wbuf_cur_sz > 0 && !seen_exp | |
| 1222 | 			 && (wchar_t) towlower (c) == not_in) | |
| 1223 | 		 { | |
| 1224 | 		 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1225 | 		 wbuf[wbuf_cur_sz++] = not_in; | |
| 1226 | ||
| 1227 | 		 seen_exp = seen_dot = 1; | |
| 1228 | 		 } | |
| 1229 | 		 else | |
| 1230 | 		 { | |
| 1231 | 		 if (!seen_dot && c == lc_decimal_point) | |
| 1232 | 			{ | |
| 1233 | 			 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1234 | 			 wbuf[wbuf_cur_sz++] = c; | |
| 1235 | ||
| 1236 | 			 seen_dot = 1; | |
| 1237 | 			} | |
| 1238 | 		 else if ((flags & USE_GROUP) != 0 && !seen_dot && c == lc_thousands_sep) | |
| 1239 | 			{ | |
| 1240 | 			 /* As our conversion routines aren't supporting thousands | |
| 1241 | 			 separators, we are filtering them here. */ | |
| 1242 | 			} | |
| 1243 | 		 else | |
| 1244 | 			{ | |
| 1245 | 			 back_ch (c, s, &read_in, 0); | |
| 1246 | 			 break; | |
| 1247 | 			} | |
| 1248 | 		 } | |
| 1249 | ||
| 1250 | 		 if (width == 0 || (c = in_ch (s, &read_in)) == WEOF) | |
| 1251 | 		 break; | |
| 1252 | ||
| 1253 | 		 if (width > 0) | |
| 1254 | 		 --width; | |
| 1255 | 		} | |
| 1256 | ||
| 1257 | 	 if (wbuf_cur_sz == 0 || ((flags & IS_HEX_FLOAT) != 0 && wbuf_cur_sz == 2)) | |
| 1258 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1259 | 	 } | |
| 1260 | ||
| 1261 | 	 wbuf = resize_wbuf (wbuf_cur_sz, &wbuf_max_sz, wbuf); | |
| 1262 | 	 wbuf[wbuf_cur_sz++] = 0; | |
| 1263 | ||
| 1264 | 	 if ((flags & IS_LL) != 0) | |
| 1265 | 	 { | |
| 1266 | 	 long double d = __mingw_wcstold (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1267 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1268 | 		*(npos != 0 ? (long double *) get_va_nth (argp, npos) : va_arg (arg, long double *)) = is_neg ? -d : d; | |
| 1269 | 	 } | |
| 1270 | 	 else if ((flags & IS_L) != 0) | |
| 1271 | 	 { | |
| 1272 | 	 double d = __mingw_wcstod (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1273 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1274 | 		*(npos != 0 ? (double *) get_va_nth (argp, npos) : va_arg (arg, double *)) = is_neg ? -d : d; | |
| 1275 | 	 } | |
| 1276 | 	 else | |
| 1277 | 	 { | |
| 1278 | 	 float d = __mingw_wcstof (wbuf, &tmp_wbuf_ptr/*, flags & USE_GROUP*/); | |
| 1279 | 	 if ((flags & IS_SUPPRESSED) == 0 && tmp_wbuf_ptr != wbuf) | |
| 1280 | 		*(npos != 0 ? (float *) get_va_nth (argp, npos) : va_arg (arg, float *)) = is_neg ? -d : d; | |
| 1281 | 	 } | |
| 1282 | ||
| 1283 | 	 if (wbuf == tmp_wbuf_ptr) | |
| 1284 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1285 | ||
| 1286 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1287 | 	 ++rval; | |
| 1288 | 	 break; | |
| 1289 | ||
| 1290 | 	case '[': | |
| 1291 | 	 if ((flags & IS_L) != 0) | |
| 1292 | 	 { | |
| 1293 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1294 | 		{ | |
| 1295 | 		 if ((flags & IS_ALLOC_USED) != 0) | |
| 1296 | 		 { | |
| 1297 | 		 if (npos != 0) | |
| 1298 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1299 | 		 else | |
| 1300 | 		 pstr = va_arg (arg, char **); | |
| 1301 | ||
| 1302 | 		 if (!pstr) | |
| 1303 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1304 | 		 str_sz = 100; | |
| 1305 | 		 *pstr = (char *) malloc (100 * sizeof (wchar_t)); | |
| 1306 | 		 if ((wstr = (wchar_t *) *pstr) == NULL) | |
| 1307 | 			return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1308 | ||
| 1309 | 		 gcollect = resize_gcollect (gcollect); | |
| 1310 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1311 | 		 } | |
| 1312 | 		 else | |
| 1313 | 		 { | |
| 1314 | 		 if (npos != 0) | |
| 1315 | 			wstr = (wchar_t *) get_va_nth (argp, npos); | |
| 1316 | 		 else | |
| 1317 | 			wstr = va_arg (arg, wchar_t *); | |
| 1318 | 		 if (!wstr) | |
| 1319 | 			return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1320 | 		 } | |
| 1321 | 		} | |
| 1322 | ||
| 1323 | 	 } | |
| 1324 | 	 else if ((flags & IS_SUPPRESSED) == 0) | |
| 1325 | 	 { | |
| 1326 | 	 if ((flags & IS_ALLOC_USED) != 0) | |
| 1327 | 		{ | |
| 1328 | 		 if (npos != 0) | |
| 1329 | 		 pstr = (char **) get_va_nth (argp, npos); | |
| 1330 | 		 else | |
| 1331 | 		 pstr = va_arg (arg, char **); | |
| 1332 | ||
| 1333 | 		 if (!pstr) | |
| 1334 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1335 | 		 str_sz = 100; | |
| 1336 | 		 if ((str = *pstr = (char *) malloc (100)) == NULL) | |
| 1337 | 		 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1338 | 		 gcollect = resize_gcollect (gcollect); | |
| 1339 | 		 gcollect->ptrs[gcollect->count++] = pstr; | |
| 1340 | 		} | |
| 1341 | 	 else | |
| 1342 | 		{ | |
| 1343 | 		 if (npos != 0) | |
| 1344 | 		 str = (char *) get_va_nth (argp, npos); | |
| 1345 | 		 else | |
| 1346 | 		 str = va_arg (arg, char *); | |
| 1347 | 		 if (!str) | |
| 1348 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1349 | 		} | |
| 1350 | 	 } | |
| 1351 | ||
| 1352 | 	 not_in = (*f == '^' ? 1 : 0); | |
| 1353 | 	 if (*f == '^') | |
| 1354 | 	 f++; | |
| 1355 | ||
| 1356 | 	 if (width < 0) | |
| 1357 | 	 width = INT_MAX; | |
| 1358 | ||
| 1359 | 	 tmp_wbuf_ptr = (wchar_t *) f; | |
| 1360 | ||
| 1361 | 	 if (*f == L']') | |
| 1362 | 	 ++f; | |
| 1363 | ||
| 1364 | 	 while ((fc = *f++) != 0 && fc != L']'); | |
| 1365 | ||
| 1366 | 	 if (fc == 0) | |
| 1367 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1368 | 	 temp_wbuf_end = (wchar_t *) f - 1; | |
| 1369 | ||
| 1370 | 	 if ((flags & IS_L) != 0) | |
| 1371 | 	 { | |
| 1372 | 	 read_in_sv = read_in; | |
| 1373 | ||
| 1374 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1375 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1376 | ||
| 1377 | 	 do | |
| 1378 | 		{ | |
| 1379 | 		 int ended = 0; | |
| 1380 | 		 for (wbuf_iter = tmp_wbuf_ptr; wbuf_iter < temp_wbuf_end;) | |
| 1381 | 		 { | |
| 1382 | 		 if (wbuf_iter[0] == '-' && wbuf_iter[1] != 0 | |
| 1383 | 			 && (wbuf_iter + 1) != temp_wbuf_end | |
| 1384 | 			 && wbuf_iter != tmp_wbuf_ptr | |
| 1385 | 			 && (unsigned int) wbuf_iter[-1] <= (unsigned int) wbuf_iter[1]) | |
| 1386 | 			{ | |
| 1387 | 			 for (wc = wbuf_iter[-1] + 1; wc <= wbuf_iter[1] && (wint_t) wc != c; ++wc); | |
| 1388 | ||
| 1389 | 			 if (wc <= wbuf_iter[1] && !not_in) | |
| 1390 | 			 break; | |
| 1391 | 			 if (wc <= wbuf_iter[1] && not_in) | |
| 1392 | 			 { | |
| 1393 | 			 back_ch (c, s, &read_in, 0); | |
| 1394 | 			 ended = 1; | |
| 1395 | 			 break; | |
| 1396 | 			 } | |
| 1397 | ||
| 1398 | 			 wbuf_iter += 2; | |
| 1399 | 			} | |
| 1400 | 		 else | |
| 1401 | 			{ | |
| 1402 | 			 if ((wint_t) *wbuf_iter == c && !not_in) | |
| 1403 | 			 break; | |
| 1404 | 			 if ((wint_t) *wbuf_iter == c && not_in) | |
| 1405 | 			 { | |
| 1406 | 			 back_ch (c, s, &read_in, 0); | |
| 1407 | 			 ended = 1; | |
| 1408 | 			 break; | |
| 1409 | 			 } | |
| 1410 | ||
| 1411 | 			 ++wbuf_iter; | |
| 1412 | 			} | |
| 1413 | 		 } | |
| 1414 | 		 if (ended) | |
| 1415 | 		 break; | |
| 1416 | ||
| 1417 | 		 if (wbuf_iter == temp_wbuf_end && !not_in) | |
| 1418 | 		 { | |
| 1419 | 		 back_ch (c, s, &read_in, 0); | |
| 1420 | 		 break; | |
| 1421 | 		 } | |
| 1422 | ||
| 1423 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1424 | 		 { | |
| 1425 | 		 *wstr++ = c; | |
| 1426 | ||
| 1427 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 1428 | 			 && wstr == ((wchar_t *) *pstr + str_sz)) | |
| 1429 | 			{ | |
| 1430 | 			 new_sz = str_sz * 2; | |
| 1431 | 			 while ((wstr = (wchar_t *) realloc (*pstr, | |
| 1432 | 						 new_sz * sizeof (wchar_t))) == NULL | |
| 1433 | 				 && new_sz > (size_t) (str_sz + 1)) | |
| 1434 | 			 new_sz = str_sz + 1; | |
| 1435 | 			 if (!wstr) | |
| 1436 | 			 { | |
| 1437 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1438 | 				{ | |
| 1439 | 				 ((wchar_t *) (*pstr))[str_sz - 1] = 0; | |
| 1440 | 				 pstr = NULL; | |
| 1441 | 				 ++rval; | |
| 1442 | 				} | |
| 1443 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1444 | 			 } | |
| 1445 | 			 *pstr = (char *) wstr; | |
| 1446 | 			 wstr += str_sz; | |
| 1447 | 			 str_sz = new_sz; | |
| 1448 | 			} | |
| 1449 | 		 } | |
| 1450 | 		} | |
| 1451 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 1452 | ||
| 1453 | 	 if (read_in_sv == read_in) | |
| 1454 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1455 | ||
| 1456 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1457 | 		{ | |
| 1458 | 		 *wstr++ = 0; | |
| 1459 | ||
| 1460 | 		 optimize_alloc (pstr, (char *) wstr, str_sz * sizeof (wchar_t)); | |
| 1461 | 		 pstr = NULL; | |
| 1462 | 		 ++rval; | |
| 1463 | 		} | |
| 1464 | 	 } | |
| 1465 | 	 else | |
| 1466 | 	 { | |
| 1467 | 	 read_in_sv = read_in; | |
| 1468 | ||
| 1469 | 	 if ((c = in_ch (s, &read_in)) == WEOF) | |
| 1470 | 		return cleanup_return ((!rval ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1471 | ||
| 1472 | 	 memset (&state, 0, sizeof (state)); | |
| 1473 | ||
| 1474 | 	 do | |
| 1475 | 		{ | |
| 1476 | 		 int ended = 0; | |
| 1477 | 		 wbuf_iter = tmp_wbuf_ptr; | |
| 1478 | 		 while (wbuf_iter < temp_wbuf_end) | |
| 1479 | 		 { | |
| 1480 | 		 if (wbuf_iter[0] == '-' && wbuf_iter[1] != 0 | |
| 1481 | 			 && (wbuf_iter + 1) != temp_wbuf_end | |
| 1482 | 			 && wbuf_iter != tmp_wbuf_ptr | |
| 1483 | 			 && (unsigned int) wbuf_iter[-1] <= (unsigned int) wbuf_iter[1]) | |
| 1484 | 			{ | |
| 1485 | 			 for (wc = wbuf_iter[-1] + 1; wc <= wbuf_iter[1] && (wint_t) wc != c; ++wc); | |
| 1486 | ||
| 1487 | 			 if (wc <= wbuf_iter[1] && !not_in) | |
| 1488 | 			 break; | |
| 1489 | 			 if (wc <= wbuf_iter[1] && not_in) | |
| 1490 | 			 { | |
| 1491 | 			 back_ch (c, s, &read_in, 0); | |
| 1492 | 			 ended = 1; | |
| 1493 | 			 break; | |
| 1494 | 			 } | |
| 1495 | ||
| 1496 | 			 wbuf_iter += 2; | |
| 1497 | 			} | |
| 1498 | 		 else | |
| 1499 | 			{ | |
| 1500 | 			 if ((wint_t) *wbuf_iter == c && !not_in) | |
| 1501 | 			 break; | |
| 1502 | 			 if ((wint_t) *wbuf_iter == c && not_in) | |
| 1503 | 			 { | |
| 1504 | 			 back_ch (c, s, &read_in, 0); | |
| 1505 | 			 ended = 1; | |
| 1506 | 			 break; | |
| 1507 | 			 } | |
| 1508 | ||
| 1509 | 			 ++wbuf_iter; | |
| 1510 | 			} | |
| 1511 | 		 } | |
| 1512 | ||
| 1513 | 		 if (ended) | |
| 1514 | 		 break; | |
| 1515 | 		 if (wbuf_iter == temp_wbuf_end && !not_in) | |
| 1516 | 		 { | |
| 1517 | 		 back_ch (c, s, &read_in, 0); | |
| 1518 | 		 break; | |
| 1519 | 		 } | |
| 1520 | ||
| 1521 | 		 if ((flags & IS_SUPPRESSED) == 0) | |
| 1522 | 		 { | |
| 1523 | 		 if ((flags & IS_ALLOC_USED) != 0 | |
| 1524 | 			 && (str + MB_CUR_MAX) >= (*pstr + str_sz)) | |
| 1525 | 			{ | |
| 1526 | 			 new_sz = str_sz * 2; | |
| 1527 | 			 str_len = (str - *pstr); | |
| 1528 | ||
| 1529 | 			 while ((nstr = (char *) realloc (*pstr, new_sz)) == NULL | |
| 1530 | 			 	 && new_sz > (str_len + MB_CUR_MAX)) | |
| 1531 | 			 new_sz = str_len + MB_CUR_MAX; | |
| 1532 | 			 if (!nstr) | |
| 1533 | 			 { | |
| 1534 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1535 | 				{ | |
| 1536 | 				 ((*pstr))[str_len] = 0; | |
| 1537 | 				 pstr = NULL; | |
| 1538 | 				 ++rval; | |
| 1539 | 				} | |
| 1540 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1541 | 			 } | |
| 1542 | 			 *pstr = nstr; | |
| 1543 | 			 str = nstr + str_len; | |
| 1544 | 			 str_sz = new_sz; | |
| 1545 | 			} | |
| 1546 | 		 } | |
| 1547 | ||
| 1548 | 		 n = wcrtomb ((flags & IS_SUPPRESSED) == 0 ? str : NULL, c, &state); | |
| 1549 | 		 if (n == (size_t) -1LL) | |
| 1550 | 		 { | |
| 1551 | 		 errno = EILSEQ; | |
| 1552 | 		 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1553 | 		 } | |
| 1554 | ||
| 1555 | 		 str += n; | |
| 1556 | 		} | |
| 1557 | 	 while (--width > 0 && (c = in_ch (s, &read_in)) != WEOF); | |
| 1558 | ||
| 1559 | 	 if (read_in_sv == read_in) | |
| 1560 | 		return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1561 | ||
| 1562 | 	 if ((flags & IS_SUPPRESSED) == 0) | |
| 1563 | 		{ | |
| 1564 | 		 n = wcrtomb (buf, 0, &state); | |
| 1565 | 		 if (n > 0 && (flags & IS_ALLOC_USED) != 0 | |
| 1566 | 		 && (str + n) >= (*pstr + str_sz)) | |
| 1567 | 		 { | |
| 1568 | 		 str_len = (str - *pstr); | |
| 1569 | ||
| 1570 | 		 if ((nstr = (char *) realloc (*pstr, str_len + n + 1)) == NULL) | |
| 1571 | 			{ | |
| 1572 | 			 if ((flags & USE_POSIX_ALLOC) == 0) | |
| 1573 | 			 { | |
| 1574 | 			 (*pstr)[str_len] = 0; | |
| 1575 | 			 pstr = NULL; | |
| 1576 | 			 ++rval; | |
| 1577 | 			 } | |
| 1578 | 			 return cleanup_return (((flags & USE_POSIX_ALLOC) != 0 ? EOF : rval), &gcollect, pstr, &wbuf); | |
| 1579 | 			} | |
| 1580 | 		 *pstr = nstr; | |
| 1581 | 		 str = nstr + str_len; | |
| 1582 | 		 str_sz = str_len + n + 1; | |
| 1583 | 		 } | |
| 1584 | ||
| 1585 | 		 if (n) | |
| 1586 | 		 { | |
| 1587 | 		 memcpy (str, buf, n); | |
| 1588 | 		 str += n; | |
| 1589 | 		 } | |
| 1590 | 		 *str++ = 0; | |
| 1591 | ||
| 1592 | 		 optimize_alloc (pstr, str, str_sz); | |
| 1593 | 		 pstr = NULL; | |
| 1594 | 		 ++rval; | |
| 1595 | 		} | |
| 1596 | 	 } | |
| 1597 | 	 break; | |
| 1598 | ||
| 1599 | 	default: | |
| 1600 | 	 return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1601 | 	} | |
| 1602 | } | |
| 1603 | ||
| 1604 | if (ignore_ws) | |
| 1605 | { | |
| 1606 | while (iswspace ((c = in_ch (s, &read_in)))); | |
| 1607 | back_ch (c, s, &read_in, 0); | |
| 1608 | } | |
| 1609 | ||
| 1610 | return cleanup_return (rval, &gcollect, pstr, &wbuf); | |
| 1611 | } | |
| 1612 | ||
| 1613 | int | |
| 1614 | __mingw_vfwscanf (FILE *s, const wchar_t *format, va_list argp) | |
| 1615 | { | |
| 1616 | _IFP ifp; | |
| 1617 | memset (&ifp, 0, sizeof (_IFP)); | |
| 1618 | ifp.fp = s; | |
| 1619 | return __mingw_swformat (&ifp, format, argp); | |
| 1620 | } | |
| 1621 | ||
| 1622 | int | |
| 1623 | __mingw_vswscanf (const wchar_t *s, const wchar_t *format, va_list argp) | |
| 1624 | { | |
| 1625 | _IFP ifp; | |
| 1626 | memset (&ifp, 0, sizeof (_IFP)); | |
| 1627 | ifp.str = s; | |
| 1628 | ifp.is_string = 1; | |
| 1629 | return __mingw_swformat (&ifp, format, argp); | |
| 1630 | } | |
| 1631 |
lib/libc/mingw/stdio/scanf.S deleted-243| ... | ... | @@ -1,243 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | /* vsscanf, vswscanf, vfscanf, and vfwscanf all come here for i386 and arm. | |
| 8 | ||
| 9 | The goal of this routine is to turn a call to v*scanf into a call to | |
| 10 | s*scanf. This is needed because mingw-w64 uses msvcr100.dll, which doesn't | |
| 11 | support the v*scanf functions instead of msvcr120.dll which does. | |
| 12 | */ | |
| 13 | ||
| 14 | /* The function prototype here is (essentially): | |
| 15 | ||
| 16 | int __ms_v*scanf_internal (void *s, | |
| 17 | 			 void *format, | |
| 18 | 			 void *arg, | |
| 19 | 			 size_t count, | |
| 20 | 			 void *func); | |
| 21 | ||
| 22 | I say 'essentially' because passing a function pointer as void in ISO | |
| 23 | is not supported. But in the end, I take the first parameter (which | |
| 24 | may be a char *, a wchar_t *, or a FILE *) and put it into the newly | |
| 25 | formed stack, and eventually call the address in func. */ | |
| 26 | ||
| 27 | #if defined (__x86_64__) | |
| 28 | ||
| 29 | .text | |
| 30 | .align 16 | |
| 31 | ||
| 32 | /* scl 2: C_EXT - External (public) symbol - covers globals and externs | |
| 33 | type 32: DT_FCN - function returning T | |
| 34 | 	 */ | |
| 35 | .def __argtos; .scl 2; .type 32; .endef | |
| 36 | ||
| 37 | .seh_proc __argtos | |
| 38 | __argtos: | |
| 39 | ||
| 40 | /* When we are done: | |
| 41 | - s must be in rcx. That's where it is on entry. | |
| 42 | - format must be in rdx. That's where it is on entry. | |
| 43 | - The first pointer in arg must be in r8. arg is in r8 on entry. | |
| 44 | - The second pointer in arg must be in r9. arg is in r8 on entry. | |
| 45 | - The (count - 2) other pointers in arg must be on the stack, | |
| 46 | 	starting 32bytes into rsp. */ | |
| 47 | ||
| 48 | pushq %rbp | |
| 49 | .seh_pushreg %rbp | |
| 50 | movq %rsp, %rbp | |
| 51 | .seh_setframe %rbp, 0 | |
| 52 | ||
| 53 | /* We need to always reserve space to shadow 4 parameters. */ | |
| 54 | subq $32, %rsp | |
| 55 | .seh_stackalloc 32 | |
| 56 | .seh_endprologue | |
| 57 | ||
| 58 | movq 48(%rbp), %r10 /* func. */ | |
| 59 | ||
| 60 | /* We need enough room to shadow all the other args. | |
| 61 | Except the first 2, since they will be loaded in registers. */ | |
| 62 | cmpq $2, %r9 /* count. */ | |
| 63 | jbe .SKIP | |
| 64 | subq $2, %r9 /* # of ptrs to copy. */ | |
| 65 | /* Calculate stack size (arg is 8byte) and keep the stack 16byte aligned. */ | |
| 66 | leaq 8(, %r9, 8), %rax /* %rax = (%r9 + 1) * 8 */ | |
| 67 | andq $-16, %rax | |
| 68 | subq %rax, %rsp | |
| 69 | ||
| 70 | /* We are going to copy parameters from arg to our local stack. | |
| 71 | The first 32 bytes are in registers, but by spec, space | |
| 72 | must still be reserved for them on the stack. Put the | |
| 73 | rest of the pointers in the stack after that. */ | |
| 74 | lea 32(%rsp), %r11 /* dst. */ | |
| 75 | ||
| 76 | .LOOP: | |
| 77 | subq $1, %r9 | |
| 78 | ||
| 79 | /* Use 16 to skip over the first 2 pointers. */ | |
| 80 | movq 16(%r8, %r9, 8), %rax | |
| 81 | movq %rax, (%r11, %r9, 8) | |
| 82 | jnz .LOOP | |
| 83 | ||
| 84 | .SKIP: | |
| 85 | /* The stack is now correctly populated, and so are rcx and rdx. | |
| 86 | But we need to load the last 2 regs before making the call. */ | |
| 87 | movq 0x8(%r8), %r9 /* 2nd dest location (may be garbage if only 1 arg). */ | |
| 88 | movq (%r8), %r8 /* 1st dest location (may be garbage if no arg). */ | |
| 89 | ||
| 90 | /* Make the call. */ | |
| 91 | callq *%r10 | |
| 92 | ||
| 93 | /* Restore stack. */ | |
| 94 | movq %rbp, %rsp | |
| 95 | ||
| 96 | popq %rbp | |
| 97 | retq | |
| 98 | .seh_endproc | |
| 99 | ||
| 100 | #elif defined (_X86_) | |
| 101 | ||
| 102 | .text | |
| 103 | .align 16 | |
| 104 | ||
| 105 | /* scl 2: C_EXT - External (public) symbol - covers globals and externs | |
| 106 | type 32: DT_FCN - function returning T | |
| 107 | 	 */ | |
| 108 | .def __argtos; .scl 2; .type 32; .endef | |
| 109 | ||
| 110 | __argtos: | |
| 111 | pushl %ebp | |
| 112 | movl %esp, %ebp | |
| 113 | pushl %edi | |
| 114 | pushl %ebx | |
| 115 | ||
| 116 | /* Reserve enough stack space for everything. | |
| 117 | ||
| 118 | Stack usage will look like: | |
| 119 | 4 bytes - s | |
| 120 | 4 bytes - format | |
| 121 | 4*count bytes - variable # of parameters for sscanf (all ptrs). */ | |
| 122 | ||
| 123 | movl 20(%ebp), %ebx /* count. */ | |
| 124 | addl $2, %ebx /* s + format. */ | |
| 125 | sall $2, %ebx /* (count + 2) * 4. */ | |
| 126 | subl %ebx, %esp | |
| 127 | ||
| 128 | /* Write out s and format where they need to be for the sscanf call. */ | |
| 129 | movl 8(%ebp), %eax | |
| 130 | movl %eax, (%esp) /* s. */ | |
| 131 | movl 12(%ebp), %edx | |
| 132 | movl %edx, 0x4(%esp) /* format. */ | |
| 133 | ||
| 134 | /* We are going to copy _count_ pointers from arg to our | |
| 135 | local stack. */ | |
| 136 | movl 20(%ebp), %ecx /* # of ptrs to copy. */ | |
| 137 | testl %ecx, %ecx | |
| 138 | jz .SKIP | |
| 139 | lea 8(%esp), %edi /* dst. */ | |
| 140 | movl 16(%ebp), %edx /* src. */ | |
| 141 | ||
| 142 | .LOOP: | |
| 143 | subl $1, %ecx | |
| 144 | ||
| 145 | movl (%edx, %ecx, 4), %eax | |
| 146 | movl %eax, (%edi, %ecx, 4) | |
| 147 | jnz .LOOP | |
| 148 | ||
| 149 | .SKIP: | |
| 150 | /* The stack is now correctly populated. */ | |
| 151 | ||
| 152 | /* Make the call. */ | |
| 153 | call *24(%ebp) | |
| 154 | ||
| 155 | /* Restore stack. */ | |
| 156 | addl %ebx, %esp | |
| 157 | ||
| 158 | popl %ebx | |
| 159 | popl %edi | |
| 160 | leave | |
| 161 | ||
| 162 | ret | |
| 163 | ||
| 164 | #elif defined (__arm__) | |
| 165 | ||
| 166 | .text | |
| 167 | .align 2 | |
| 168 | .thumb_func | |
| 169 | .globl __argtos | |
| 170 | ||
| 171 | __argtos: | |
| 172 | push {r4-r8, lr} | |
| 173 | ldr r12, [sp, #24] | |
| 174 | ||
| 175 | ldr r5, [r2], #4 | |
| 176 | ldr r6, [r2], #4 | |
| 177 | ||
| 178 | subs r3, r3, #2 | |
| 179 | mov r8, #0 | |
| 180 | ble 2f | |
| 181 | ||
| 182 | /* Round the number of entries to an even number, to maintain | |
| 183 | * 8 byte stack alignment. */ | |
| 184 | mov r8, r3 | |
| 185 | add r8, r8, #1 | |
| 186 | bic r8, r8, #1 | |
| 187 | sub sp, sp, r8, lsl #2 | |
| 188 | mov r4, sp | |
| 189 | 1: ldr r7, [r2], #4 | |
| 190 | subs r3, r3, #1 | |
| 191 | str r7, [r4], #4 | |
| 192 | bne 1b | |
| 193 | ||
| 194 | 2: | |
| 195 | mov r2, r5 | |
| 196 | mov r3, r6 | |
| 197 | blx r12 | |
| 198 | ||
| 199 | add sp, sp, r8, lsl #2 | |
| 200 | pop {r4-r8, pc} | |
| 201 | ||
| 202 | #elif defined (__aarch64__) | |
| 203 | ||
| 204 | .text | |
| 205 | .align 2 | |
| 206 | .globl __argtos | |
| 207 | ||
| 208 | __argtos: | |
| 209 | stp x29, x30, [sp, #-16]! | |
| 210 | mov x29, sp | |
| 211 | mov x10, x2 | |
| 212 | mov x11, x3 | |
| 213 | mov x12, x4 | |
| 214 | ||
| 215 | ldr x2, [x10], #8 | |
| 216 | ldr x3, [x10], #8 | |
| 217 | ldr x4, [x10], #8 | |
| 218 | ldr x5, [x10], #8 | |
| 219 | ldr x6, [x10], #8 | |
| 220 | ldr x7, [x10], #8 | |
| 221 | ||
| 222 | subs x11, x11, #6 | |
| 223 | b.le 2f | |
| 224 | ||
| 225 | /* Round the number of entries to an even number, to maintain | |
| 226 | * 16 byte stack alignment. */ | |
| 227 | mov x13, x11 | |
| 228 | add x13, x13, #1 | |
| 229 | bic x13, x13, #1 | |
| 230 | sub sp, sp, x13, lsl #3 | |
| 231 | mov x9, sp | |
| 232 | 1: ldr x13, [x10], #8 | |
| 233 | subs x11, x11, #1 | |
| 234 | str x13, [x9], #8 | |
| 235 | b.ne 1b | |
| 236 | ||
| 237 | 2: | |
| 238 | blr x12 | |
| 239 | mov sp, x29 | |
| 240 | ldp x29, x30, [sp], #16 | |
| 241 | ret | |
| 242 | ||
| 243 | #endif |
lib/libc/mingw/stdio/scanf2-argcount-char.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define FUNC __ms_scanf_max_arg_count_internal | |
| 8 | #define TYPE char | |
| 9 | #include "scanf2-argcount-template.c" |
lib/libc/mingw/stdio/scanf2-argcount-template.c deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #include <stddef.h> | |
| 8 | ||
| 9 | size_t FUNC(const TYPE *format); | |
| 10 | size_t FUNC(const TYPE *format) | |
| 11 | { | |
| 12 | size_t count = 0; | |
| 13 | for (; *format; format++) { | |
| 14 | if (*format == (TYPE)'%') | |
| 15 | count++; | |
| 16 | } | |
| 17 | return count; | |
| 18 | } |
lib/libc/mingw/stdio/scanf2-argcount-wchar.c deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #define FUNC __ms_wscanf_max_arg_count_internal | |
| 8 | #define TYPE wchar_t | |
| 9 | #include "scanf2-argcount-template.c" |
lib/libc/mingw/stdio/scanf2-template.S deleted-32| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #if defined(_ARM_) || defined(__arm__) | |
| 8 | .thumb | |
| 9 | #endif | |
| 10 | .text | |
| 11 | .p2align 4,,15 | |
| 12 | .globl FCT | |
| 13 | .def FCT; .scl 2; .type 32; .endef | |
| 14 | #ifdef __x86_64__ | |
| 15 | .seh_proc FCT | |
| 16 | #endif | |
| 17 | FCT: | |
| 18 | #ifdef __x86_64__ | |
| 19 | .seh_endprologue | |
| 20 | #endif | |
| 21 | #if defined(_AMD64_) || defined(__x86_64__) || defined(_X86_) || defined(__i386__) | |
| 22 | jmp FWD | |
| 23 | #elif defined(_ARM_) || defined(__arm__) | |
| 24 | .thumb_func | |
| 25 | b FWD | |
| 26 | #elif defined(_ARM64_) || defined(__aarch64__) | |
| 27 | b FWD | |
| 28 | #endif | |
| 29 | #ifdef __x86_64__ | |
| 30 | .seh_endproc | |
| 31 | #endif | |
| 32 | .def FWD; .scl 2; .type 32; .endef |
lib/libc/mingw/stdio/snwprintf.c+1-1| ... | ... | @@ -12,7 +12,7 @@ int __cdecl __ms_snwprintf(wchar_t *buffer, size_t n, const wchar_t *format, ... |
| 12 | 12 | va_list argptr; |
| 13 | 13 | |
| 14 | 14 | va_start(argptr, format); |
| 15 | retval = _vsnwprintf(buffer, n, format, argptr); | |
| 15 | retval = __ms_vsnwprintf(buffer, n, format, argptr); | |
| 16 | 16 | va_end(argptr); |
| 17 | 17 | return retval; |
| 18 | 18 | } |
lib/libc/mingw/stdio/ucrt_ms_fprintf.c created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #undef __MSVCRT_VERSION__ | |
| 8 | #define _UCRT | |
| 9 | ||
| 10 | #include <stdio.h> | |
| 11 | #include <stdarg.h> | |
| 12 | ||
| 13 | int __cdecl __ms_fprintf(FILE * restrict file, const char * restrict format, ...) | |
| 14 | { | |
| 15 | va_list ap; | |
| 16 | int ret; | |
| 17 | va_start(ap, format); | |
| 18 | ret = __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, file, format, NULL, ap); | |
| 19 | va_end(ap); | |
| 20 | return ret; | |
| 21 | } | |
| 22 | int __cdecl (*__MINGW_IMP_SYMBOL(__ms_fprintf))(FILE * restrict, const char * restrict, ...) = __ms_fprintf; |
lib/libc/mingw/stdio/vfscanf.c deleted-35| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #include <stdio.h> | |
| 8 | #include <stdarg.h> | |
| 9 | ||
| 10 | extern int __ms_vfscanf_internal ( | |
| 11 | FILE * s, | |
| 12 | const char * format, | |
| 13 | va_list arg, | |
| 14 | size_t count, | |
| 15 | int (*func)(FILE * __restrict__, const char * __restrict__, ...)) | |
| 16 | asm("__argtos"); | |
| 17 | ||
| 18 | extern size_t __ms_scanf_max_arg_count_internal (const char * format); | |
| 19 | ||
| 20 | int __ms_vfscanf (FILE * __restrict__ stream, const char * __restrict__ format, va_list arg) | |
| 21 | { | |
| 22 | size_t count = __ms_scanf_max_arg_count_internal (format); | |
| 23 | int ret; | |
| 24 | ||
| 25 | #if defined(_AMD64_) || defined(__x86_64__) || \ | |
| 26 | defined(_X86_) || defined(__i386__) || \ | |
| 27 | defined(_ARM_) || defined(__arm__) || \ | |
| 28 | defined(_ARM64_) || defined(__aarch64__) | |
| 29 | ret = __ms_vfscanf_internal (stream, format, arg, count, fscanf); | |
| 30 | #else | |
| 31 | #error "unknown platform" | |
| 32 | #endif | |
| 33 | ||
| 34 | return ret; | |
| 35 | } |
lib/libc/mingw/stdio/vfscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vfscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vfscanf) | |
| 10 | ||
| 11 | 	.file "vfscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/stdio/vfwscanf.c deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #include <stdarg.h> | |
| 8 | #include <wchar.h> | |
| 9 | ||
| 10 | extern int __ms_vfwscanf_internal ( | |
| 11 | FILE * s, | |
| 12 | const wchar_t * format, | |
| 13 | va_list arg, | |
| 14 | size_t count, | |
| 15 | int (*func)(FILE * __restrict__, const wchar_t * __restrict__, ...)) | |
| 16 | asm("__argtos"); | |
| 17 | ||
| 18 | extern size_t __ms_wscanf_max_arg_count_internal (const wchar_t * format); | |
| 19 | ||
| 20 | int __ms_vfwscanf (FILE * __restrict__ stream, | |
| 21 | const wchar_t * __restrict__ format, va_list arg) | |
| 22 | { | |
| 23 | size_t count = __ms_wscanf_max_arg_count_internal (format); | |
| 24 | int ret; | |
| 25 | ||
| 26 | #if defined(_AMD64_) || defined(__x86_64__) || \ | |
| 27 | defined(_X86_) || defined(__i386__) || \ | |
| 28 | defined(_ARM_) || defined(__arm__) || \ | |
| 29 | defined (_ARM64_) || defined (__aarch64__) | |
| 30 | ret = __ms_vfwscanf_internal (stream, format, arg, count, fwscanf); | |
| 31 | #else | |
| 32 | #error "unknown platform" | |
| 33 | #endif | |
| 34 | ||
| 35 | return ret; | |
| 36 | } |
lib/libc/mingw/stdio/vfwscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vfwscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vfwscanf) | |
| 10 | ||
| 11 | 	.file "vfwscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/stdio/vscanf.c deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | // By aaronwl 2003-01-28 for mingw-msvcrt | |
| 7 | // Public domain: all copyrights disclaimed, absolutely no warranties | |
| 8 | ||
| 9 | #include <stdarg.h> | |
| 10 | #include <stdio.h> | |
| 11 | ||
| 12 | int __ms_vscanf(const char * __restrict__ format, va_list arg) | |
| 13 | { | |
| 14 | return __ms_vfscanf(stdin, format, arg); | |
| 15 | } |
lib/libc/mingw/stdio/vscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vscanf) | |
| 10 | ||
| 11 | 	.file "vscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/stdio/vsnwprintf.c+19-1| ... | ... | @@ -12,5 +12,23 @@ int __cdecl __ms_vsnwprintf(wchar_t *buffer, size_t n, const wchar_t * format, |
| 12 | 12 | |
| 13 | 13 | int __cdecl __ms_vsnwprintf(wchar_t *buffer, size_t n, const wchar_t * format, va_list argptr) |
| 14 | 14 | { |
| 15 | return _vsnwprintf(buffer, n, format, argptr); | |
| 15 | int retval; | |
| 16 | ||
| 17 | /* _vsnwprintf() does not work with zero length buffer | |
| 18 | * so count number of characters by _vscwprintf() call */ | |
| 19 | if (n == 0) | |
| 20 | return _vscwprintf(format, argptr); | |
| 21 | ||
| 22 | retval = _vsnwprintf(buffer, n, format, argptr); | |
| 23 | ||
| 24 | /* _vsnwprintf() does not fill trailing null character if there is not place for it */ | |
| 25 | if (retval < 0 || (size_t)retval == n) | |
| 26 | buffer[n-1] = '\0'; | |
| 27 | ||
| 28 | /* _vsnwprintf() returns negative number if buffer is too small | |
| 29 | * so count number of characters by _vscwprintf() call */ | |
| 30 | if (retval < 0) | |
| 31 | retval = _vscwprintf(format, argptr); | |
| 32 | ||
| 33 | return retval; | |
| 16 | 34 | } |
lib/libc/mingw/stdio/vsscanf.c deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #include <stdarg.h> | |
| 8 | #include <stdio.h> | |
| 9 | ||
| 10 | extern int __ms_vsscanf_internal ( | |
| 11 | const char * s, | |
| 12 | const char * format, | |
| 13 | va_list arg, | |
| 14 | size_t count, | |
| 15 | int (*func)(const char * __restrict__, const char * __restrict__, ...)) | |
| 16 | asm("__argtos"); | |
| 17 | ||
| 18 | extern size_t __ms_scanf_max_arg_count_internal (const char * format); | |
| 19 | ||
| 20 | int __ms_vsscanf (const char * __restrict__ s, | |
| 21 | const char * __restrict__ format, va_list arg) | |
| 22 | { | |
| 23 | size_t count = __ms_scanf_max_arg_count_internal (format); | |
| 24 | int ret; | |
| 25 | ||
| 26 | #if defined(_AMD64_) || defined(__x86_64__) || \ | |
| 27 | defined(_X86_) || defined(__i386__) || \ | |
| 28 | defined(_ARM_) || defined(__arm__) || \ | |
| 29 | defined(_ARM64_) || defined(__aarch64__) | |
| 30 | ret = __ms_vsscanf_internal (s, format, arg, count, sscanf); | |
| 31 | #else | |
| 32 | #error "unknown platform" | |
| 33 | #endif | |
| 34 | ||
| 35 | return ret; | |
| 36 | } |
lib/libc/mingw/stdio/vsscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vsscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vsscanf) | |
| 10 | ||
| 11 | 	.file "vsscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/stdio/vswscanf.c deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | ||
| 7 | #include <stdarg.h> | |
| 8 | #include <wchar.h> | |
| 9 | ||
| 10 | extern int __ms_vswscanf_internal ( | |
| 11 | const wchar_t * s, | |
| 12 | const wchar_t * format, | |
| 13 | va_list arg, | |
| 14 | size_t count, | |
| 15 | int (*func)(const wchar_t * __restrict__, const wchar_t * __restrict__, ...)) | |
| 16 | asm("__argtos"); | |
| 17 | ||
| 18 | extern size_t __ms_wscanf_max_arg_count_internal (const wchar_t * format); | |
| 19 | ||
| 20 | int __ms_vswscanf(const wchar_t * __restrict__ s, const wchar_t * __restrict__ format, | |
| 21 | va_list arg) | |
| 22 | { | |
| 23 | size_t count = __ms_wscanf_max_arg_count_internal (format); | |
| 24 | int ret; | |
| 25 | ||
| 26 | #if defined(_AMD64_) || defined(__x86_64__) || \ | |
| 27 | defined(_X86_) || defined(__i386__) || \ | |
| 28 | defined(_ARM_) || defined(__arm__) || \ | |
| 29 | defined(_ARM64_) || defined(__aarch64__) | |
| 30 | ret = __ms_vswscanf_internal (s, format, arg, count, swscanf); | |
| 31 | #else | |
| 32 | #error "unknown platform" | |
| 33 | #endif | |
| 34 | ||
| 35 | return ret; | |
| 36 | } |
lib/libc/mingw/stdio/vswscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vswscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vswscanf) | |
| 10 | ||
| 11 | 	.file "vswscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/stdio/vwscanf.c deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | // By aaronwl 2003-01-28 for mingw-msvcrt. | |
| 7 | // Public domain: all copyrights disclaimed, absolutely no warranties. | |
| 8 | ||
| 9 | #include <stdarg.h> | |
| 10 | #include <wchar.h> | |
| 11 | #include <stdio.h> | |
| 12 | ||
| 13 | int __ms_vwscanf (const wchar_t * __restrict__ format, va_list arg) | |
| 14 | { | |
| 15 | return __ms_vfwscanf(stdin, format, arg); | |
| 16 | } |
lib/libc/mingw/stdio/vwscanf2.S deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | #include <_mingw_mac.h> | |
| 7 | ||
| 8 | #define FCT __MINGW_USYMBOL(vwscanf) | |
| 9 | #define FWD __MINGW_USYMBOL(__ms_vwscanf) | |
| 10 | ||
| 11 | 	.file "vwscanf2.S" | |
| 12 | #include "scanf2-template.S" |
lib/libc/mingw/winpthreads/thread.c+3-2| ... | ... | @@ -970,7 +970,8 @@ void |
| 970 | 970 | _pthread_cleanup_dest (pthread_t t) |
| 971 | 971 | { |
| 972 | 972 | 	_pthread_v *tv; |
| 973 | 	unsigned int i, j; | |
| 973 | 	unsigned int j; | |
| 974 | 	int i; | |
| 974 | 975 | |
| 975 | 976 | 	if (!t) |
| 976 | 977 | 		return; |
| ... | ... | @@ -983,7 +984,7 @@ _pthread_cleanup_dest (pthread_t t) |
| 983 | 984 | 		int flag = 0; |
| 984 | 985 | |
| 985 | 986 | 		pthread_spin_lock (&tv->spin_keys); |
| 986 | 		for (i = 0; i < tv->keymax; i++) | |
| 987 | 		for (i = tv->keymax - 1; i >= 0; i--) | |
| 987 | 988 | 		{ |
| 988 | 989 | 			void *val = tv->keyval[i]; |
| 989 | 990 |
lib/libc/mingw/winpthreads/thread.h+1-1| ... | ... | @@ -74,6 +74,6 @@ void thread_print_set(int state); |
| 74 | 74 | void thread_print(volatile pthread_t t, char *txt); |
| 75 | 75 | #endif |
| 76 | 76 | int __pthread_shallcancel(void); |
| 77 | struct _pthread_v *WINPTHREAD_API __pth_gpointer_locked (pthread_t id); | |
| 77 | WINPTHREAD_API struct _pthread_v * __pth_gpointer_locked (pthread_t id); | |
| 78 | 78 | |
| 79 | 79 | #endif |
src/mingw.zig+17-30| ... | ... | @@ -497,7 +497,7 @@ const mingw32_generic_src = [_][]const u8{ |
| 497 | 497 | "crt" ++ path.sep_str ++ "cxa_atexit.c", |
| 498 | 498 | "crt" ++ path.sep_str ++ "cxa_thread_atexit.c", |
| 499 | 499 | "crt" ++ path.sep_str ++ "tls_atexit.c", |
| 500 | "crt" ++ path.sep_str ++ "intrincs" ++ path.sep_str ++ "RtlSecureZeroMemory.c", | |
| 500 | "intrincs" ++ path.sep_str ++ "RtlSecureZeroMemory.c", | |
| 501 | 501 | // mingwex |
| 502 | 502 | "cfguard" ++ path.sep_str ++ "mingw_cfguard_support.c", |
| 503 | 503 | "complex" ++ path.sep_str ++ "_cabs.c", |
| ... | ... | @@ -630,8 +630,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 630 | 630 | "misc" ++ path.sep_str ++ "getlogin.c", |
| 631 | 631 | "misc" ++ path.sep_str ++ "getopt.c", |
| 632 | 632 | "misc" ++ path.sep_str ++ "gettimeofday.c", |
| 633 | "misc" ++ path.sep_str ++ "isblank.c", | |
| 634 | "misc" ++ path.sep_str ++ "iswblank.c", | |
| 635 | 633 | "misc" ++ path.sep_str ++ "mempcpy.c", |
| 636 | 634 | "misc" ++ path.sep_str ++ "mingw-access.c", |
| 637 | 635 | "misc" ++ path.sep_str ++ "mingw-aligned-malloc.c", |
| ... | ... | @@ -658,8 +656,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 658 | 656 | "misc" ++ path.sep_str ++ "wcstold.c", |
| 659 | 657 | "misc" ++ path.sep_str ++ "wcstoumax.c", |
| 660 | 658 | "misc" ++ path.sep_str ++ "wctob.c", |
| 661 | "misc" ++ path.sep_str ++ "wctrans.c", | |
| 662 | "misc" ++ path.sep_str ++ "wctype.c", | |
| 663 | 659 | "misc" ++ path.sep_str ++ "wdirent.c", |
| 664 | 660 | "misc" ++ path.sep_str ++ "winbs_uint64.c", |
| 665 | 661 | "misc" ++ path.sep_str ++ "winbs_ulong.c", |
| ... | ... | @@ -692,35 +688,36 @@ const mingw32_generic_src = [_][]const u8{ |
| 692 | 688 | "stdio" ++ path.sep_str ++ "lseek64.c", |
| 693 | 689 | "stdio" ++ path.sep_str ++ "mingw_asprintf.c", |
| 694 | 690 | "stdio" ++ path.sep_str ++ "mingw_fprintf.c", |
| 695 | "stdio" ++ path.sep_str ++ "mingw_fprintfw.c", | |
| 691 | "stdio" ++ path.sep_str ++ "mingw_fwprintf.c", | |
| 696 | 692 | "stdio" ++ path.sep_str ++ "mingw_fscanf.c", |
| 697 | 693 | "stdio" ++ path.sep_str ++ "mingw_fwscanf.c", |
| 698 | 694 | "stdio" ++ path.sep_str ++ "mingw_pformat.c", |
| 699 | "stdio" ++ path.sep_str ++ "mingw_pformatw.c", | |
| 695 | "stdio" ++ path.sep_str ++ "mingw_sformat.c", | |
| 696 | "stdio" ++ path.sep_str ++ "mingw_swformat.c", | |
| 697 | "stdio" ++ path.sep_str ++ "mingw_wpformat.c", | |
| 700 | 698 | "stdio" ++ path.sep_str ++ "mingw_printf.c", |
| 701 | "stdio" ++ path.sep_str ++ "mingw_printfw.c", | |
| 699 | "stdio" ++ path.sep_str ++ "mingw_wprintf.c", | |
| 702 | 700 | "stdio" ++ path.sep_str ++ "mingw_scanf.c", |
| 703 | 701 | "stdio" ++ path.sep_str ++ "mingw_snprintf.c", |
| 704 | "stdio" ++ path.sep_str ++ "mingw_snprintfw.c", | |
| 702 | "stdio" ++ path.sep_str ++ "mingw_snwprintf.c", | |
| 705 | 703 | "stdio" ++ path.sep_str ++ "mingw_sprintf.c", |
| 706 | "stdio" ++ path.sep_str ++ "mingw_sprintfw.c", | |
| 704 | "stdio" ++ path.sep_str ++ "mingw_swprintf.c", | |
| 707 | 705 | "stdio" ++ path.sep_str ++ "mingw_sscanf.c", |
| 708 | 706 | "stdio" ++ path.sep_str ++ "mingw_swscanf.c", |
| 709 | 707 | "stdio" ++ path.sep_str ++ "mingw_vasprintf.c", |
| 710 | 708 | "stdio" ++ path.sep_str ++ "mingw_vfprintf.c", |
| 711 | "stdio" ++ path.sep_str ++ "mingw_vfprintfw.c", | |
| 709 | "stdio" ++ path.sep_str ++ "mingw_vfwprintf.c", | |
| 712 | 710 | "stdio" ++ path.sep_str ++ "mingw_vfscanf.c", |
| 713 | 711 | "stdio" ++ path.sep_str ++ "mingw_vprintf.c", |
| 714 | "stdio" ++ path.sep_str ++ "mingw_vprintfw.c", | |
| 712 | "stdio" ++ path.sep_str ++ "mingw_vsscanf.c", | |
| 713 | "stdio" ++ path.sep_str ++ "mingw_vwprintf.c", | |
| 715 | 714 | "stdio" ++ path.sep_str ++ "mingw_vsnprintf.c", |
| 716 | "stdio" ++ path.sep_str ++ "mingw_vsnprintfw.c", | |
| 715 | "stdio" ++ path.sep_str ++ "mingw_vsnwprintf.c", | |
| 717 | 716 | "stdio" ++ path.sep_str ++ "mingw_vsprintf.c", |
| 718 | "stdio" ++ path.sep_str ++ "mingw_vsprintfw.c", | |
| 717 | "stdio" ++ path.sep_str ++ "mingw_vswprintf.c", | |
| 719 | 718 | "stdio" ++ path.sep_str ++ "mingw_wscanf.c", |
| 720 | "stdio" ++ path.sep_str ++ "mingw_wvfscanf.c", | |
| 721 | "stdio" ++ path.sep_str ++ "scanf2-argcount-char.c", | |
| 722 | "stdio" ++ path.sep_str ++ "scanf2-argcount-wchar.c", | |
| 723 | "stdio" ++ path.sep_str ++ "scanf.S", | |
| 719 | "stdio" ++ path.sep_str ++ "mingw_vfwscanf.c", | |
| 720 | "stdio" ++ path.sep_str ++ "mingw_vswscanf.c", | |
| 724 | 721 | "stdio" ++ path.sep_str ++ "snprintf.c", |
| 725 | 722 | "stdio" ++ path.sep_str ++ "snwprintf.c", |
| 726 | 723 | "stdio" ++ path.sep_str ++ "strtok_r.c", |
| ... | ... | @@ -728,20 +725,8 @@ const mingw32_generic_src = [_][]const u8{ |
| 728 | 725 | "stdio" ++ path.sep_str ++ "ulltoa.c", |
| 729 | 726 | "stdio" ++ path.sep_str ++ "ulltow.c", |
| 730 | 727 | "stdio" ++ path.sep_str ++ "vasprintf.c", |
| 731 | "stdio" ++ path.sep_str ++ "vfscanf.c", | |
| 732 | "stdio" ++ path.sep_str ++ "vfscanf2.S", | |
| 733 | "stdio" ++ path.sep_str ++ "vfwscanf.c", | |
| 734 | "stdio" ++ path.sep_str ++ "vfwscanf2.S", | |
| 735 | "stdio" ++ path.sep_str ++ "vscanf.c", | |
| 736 | "stdio" ++ path.sep_str ++ "vscanf2.S", | |
| 737 | 728 | "stdio" ++ path.sep_str ++ "vsnprintf.c", |
| 738 | 729 | "stdio" ++ path.sep_str ++ "vsnwprintf.c", |
| 739 | "stdio" ++ path.sep_str ++ "vsscanf.c", | |
| 740 | "stdio" ++ path.sep_str ++ "vsscanf2.S", | |
| 741 | "stdio" ++ path.sep_str ++ "vswscanf.c", | |
| 742 | "stdio" ++ path.sep_str ++ "vswscanf2.S", | |
| 743 | "stdio" ++ path.sep_str ++ "vwscanf.c", | |
| 744 | "stdio" ++ path.sep_str ++ "vwscanf2.S", | |
| 745 | 730 | "stdio" ++ path.sep_str ++ "wtoll.c", |
| 746 | 731 | // mingwthrd |
| 747 | 732 | "libsrc" ++ path.sep_str ++ "mingwthrd_mt.c", |
| ... | ... | @@ -768,6 +753,7 @@ const mingw32_generic_src = [_][]const u8{ |
| 768 | 753 | "stdio" ++ path.sep_str ++ "ucrt_fprintf.c", |
| 769 | 754 | "stdio" ++ path.sep_str ++ "ucrt_fscanf.c", |
| 770 | 755 | "stdio" ++ path.sep_str ++ "ucrt_fwprintf.c", |
| 756 | "stdio" ++ path.sep_str ++ "ucrt_ms_fprintf.c", | |
| 771 | 757 | "stdio" ++ path.sep_str ++ "ucrt_ms_fwprintf.c", |
| 772 | 758 | "stdio" ++ path.sep_str ++ "ucrt_printf.c", |
| 773 | 759 | "stdio" ++ path.sep_str ++ "ucrt_scanf.c", |
| ... | ... | @@ -933,6 +919,7 @@ const mingw32_x86_src = [_][]const u8{ |
| 933 | 919 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl.c", |
| 934 | 920 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cosl_internal.S", |
| 935 | 921 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossin.c", |
| 922 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "cossinl.c", | |
| 936 | 923 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "exp2l.S", |
| 937 | 924 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expl.c", |
| 938 | 925 | "math" ++ path.sep_str ++ "x86" ++ path.sep_str ++ "expm1l.c", |