Alexandre Julliard : ntdll: Add _wmakepath_s.

Alexandre Julliard julliard at winehq.org
Thu Jun 30 16:34:20 CDT 2022


Module: wine
Branch: master
Commit: 0c986b2c778022a8c271471b89bd0ff9a3ff7a41
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0c986b2c778022a8c271471b89bd0ff9a3ff7a41

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Jun 30 11:07:04 2022 +0200

ntdll: Add _wmakepath_s.

Implementation copied from msvcrt.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/ntdll.spec |  1 +
 dlls/ntdll/wcstring.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index ffc3cb00fcd..cc78f4539f3 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1555,6 +1555,7 @@
 @ cdecl -ret64 _wcstoui64(wstr ptr long)
 @ cdecl _wcsupr(wstr)
 @ cdecl _wcsupr_s(wstr long)
+@ cdecl _wmakepath_s(ptr long wstr wstr wstr wstr)
 @ cdecl _wsplitpath_s(wstr ptr long ptr long ptr long ptr long)
 @ cdecl _wtoi(wstr)
 @ cdecl -ret64 _wtoi64(wstr)
diff --git a/dlls/ntdll/wcstring.c b/dlls/ntdll/wcstring.c
index 76190c08c12..aa43c3de16b 100644
--- a/dlls/ntdll/wcstring.c
+++ b/dlls/ntdll/wcstring.c
@@ -1375,3 +1375,80 @@ error:
     if (ext) ext[0]= 0;
     return ERANGE;
 }
+
+
+/*********************************************************************
+ *      _wmakepath_s   (NTDLL.@)
+ */
+errno_t __cdecl _wmakepath_s( wchar_t *path, size_t size, const wchar_t *drive,
+                              const wchar_t *directory, const wchar_t *filename,
+                              const wchar_t *extension )
+{
+    wchar_t *p = path;
+
+    if (!path || !size) return EINVAL;
+
+    if (drive && drive[0])
+    {
+        if (size <= 2) goto range;
+        *p++ = drive[0];
+        *p++ = ':';
+        size -= 2;
+    }
+
+    if (directory && directory[0])
+    {
+        unsigned int len = wcslen(directory);
+        unsigned int needs_separator = directory[len - 1] != '/' && directory[len - 1] != '\\';
+        unsigned int copylen = min(size - 1, len);
+
+        if (size < 2) goto range;
+        memmove(p, directory, copylen * sizeof(wchar_t));
+        if (size <= len) goto range;
+        p += copylen;
+        size -= copylen;
+        if (needs_separator)
+        {
+            if (size < 2) goto range;
+            *p++ = '\\';
+            size -= 1;
+        }
+    }
+
+    if (filename && filename[0])
+    {
+        unsigned int len = wcslen(filename);
+        unsigned int copylen = min(size - 1, len);
+
+        if (size < 2) goto range;
+        memmove(p, filename, copylen * sizeof(wchar_t));
+        if (size <= len) goto range;
+        p += len;
+        size -= len;
+    }
+
+    if (extension && extension[0])
+    {
+        unsigned int len = wcslen(extension);
+        unsigned int needs_period = extension[0] != '.';
+        unsigned int copylen;
+
+        if (size < 2) goto range;
+        if (needs_period)
+        {
+            *p++ = '.';
+            size -= 1;
+        }
+        copylen = min(size - 1, len);
+        memcpy(p, extension, copylen * sizeof(wchar_t));
+        if (size <= len) goto range;
+        p += copylen;
+    }
+
+    *p = 0;
+    return 0;
+
+range:
+    path[0] = 0;
+    return ERANGE;
+}




More information about the wine-cvs mailing list