Implementing wtmpnam in msvcrt

Tim Holy holy at wustl.edu
Sat Nov 29 08:47:09 CST 2008


Hello,

I'm trying to implement the "stub" function wtmpnam in msvcrt. Below is a 
patch at an attempt; there are a number of questions I have about the right 
way to implement it, and since I don't know the Wine codebase I thought 
perhaps readers of this list might (with minimal effort) be able to point me in 
the right direction.

Below is the text of the patch (it's short). My questions are embedded after 
//-style comments (4 in total).

Many thanks in advance for your help!
--Tim

diff -U 3 -r winecopy/wine-1.1.8/dlls/msvcrt/file.c wine-1.1.8/dlls/msvcrt/file.c
--- winecopy/wine-1.1.8/dlls/msvcrt/file.c	2008-11-07 10:09:33.000000000 
-0600
+++ wine-1.1.8/dlls/msvcrt/file.c	2008-11-29 07:32:43.000000000 -0600
@@ -88,6 +88,7 @@
 
 /* INTERNAL: Static buffer for temp file name */
 static char MSVCRT_tmpname[MAX_PATH];
+static MSVCRT_wchar_t MSVCRT_wtmpname[MAX_PATH];
 
 static const unsigned int EXE = 'e' << 16 | 'x' << 8 | 'e';
 static const unsigned int BAT = 'b' << 16 | 'a' << 8 | 't';
@@ -2990,6 +2991,32 @@
 }
 
 /*********************************************************************
+ *		wtmpnam (MSVCRT.@)
+ */
+MSVCRT_wchar_t * CDECL MSVCRT_wtmpnam(MSVCRT_wchar_t *s)
+{
+  static int unique;
+  char tmpstr[16];
+  MSVCRT_wchar_t wtmpstr[16];
+  MSVCRT_wchar_t *p;
+  int count;
+  if (s == 0)
+    s = MSVCRT_wtmpname;
+  msvcrt_int_to_base32(GetCurrentProcessId(), tmpstr);
+  p = s + MSVCRT_swprintf(s, "\\s%s.", tmpstr);  // "implicit declaration" 
error, function is defined in wcs (but no wcs.h); but how to convert format 
string to MSVCRT_wchar_t?
+  for (count = 0; count < MSVCRT_TMP_MAX; count++)
+  {
+    msvcrt_int_to_base32(unique++, tmpstr);
+    mbstowcs(wtmpstr,tmpstr,strlen(tmpstr));  // need a MSVCRT_wchar 
version
+    wcscpy(p, wtmpstr);    // need a MSVCRT_wchar version
+    if (GetFileAttributesW(s) == INVALID_FILE_ATTRIBUTES &&
+        GetLastError() == ERROR_FILE_NOT_FOUND)
+      break;
+  }
+  return s;
+}
+
+/*********************************************************************
  *		tmpfile (MSVCRT.@)
  */
 MSVCRT_FILE* CDECL MSVCRT_tmpfile(void)
diff -U 3 -r winecopy/wine-1.1.8/dlls/msvcrt/msvcrt.spec 
wine-1.1.8/dlls/msvcrt/msvcrt.spec
--- winecopy/wine-1.1.8/dlls/msvcrt/msvcrt.spec	2008-11-07 
10:09:33.000000000 -0600
+++ wine-1.1.8/dlls/msvcrt/msvcrt.spec	2008-11-29 07:12:10.000000000 
-0600
@@ -579,7 +579,7 @@
 @ cdecl _wstrtime(ptr)
 @ cdecl _wsystem(wstr)
 @ cdecl _wtempnam(wstr wstr)
-@ stub _wtmpnam #(ptr)
+@ cdecl wtmpnam(ptr) MSVCRT_wtmpnam  // needs an underscore?
 @ cdecl _wtoi(wstr) ntdll._wtoi
 @ cdecl _wtoi64(wstr) ntdll._wtoi64
 @ cdecl _wtol(wstr) ntdll._wtol




More information about the wine-devel mailing list