diff --git a/configure b/configure
index 58c7778a640aff9820430b5f4d9993a4fd4536ec..f6bbde77b311b08ea20d4ee726fd0c78a65c2983 100755
--- a/configure
+++ b/configure
@@ -16276,6 +16276,7 @@ fi
 
 
 
+
 
 
 for ac_func in \
@@ -16308,6 +16309,7 @@ for ac_func in \
 	getservbyport \
 	gettid \
 	gettimeofday \
+	getuid \
 	inet_network \
 	lseek64 \
 	lstat \
diff --git a/configure.ac b/configure.ac
index f57925136cba313c8ca7cb77f308fbd4c867f3b7..b08512e4267193adbd02f21de4eacc681e54c809 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1083,6 +1083,7 @@ AC_CHECK_FUNCS(\
 	getservbyport \
 	gettid \
 	gettimeofday \
+	getuid \
 	inet_network \
 	lseek64 \
 	lstat \
diff --git a/include/config.h.in b/include/config.h.in
index 1a590869f2cdf08b99f69ff83ee14b738224a500..c7911210d483b1f762ad0294909afa671f770b65 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -191,6 +191,9 @@
 /* Define to 1 if you have the `gettimeofday' function. */
 #undef HAVE_GETTIMEOFDAY
 
+/* Define to 1 if you have the `getuid' function. */
+#undef HAVE_GETUID
+
 /* Define to 1 if you have the <gif_lib.h> header file. */
 #undef HAVE_GIF_LIB_H
 
diff --git a/libs/wine/config.c b/libs/wine/config.c
index 72990332e1d400382ae26080ba68f9581100fe75..ebe41080bd087c045139e7d10fdef33b4382def4 100644
--- a/libs/wine/config.c
+++ b/libs/wine/config.c
@@ -105,10 +105,15 @@ inline static void remove_trailing_slashes( char *path )
 static void init_server_dir( dev_t dev, ino_t ino )
 {
     char *p;
+#ifdef HAVE_GETUID
+    const unsigned int uid = getuid();
+#else
+    const unsigned int uid = 0;
+#endif
 
     server_dir = xmalloc( sizeof(server_root_prefix) + 32 + sizeof(server_dir_prefix) +
                           2*sizeof(dev) + 2*sizeof(ino) );
-    sprintf( server_dir, "%s%u%s", server_root_prefix, getuid(), server_dir_prefix );
+    sprintf( server_dir, "%s%u%s", server_root_prefix, uid, server_dir_prefix );
     p = server_dir + strlen(server_dir);
 
     if (sizeof(dev) > sizeof(unsigned long) && dev > ~0UL)