From 4ab1558d8abb21656fb069ee866db72147afdf91 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Mon, 22 Jan 2001 02:17:29 +0000 Subject: [PATCH] - Remove from winnt.h. - ntdll: complete crt functions, prevent libc imports, fix sscanf. --- dlls/dplayx/dplobby.c | 1 + dlls/msvcrt/msvcrt.h | 2 + dlls/ntdll/ntdll.spec | 32 ++++---- dlls/ntdll/string.c | 88 ++++++++++++++++++++ dlls/ntdll/wcstring.c | 157 ++++++++++++++++++++++++++++++++++++ dlls/opengl32/wgl.c | 1 + dlls/setupapi/setupx_main.c | 1 + dlls/user/lstr.c | 1 + dlls/user/user_main.c | 1 + dlls/winaspi/aspi.c | 1 + dlls/wininet/http.c | 1 + dlls/wsock32/protocol.c | 1 + include/winnt.h | 1 - loader/pe_image.c | 1 + tools/winebuild/import.c | 1 + tools/winebuild/main.c | 1 + 16 files changed, 274 insertions(+), 17 deletions(-) diff --git a/dlls/dplayx/dplobby.c b/dlls/dplayx/dplobby.c index 8fa426d0f84..19361807419 100644 --- a/dlls/dplayx/dplobby.c +++ b/dlls/dplayx/dplobby.c @@ -5,6 +5,7 @@ * * */ +#include #include "winerror.h" #include "winnt.h" #include "winreg.h" diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index a5af9eef171..1cc2697c725 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -8,6 +8,8 @@ #include "winerror.h" #include "winnls.h" #include +#include +#include /* Files */ #define MSVCRT_EOF -1 diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 8f282101ec2..ed34973cac0 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -884,11 +884,11 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem @ cdecl _ftol() NTDLL__ftol @ cdecl _itoa(long ptr long) _itoa @ cdecl _ltoa(long ptr long) _ltoa -@ stub _memccpy +@ cdecl _memccpy(ptr ptr long long) memccpy @ cdecl _memicmp(str str long) _memicmp @ varargs _snprintf(ptr long ptr) snprintf -@ stub _snwprintf -@ stub _splitpath +@ varargs _snwprintf(wstr long wstr) _snwprintf +@ cdecl _splitpath(str str str str str) _splitpath @ cdecl _strcmpi(str str) strcasecmp @ cdecl _stricmp(str str) strcasecmp @ cdecl _strlwr(str) _strlwr @@ -901,14 +901,14 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem @ cdecl _wcslwr(wstr) NTDLL__wcslwr @ cdecl _wcsnicmp(wstr wstr long) NTDLL__wcsnicmp @ cdecl _wcsupr(wstr) NTDLL__wcsupr -@ stub abs -@ stub atan +@ cdecl -noimport abs(long) abs +@ cdecl -noimport atan(double) atan @ cdecl -noimport atoi(str) atoi @ cdecl -noimport atol(str) atol -@ stub ceil +@ cdecl -noimport ceil(double) ceil @ cdecl -noimport cos(double) cos -@ stub fabs -@ stub floor +@ cdecl -noimport fabs(double) fabs +@ cdecl -noimport floor(double) floor @ cdecl isalpha(long) isalpha @ cdecl isdigit(long) isdigit @ cdecl islower(long) islower @@ -918,8 +918,8 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem @ cdecl iswalpha(long) NTDLL_iswalpha @ cdecl iswctype(long long) NTDLL_iswctype @ cdecl isxdigit(long) isxdigit -@ stub labs -@ stub log +@ cdecl -noimport labs(long) labs +@ cdecl -noimport log(double) log @ cdecl mbstowcs(ptr str long) NTDLL_mbstowcs @ cdecl -noimport memchr(ptr long long) memchr @ cdecl -noimport memcmp(ptr ptr long) memcmp @@ -929,9 +929,9 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem @ cdecl -noimport pow(double double) pow @ cdecl -noimport qsort(ptr long long ptr) qsort @ cdecl -noimport sin(double) sin -@ varargs sprintf(str str) sprintf -@ stub sqrt -@ varargs sscanf() sscanf +@ varargs -noimport sprintf(str str) sprintf +@ cdecl -noimport sqrt(double) sqrt +@ varargs -noimport sscanf(str str) sscanf @ cdecl -noimport strcat(str str) strcat @ cdecl -noimport strchr(str long) strchr @ cdecl -noimport strcmp(str str) strcmp @@ -946,13 +946,13 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem @ cdecl -noimport strspn(str str) strspn @ cdecl -noimport strstr(str str) strstr @ cdecl -noimport strtol(str ptr long) strtol -@ stub swprintf -@ stub tan +@ varargs swprintf(wstr wstr) NTDLL_swprintf +@ cdecl -noimport tan(double) tan @ cdecl tolower(long) tolower @ cdecl toupper(long) toupper @ cdecl towlower(long) NTDLL_towlower @ cdecl towupper(long) NTDLL_towupper -@ cdecl vsprintf(ptr str ptr) vsprintf +@ cdecl -noimport vsprintf(ptr str ptr) vsprintf @ cdecl wcscat(wstr wstr) NTDLL_wcscat @ cdecl wcschr(wstr long) NTDLL_wcschr @ cdecl wcscmp(wstr wstr) NTDLL_wcscmp diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c index 5e552b784b8..1b09dbb1a0c 100644 --- a/dlls/ntdll/string.c +++ b/dlls/ntdll/string.c @@ -2,6 +2,7 @@ * NTDLL string functions * * Copyright 2000 Alexandre Julliard + * Copyright 2000 Jon Griffiths */ #include "config.h" @@ -92,3 +93,90 @@ LPSTR __cdecl _itoa( int x, LPSTR buf, INT radix ) { return _ltoa( x, buf, radix ); } + + +/********************************************************************* + * _splitpath (NTDLL) + */ +void __cdecl _splitpath(const char* inpath, char * drv, char * dir, + char* fname, char * ext ) +{ + /* Modified PD code from 'snippets' collection. */ + char ch, *ptr, *p; + char pathbuff[MAX_PATH], *path=pathbuff; + + strcpy(pathbuff, inpath); + + /* convert slashes to backslashes for searching */ + for (ptr = (char*)path; *ptr; ++ptr) + if ('/' == *ptr) + *ptr = '\\'; + + /* look for drive spec */ + if ('\0' != (ptr = strchr(path, ':'))) + { + ++ptr; + if (drv) + { + strncpy(drv, path, ptr - path); + drv[ptr - path] = '\0'; + } + path = ptr; + } + else if (drv) + *drv = '\0'; + + /* find rightmost backslash or leftmost colon */ + if (NULL == (ptr = strrchr(path, '\\'))) + ptr = (strchr(path, ':')); + + if (!ptr) + { + ptr = (char *)path; /* no path */ + if (dir) + *dir = '\0'; + } + else + { + ++ptr; /* skip the delimiter */ + if (dir) + { + ch = *ptr; + *ptr = '\0'; + strcpy(dir, path); + *ptr = ch; + } + } + + if (NULL == (p = strrchr(ptr, '.'))) + { + if (fname) + strcpy(fname, ptr); + if (ext) + *ext = '\0'; + } + else + { + *p = '\0'; + if (fname) + strcpy(fname, ptr); + *p = '.'; + if (ext) + strcpy(ext, p); + } + + /* Fix pathological case - Win returns ':' as part of the + * directory when no drive letter is given. + */ + if (drv && drv[0] == ':') + { + *drv = '\0'; + if (dir) + { + pathbuff[0] = ':'; + pathbuff[1] = '\0'; + strcat(pathbuff,dir); + strcpy(dir,pathbuff); + } + } +} diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c index 6f43b0b4835..55da5180350 100644 --- a/dlls/ntdll/wcstring.c +++ b/dlls/ntdll/wcstring.c @@ -2,13 +2,16 @@ * NTDLL wide-char functions * * Copyright 2000 Alexandre Julliard + * Copyright 2000 Jon Griffiths */ #include "config.h" #include +#include #include #include +#include #include "windef.h" #include "winbase.h" @@ -334,3 +337,157 @@ LPWSTR __cdecl _ultow(ULONG value, LPWSTR string, INT radix) *sp = 0; return string; } + + +/* INTERNAL: Wide char snprintf + * If you fix a bug in this function, fix it in msvcrt/wcs.c also! + */ +static int __cdecl NTDLL_vsnwprintf(WCHAR *str, unsigned int len, + const WCHAR *format, va_list valist) +{ + unsigned int written = 0; + const WCHAR *iter = format; + char bufa[256], fmtbufa[64], *fmta; + + TRACE("(%d,%s)\n",len,debugstr_w(format)); + + while (*iter) + { + while (*iter && *iter != (WCHAR)L'%') + { + if (written++ >= len) + return -1; + *str++ = *iter++; + } + if (*iter == (WCHAR)L'%') + { + fmta = fmtbufa; + *fmta++ = *iter++; + while (*iter == (WCHAR)L'0' || + *iter == (WCHAR)L'+' || + *iter == (WCHAR)L'-' || + *iter == (WCHAR)L' ' || + *iter == (WCHAR)L'0' || + *iter == (WCHAR)L'*' || + *iter == (WCHAR)L'#') + { + if (*iter == (WCHAR)L'*') + { + char *buffiter = bufa; + int fieldlen = va_arg(valist, int); + sprintf(buffiter, "%d", fieldlen); + while (*buffiter) + *fmta++ = *buffiter++; + } + else + *fmta++ = *iter; + iter++; + } + + while (isdigit(*iter)) + *fmta++ = *iter++; + + if (*iter == (WCHAR)L'.') + { + *fmta++ = *iter++; + if (*iter == (WCHAR)L'*') + { + char *buffiter = bufa; + int fieldlen = va_arg(valist, int); + sprintf(buffiter, "%d", fieldlen); + while (*buffiter) + *fmta++ = *buffiter++; + } + else + while (isdigit(*iter)) + *fmta++ = *iter++; + } + if (*iter == (WCHAR)L'h' || + *iter == (WCHAR)L'l') + { + *fmta++ = *iter++; + *fmta++ = *iter++; + } + + switch (*iter) + { + case (WCHAR)L's': + { + static const WCHAR none[] = { '(', 'n', 'u', 'l', 'l', ')', 0 }; + const WCHAR *wstr = va_arg(valist, const WCHAR *); + const WCHAR *striter = wstr ? wstr : none; + while (*striter) + { + if (written++ >= len) + return -1; + *str++ = *striter++; + } + iter++; + break; + } + + case (WCHAR)L'c': + if (written++ >= len) + return -1; + *str++ = va_arg(valist, WCHAR); + iter++; + break; + + default: + { + /* For non wc types, use system sprintf and append to wide char output */ + /* FIXME: for unrecognised types, should ignore % when printing */ + char *bufaiter = bufa; + if (*iter == (WCHAR)L'p') + sprintf(bufaiter, "%08lX", va_arg(valist, long)); + else + { + *fmta++ = *iter; + *fmta = '\0'; + sprintf(bufaiter, fmtbufa, va_arg(valist, void *)); + } + while (*bufaiter) + { + if (written++ >= len) + return -1; + *str++ = *bufaiter++; + } + iter++; + break; + } + } + } + } + if (written >= len) + return -1; + *str++ = (WCHAR)L'\0'; + return (int)written; +} + + +/*********************************************************************** + * _snwprintf (NTDLL) + */ +int __cdecl _snwprintf(WCHAR *str, unsigned int len, const WCHAR *format, ...) +{ + int retval; + va_list valist; + va_start(valist, format); + retval = NTDLL_vsnwprintf(str, len, format, valist); + va_end(valist); + return retval; +} + + +/*********************************************************************** + * NTDLL_swprintf (NTDLL) + */ +int __cdecl NTDLL_swprintf(WCHAR *str, const WCHAR *format, ...) +{ + int retval; + va_list valist; + va_start(valist, format); + retval = NTDLL_vsnwprintf(str, INT_MAX, format, valist); + va_end(valist); + return retval; +} diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c index fbc9cc99272..0be5020ea4c 100644 --- a/dlls/opengl32/wgl.c +++ b/dlls/opengl32/wgl.c @@ -4,6 +4,7 @@ */ #include +#include #include "wine/exception.h" diff --git a/dlls/setupapi/setupx_main.c b/dlls/setupapi/setupx_main.c index cdab986f804..e0ef93aa48e 100644 --- a/dlls/setupapi/setupx_main.c +++ b/dlls/setupapi/setupx_main.c @@ -43,6 +43,7 @@ #include #include +#include #include "winreg.h" #include "wine/winuser16.h" #include "setupx16.h" diff --git a/dlls/user/lstr.c b/dlls/user/lstr.c index 1fc3c6b2def..996e80ba9be 100644 --- a/dlls/user/lstr.c +++ b/dlls/user/lstr.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "windef.h" #include "winbase.h" diff --git a/dlls/user/user_main.c b/dlls/user/user_main.c index 36a909d3414..52c094da9c0 100644 --- a/dlls/user/user_main.c +++ b/dlls/user/user_main.c @@ -2,6 +2,7 @@ * USER initialization code */ +#include #include "windef.h" #include "winbase.h" #include "wingdi.h" diff --git a/dlls/winaspi/aspi.c b/dlls/winaspi/aspi.c index 75dfd441357..29b930d11e9 100644 --- a/dlls/winaspi/aspi.c +++ b/dlls/winaspi/aspi.c @@ -31,6 +31,7 @@ HKEY_DYN_DATA #include #include #include +#include #include "debugtools.h" #include "winreg.h" diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index a3bac3ada2c..76ed99a2eb6 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "internet.h" diff --git a/dlls/wsock32/protocol.c b/dlls/wsock32/protocol.c index 92f2aae3b15..8432bffa87f 100644 --- a/dlls/wsock32/protocol.c +++ b/dlls/wsock32/protocol.c @@ -7,6 +7,7 @@ #include "config.h" #include +#include #include "winbase.h" #include "debugtools.h" #include "heap.h" diff --git a/include/winnt.h b/include/winnt.h index 9aba207996d..68b14c1e210 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -11,7 +11,6 @@ #ifndef RC_INVOKED #include -#include #include #endif diff --git a/loader/pe_image.c b/loader/pe_image.c index c511e97af8e..28d04666418 100644 --- a/loader/pe_image.c +++ b/loader/pe_image.c @@ -29,6 +29,7 @@ #ifdef HAVE_SYS_MMAN_H #include #endif +#include #include "wine/winbase16.h" #include "winerror.h" #include "snoop.h" diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index d25e46c9eed..7b9d58120bf 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "config.h" #include "winnt.h" diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c index e00ea2ea16f..b9d4e3cbf1d 100644 --- a/tools/winebuild/main.c +++ b/tools/winebuild/main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "config.h" #include "winnt.h"