From 3b2019badb1a8636425dfd0292bfe70d0ba58699 Mon Sep 17 00:00:00 2001
From: Mike McCormack <mike@codeweavers.com>
Date: Tue, 22 Feb 2005 15:50:13 +0000
Subject: [PATCH] Make lstr* functions inline inside Wine.

---
 dlls/kernel/string.c      |  1 +
 dlls/shell32/shell32.spec |  4 +-
 include/winbase.h         | 84 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel/string.c b/dlls/kernel/string.c
index d5ffb901617..61d8ac04146 100644
--- a/dlls/kernel/string.c
+++ b/dlls/kernel/string.c
@@ -27,6 +27,7 @@
 #include <stdarg.h>
 #include <string.h>
 
+#define WINE_NO_INLINE_STRING
 #include "windef.h"
 #include "winbase.h"
 #include "excpt.h"
diff --git a/dlls/shell32/shell32.spec b/dlls/shell32/shell32.spec
index e3f3eaf2508..98d9af29aa5 100644
--- a/dlls/shell32/shell32.spec
+++ b/dlls/shell32/shell32.spec
@@ -252,13 +252,13 @@
  306 stdcall StrCmpNIA(str str long) shlwapi.StrCmpNIA
  307 stdcall StrCmpNIW(wstr wstr long) shlwapi.StrCmpNIW
  308 stdcall StrCmpNW(wstr wstr long) shlwapi.StrCmpNW
- 309 stdcall StrCpyNA (ptr str long) lstrcpynA
+ 309 stdcall StrCpyNA (ptr str long) kernel32.lstrcpynA
  310 stdcall StrCpyNW(wstr wstr long) shlwapi.StrCpyNW
  311 stdcall StrNCmpA(str str long) shlwapi.StrCmpNA
  312 stdcall StrNCmpIA(str str long) shlwapi.StrCmpNIA
  313 stdcall StrNCmpIW(wstr wstr long) shlwapi.StrCmpNIW
  314 stdcall StrNCmpW(wstr wstr long) shlwapi.StrCmpNW
- 315 stdcall StrNCpyA (ptr str long) lstrcpynA
+ 315 stdcall StrNCpyA (ptr str long) kernel32.lstrcpynA
  316 stdcall StrNCpyW(wstr wstr long) shlwapi.StrCpyNW
  317 stdcall StrRChrA(str str long) shlwapi.StrRChrA
  318 stdcall StrRChrIA(str str long) shlwapi.StrRChrIA
diff --git a/include/winbase.h b/include/winbase.h
index 005ca0e11a9..df82d1972b0 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -1966,18 +1966,96 @@ BOOL        WINAPI WriteProfileStringA(LPCSTR,LPCSTR,LPCSTR);
 BOOL        WINAPI WriteProfileStringW(LPCWSTR,LPCWSTR,LPCWSTR);
 #define     WriteProfileString WINELIB_NAME_AW(WriteProfileString)
 #define     Yield()
+
+#if defined(WINE_NO_INLINE_STRING) || !defined(__WINESRC__)
+
 LPSTR       WINAPI lstrcatA(LPSTR,LPCSTR);
 LPWSTR      WINAPI lstrcatW(LPWSTR,LPCWSTR);
-#define     lstrcat WINELIB_NAME_AW(lstrcat)
 LPSTR       WINAPI lstrcpyA(LPSTR,LPCSTR);
 LPWSTR      WINAPI lstrcpyW(LPWSTR,LPCWSTR);
-#define     lstrcpy WINELIB_NAME_AW(lstrcpy)
 LPSTR       WINAPI lstrcpynA(LPSTR,LPCSTR,INT);
 LPWSTR      WINAPI lstrcpynW(LPWSTR,LPCWSTR,INT);
-#define     lstrcpyn WINELIB_NAME_AW(lstrcpyn)
 INT         WINAPI lstrlenA(LPCSTR);
 INT         WINAPI lstrlenW(LPCWSTR);
+
+#else /* !defined(WINE_NO_INLINE_STRING) && defined(__WINESRC__) */
+
+/* string functions without the exception handler */
+
+extern inline LPWSTR lstrcpynW( LPWSTR dst, LPCWSTR src, INT n )
+{
+    LPWSTR d = dst;
+    LPCWSTR s = src;
+    UINT count = n;
+
+    while ((count > 1) && *s)
+    {
+        count--;
+        *d++ = *s++;
+    }
+    if (count) *d = 0;
+    return dst;
+}
+
+extern inline LPSTR lstrcpynA( LPSTR dst, LPCSTR src, INT n )
+{
+    LPSTR d = dst;
+    LPCSTR s = src;
+    UINT count = n;
+
+    while ((count > 1) && *s)
+    {
+        count--;
+        *d++ = *s++;
+    }
+    if (count) *d = 0;
+    return dst;
+}
+
+extern inline INT lstrlenW( LPCWSTR str )
+{
+    const WCHAR *s = str;
+    while (*s) s++;
+    return s - str;
+}
+
+extern inline INT lstrlenA( LPCSTR str )
+{
+    return strlen( str );
+}
+
+extern inline LPWSTR lstrcpyW( LPWSTR dst, LPCWSTR src )
+{
+    WCHAR *p = dst;
+    while ((*p++ = *src++));
+    return dst;
+}
+
+extern inline LPSTR lstrcpyA( LPSTR dst, LPCSTR src )
+{
+    return strcpy( dst, src );
+}
+
+extern inline LPWSTR lstrcatW( LPWSTR dst, LPCWSTR src )
+{
+    WCHAR *p = dst;
+    while (*p) p++;
+    while ((*p++ = *src++));
+    return dst;
+}
+
+extern inline LPSTR lstrcatA( LPSTR dst, LPCSTR src )
+{
+    return strcat( dst, src );
+}
+
+#endif /* !defined(WINE_NO_INLINE_STRING) && defined(__WINESRC__) */
+
+#define     lstrcat WINELIB_NAME_AW(lstrcat)
+#define     lstrcpy WINELIB_NAME_AW(lstrcpy)
+#define     lstrcpyn WINELIB_NAME_AW(lstrcpyn)
 #define     lstrlen WINELIB_NAME_AW(lstrlen)
+
 LONG        WINAPI _hread(HFILE,LPVOID,LONG);
 LONG        WINAPI _hwrite(HFILE,LPCSTR,LONG);
 HFILE       WINAPI _lcreat(LPCSTR,INT);
-- 
GitLab