Alexandre Julliard : server: Add a helper function for creating a Unicode string.

Alexandre Julliard julliard at winehq.org
Tue Mar 24 15:28:16 CDT 2020


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Mar 24 12:47:44 2020 +0100

server: Add a helper function for creating a Unicode string.

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

---

 server/directory.c | 10 +++++-----
 server/registry.c  | 25 ++++++++-----------------
 server/unicode.c   | 11 +++++++++++
 server/unicode.h   |  7 +------
 4 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/server/directory.c b/server/directory.c
index 8ee9a97a99..30cdd79b4a 100644
--- a/server/directory.c
+++ b/server/directory.c
@@ -270,12 +270,12 @@ static void create_session( unsigned int id )
     static const struct unicode_str link_local_str = {link_localW, sizeof(link_localW)};
     static const struct unicode_str link_session_str = {link_sessionW, sizeof(link_sessionW)};
 
-    static const WCHAR fmt_u[] = {'%','u',0};
     static struct directory *dir_bno_global, *dir_sessions, *dir_bnolinks;
     struct directory *dir_id, *dir_bno, *dir_dosdevices, *dir_windows, *dir_winstation;
     struct object *link_global, *link_local, *link_session, *link_bno, *link_windows;
     struct unicode_str id_str;
-    WCHAR id_strW[10];
+    char id_strA[10];
+    WCHAR *id_strW;
 
     if (!id)
     {
@@ -287,9 +287,8 @@ static void create_session( unsigned int id )
         make_object_static( (struct object *)dir_sessions );
     }
 
-    sprintfW( id_strW, fmt_u, id );
-    id_str.str = id_strW;
-    id_str.len = strlenW( id_strW ) * sizeof(WCHAR);
+    sprintf( id_strA, "%u", id );
+    id_strW = ascii_to_unicode_str( id_strA, &id_str );
     dir_id = create_directory( &dir_sessions->obj, &id_str, 0, HASH_SIZE, NULL );
     dir_dosdevices = create_directory( &dir_id->obj, &dir_dosdevices_str, 0, HASH_SIZE, NULL );
 
@@ -325,6 +324,7 @@ static void create_session( unsigned int id )
     release_object( dir_windows );
     release_object( dir_bno );
     release_object( dir_id );
+    free( id_strW );
 }
 
 void init_directories(void)
diff --git a/server/registry.c b/server/registry.c
index bb65bb4818..54a6d6918b 100644
--- a/server/registry.c
+++ b/server/registry.c
@@ -1740,25 +1740,16 @@ static int load_init_registry_from_file( const char *filename, struct key *key )
 
 static WCHAR *format_user_registry_path( const SID *sid, struct unicode_str *path )
 {
-    static const WCHAR prefixW[] = {'U','s','e','r','\\','S',0};
-    static const WCHAR formatW[] = {'-','%','u',0};
-    WCHAR buffer[7 + 10 + 10 + 10 * SID_MAX_SUB_AUTHORITIES];
-    WCHAR *p = buffer;
+    char buffer[7 + 11 + 11 + 11 * SID_MAX_SUB_AUTHORITIES], *p = buffer;
     unsigned int i;
 
-    strcpyW( p, prefixW );
-    p += strlenW( prefixW );
-    p += sprintfW( p, formatW, sid->Revision );
-    p += sprintfW( p, formatW, MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5],
-                                                   sid->IdentifierAuthority.Value[4] ),
-                                         MAKEWORD( sid->IdentifierAuthority.Value[3],
-                                                   sid->IdentifierAuthority.Value[2] )));
-    for (i = 0; i < sid->SubAuthorityCount; i++)
-        p += sprintfW( p, formatW, sid->SubAuthority[i] );
-
-    path->len = (p - buffer) * sizeof(WCHAR);
-    path->str = p = memdup( buffer, path->len );
-    return p;
+    p += sprintf( p, "User\\S-%u-%u", sid->Revision,
+                  MAKELONG( MAKEWORD( sid->IdentifierAuthority.Value[5],
+                                      sid->IdentifierAuthority.Value[4] ),
+                            MAKEWORD( sid->IdentifierAuthority.Value[3],
+                                      sid->IdentifierAuthority.Value[2] )));
+    for (i = 0; i < sid->SubAuthorityCount; i++) p += sprintf( p, "-%u", sid->SubAuthority[i] );
+    return ascii_to_unicode_str( buffer, path );
 }
 
 /* get the cpu architectures that can be supported in the current prefix */
diff --git a/server/unicode.c b/server/unicode.c
index 02233e22cf..f77aa95ff2 100644
--- a/server/unicode.c
+++ b/server/unicode.c
@@ -51,6 +51,17 @@ static inline char to_hex( char ch )
     return tolower(ch) - 'a' + 10;
 }
 
+WCHAR *ascii_to_unicode_str( const char *str, struct unicode_str *ret )
+{
+    data_size_t i, len = strlen(str);
+    WCHAR *p;
+
+    ret->len = len * sizeof(WCHAR);
+    ret->str = p = mem_alloc( ret->len );
+    if (p) for (i = 0; i < len; i++) p[i] = (unsigned char)str[i];
+    return p;
+}
+
 /* parse an escaped string back into Unicode */
 /* return the number of chars read from the input, or -1 on output overflow */
 int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar )
diff --git a/server/unicode.h b/server/unicode.h
index dd922db020..b69557363f 100644
--- a/server/unicode.h
+++ b/server/unicode.h
@@ -27,12 +27,7 @@
 #include "wine/unicode.h"
 #include "object.h"
 
-static inline WCHAR *strdupW( const WCHAR *str )
-{
-    size_t len = (strlenW(str) + 1) * sizeof(WCHAR);
-    return memdup( str, len );
-}
-
+extern WCHAR *ascii_to_unicode_str( const char *str, struct unicode_str *ret );
 extern int parse_strW( WCHAR *buffer, data_size_t *len, const char *src, char endchar );
 extern int dump_strW( const WCHAR *str, data_size_t len, FILE *f, const char escape[2] );
 




More information about the wine-cvs mailing list