The format rect is recalculated for each font change. MoveEnd &
[wine] / files / directory.c
1 /*
2  * DOS directories functions
3  *
4  * Copyright 1995 Alexandre Julliard
5  */
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #ifdef HAVE_SYS_ERRNO_H
15 #include <sys/errno.h>
16 #endif
17
18 #include "winbase.h"
19 #include "wine/winbase16.h"
20 #include "wine/winestring.h"
21 #include "wine/winuser16.h"
22 #include "winerror.h"
23 #include "process.h"
24 #include "drive.h"
25 #include "file.h"
26 #include "heap.h"
27 #include "msdos.h"
28 #include "options.h"
29 #include "debugtools.h"
30
31 DECLARE_DEBUG_CHANNEL(dosfs)
32 DECLARE_DEBUG_CHANNEL(file)
33
34 static DOS_FULL_NAME DIR_Windows;
35 static DOS_FULL_NAME DIR_System;
36
37
38 /***********************************************************************
39  *           DIR_GetPath
40  *
41  * Get a path name from the wine.ini file and make sure it is valid.
42  */
43 static int DIR_GetPath( const char *keyname, const char *defval,
44                         DOS_FULL_NAME *full_name )
45 {
46     char path[MAX_PATHNAME_LEN];
47     BY_HANDLE_FILE_INFORMATION info;
48
49     PROFILE_GetWineIniString( "wine", keyname, defval, path, sizeof(path) );
50     if (!DOSFS_GetFullName( path, TRUE, full_name ) ||
51         !FILE_Stat( full_name->long_name, &info ) ||
52         !(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
53     {
54         MESSAGE("Invalid path '%s' for %s directory\n", path, keyname);
55         return 0;
56     }
57     return 1;
58 }
59
60
61 /***********************************************************************
62  *           DIR_Init
63  */
64 int DIR_Init(void)
65 {
66     char path[MAX_PATHNAME_LEN];
67     DOS_FULL_NAME tmp_dir;
68     int drive;
69     const char *cwd;
70
71     if (!getcwd( path, MAX_PATHNAME_LEN ))
72     {
73         perror( "Could not get current directory" );
74         return 0;
75     }
76     cwd = path;
77     if ((drive = DRIVE_FindDriveRoot( &cwd )) == -1)
78     {
79         MESSAGE("Warning: could not find wine.conf [Drive x] entry "
80             "for current working directory %s; "
81             "starting in windows directory.\n", cwd );
82     }
83     else
84     {
85         DRIVE_SetCurrentDrive( drive );
86         DRIVE_Chdir( drive, cwd );
87     }
88
89     if (!(DIR_GetPath( "windows", "c:\\windows", &DIR_Windows )) ||
90         !(DIR_GetPath( "system", "c:\\windows\\system", &DIR_System )) ||
91         !(DIR_GetPath( "temp", "c:\\windows", &tmp_dir )))
92     {
93         PROFILE_UsageWineIni();
94         return 0;
95     }
96     if (-1 == access( tmp_dir.long_name, W_OK ))
97     {
98         if (errno==EACCES)
99         {
100                 MESSAGE("Warning: The Temporary Directory (as specified in your configuration file) is NOT writeable.\n");
101                 PROFILE_UsageWineIni();
102         }
103         else
104                 MESSAGE("Warning: Access to Temporary Directory failed (%s).\n",
105                     strerror(errno));
106     }
107
108     if (drive == -1)
109     {
110         drive = DIR_Windows.drive;
111         DRIVE_SetCurrentDrive( drive );
112         DRIVE_Chdir( drive, DIR_Windows.short_name + 2 );
113     }
114
115     PROFILE_GetWineIniString("wine", "path", "c:\\windows;c:\\windows\\system",
116                              path, sizeof(path) );
117
118     /* Set the environment variables */
119
120     SetEnvironmentVariableA( "PATH", path );
121     SetEnvironmentVariableA( "COMSPEC", "c:\\command.com" );
122     SetEnvironmentVariableA( "TEMP", tmp_dir.short_name );
123     SetEnvironmentVariableA( "windir", DIR_Windows.short_name );
124     SetEnvironmentVariableA( "winsysdir", DIR_System.short_name );
125
126     TRACE_(dosfs)("WindowsDir = %s (%s)\n",
127           DIR_Windows.short_name, DIR_Windows.long_name );
128     TRACE_(dosfs)("SystemDir  = %s (%s)\n",
129           DIR_System.short_name, DIR_System.long_name );
130     TRACE_(dosfs)("TempDir    = %s (%s)\n",
131           tmp_dir.short_name, tmp_dir.long_name );
132     TRACE_(dosfs)("Path       = %s\n", path );
133     TRACE_(dosfs)("Cwd        = %c:\\%s\n",
134           'A' + drive, DRIVE_GetDosCwd( drive ) );
135
136     return 1;
137 }
138
139
140 /***********************************************************************
141  *           GetTempPath32A   (KERNEL32.292)
142  */
143 UINT WINAPI GetTempPathA( UINT count, LPSTR path )
144 {
145     UINT ret;
146     if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
147         if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
148             if (!(ret = GetCurrentDirectoryA( count, path )))
149                 return 0;
150     if (count && (ret < count - 1) && (path[ret-1] != '\\'))
151     {
152         path[ret++] = '\\';
153         path[ret]   = '\0';
154     }
155     return ret;
156 }
157
158
159 /***********************************************************************
160  *           GetTempPath32W   (KERNEL32.293)
161  */
162 UINT WINAPI GetTempPathW( UINT count, LPWSTR path )
163 {
164     static const WCHAR tmp[]  = { 'T', 'M', 'P', 0 };
165     static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
166     UINT ret;
167     if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
168         if (!(ret = GetEnvironmentVariableW( temp, path, count )))
169             if (!(ret = GetCurrentDirectoryW( count, path )))
170                 return 0;
171     if (count && (ret < count - 1) && (path[ret-1] != '\\'))
172     {
173         path[ret++] = '\\';
174         path[ret]   = '\0';
175     }
176     return ret;
177 }
178
179
180 /***********************************************************************
181  *           DIR_GetWindowsUnixDir
182  */
183 UINT DIR_GetWindowsUnixDir( LPSTR path, UINT count )
184 {
185     if (path) lstrcpynA( path, DIR_Windows.long_name, count );
186     return strlen( DIR_Windows.long_name );
187 }
188
189
190 /***********************************************************************
191  *           DIR_GetSystemUnixDir
192  */
193 UINT DIR_GetSystemUnixDir( LPSTR path, UINT count )
194 {
195     if (path) lstrcpynA( path, DIR_System.long_name, count );
196     return strlen( DIR_System.long_name );
197 }
198
199
200 /***********************************************************************
201  *           GetTempDrive   (KERNEL.92)
202  */
203 BYTE WINAPI GetTempDrive( BYTE ignored )
204 {
205     char *buffer;
206     BYTE ret;
207     UINT len = GetTempPathA( 0, NULL );
208
209     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 )) )
210       return DRIVE_GetCurrentDrive() + 'A';
211
212     /* FIXME: apparently Windows does something with the ignored byte */
213     if (!GetTempPathA( len, buffer )) buffer[0] = 'C';
214     ret = buffer[0];
215     HeapFree( GetProcessHeap(), 0, buffer );
216     return toupper(ret);
217 }
218
219
220 UINT WINAPI WIN16_GetTempDrive( BYTE ignored )
221 {
222     /* A closer look at krnl386.exe shows what the SDK doesn't mention:
223      *
224      * returns:
225      *   AL: driveletter
226      *   AH: ':'                - yes, some kernel code even does stosw with
227      *                            the returned AX.
228      *   DX: 1 for success
229      */
230     return MAKELONG( GetTempDrive(ignored) | (':' << 8), 1 );
231 }
232
233
234 /***********************************************************************
235  *           GetWindowsDirectory16   (KERNEL.134)
236  */
237 UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
238 {
239     return (UINT16)GetWindowsDirectoryA( path, count );
240 }
241
242
243 /***********************************************************************
244  *           GetWindowsDirectory32A   (KERNEL32.311)
245  */
246 UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
247 {
248     if (path) lstrcpynA( path, DIR_Windows.short_name, count );
249     return strlen( DIR_Windows.short_name );
250 }
251
252
253 /***********************************************************************
254  *           GetWindowsDirectory32W   (KERNEL32.312)
255  */
256 UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
257 {
258     if (path) lstrcpynAtoW( path, DIR_Windows.short_name, count );
259     return strlen( DIR_Windows.short_name );
260 }
261
262
263 /***********************************************************************
264  *           GetSystemDirectory16   (KERNEL.135)
265  */
266 UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
267 {
268     return (UINT16)GetSystemDirectoryA( path, count );
269 }
270
271
272 /***********************************************************************
273  *           GetSystemDirectory32A   (KERNEL32.282)
274  */
275 UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
276 {
277     if (path) lstrcpynA( path, DIR_System.short_name, count );
278     return strlen( DIR_System.short_name );
279 }
280
281
282 /***********************************************************************
283  *           GetSystemDirectory32W   (KERNEL32.283)
284  */
285 UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
286 {
287     if (path) lstrcpynAtoW( path, DIR_System.short_name, count );
288     return strlen( DIR_System.short_name );
289 }
290
291
292 /***********************************************************************
293  *           CreateDirectory16   (KERNEL.144)
294  */
295 BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
296 {
297     TRACE_(file)("(%s,%p)\n", path, dummy );
298     return (BOOL16)CreateDirectoryA( path, NULL );
299 }
300
301
302 /***********************************************************************
303  *           CreateDirectory32A   (KERNEL32.39)
304  * RETURNS:
305  *      TRUE : success
306  *      FALSE : failure
307  *              ERROR_DISK_FULL:        on full disk
308  *              ERROR_ALREADY_EXISTS:   if directory name exists (even as file)
309  *              ERROR_ACCESS_DENIED:    on permission problems
310  *              ERROR_FILENAME_EXCED_RANGE: too long filename(s)
311  */
312 BOOL WINAPI CreateDirectoryA( LPCSTR path,
313                                   LPSECURITY_ATTRIBUTES lpsecattribs )
314 {
315     DOS_FULL_NAME full_name;
316
317     TRACE_(file)("(%s,%p)\n", path, lpsecattribs );
318     if (DOSFS_GetDevice( path ))
319     {
320         TRACE_(file)("cannot use device '%s'!\n",path);
321         SetLastError( ERROR_ACCESS_DENIED );
322         return FALSE;
323     }
324     if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0;
325     if (mkdir( full_name.long_name, 0777 ) == -1) {
326         WARN_(file)("Errno %i trying to create directory %s.\n", errno, full_name.long_name);
327         /* the FILE_SetDosError() generated error codes don't match the 
328          * CreateDirectory ones for some errnos */
329         switch (errno) {
330         case EEXIST: SetLastError(ERROR_ALREADY_EXISTS); break;
331         case ENOSPC: SetLastError(ERROR_DISK_FULL); break;
332         default: FILE_SetDosError();break;
333         }
334         return FALSE;
335     }
336     return TRUE;
337 }
338
339
340 /***********************************************************************
341  *           CreateDirectory32W   (KERNEL32.42)
342  */
343 BOOL WINAPI CreateDirectoryW( LPCWSTR path,
344                                   LPSECURITY_ATTRIBUTES lpsecattribs )
345 {
346     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
347     BOOL ret = CreateDirectoryA( xpath, lpsecattribs );
348     HeapFree( GetProcessHeap(), 0, xpath );
349     return ret;
350 }
351
352
353 /***********************************************************************
354  *           CreateDirectoryEx32A   (KERNEL32.40)
355  */
356 BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path,
357                                     LPSECURITY_ATTRIBUTES lpsecattribs)
358 {
359     return CreateDirectoryA(path,lpsecattribs);
360 }
361
362
363 /***********************************************************************
364  *           CreateDirectoryEx32W   (KERNEL32.41)
365  */
366 BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path,
367                                     LPSECURITY_ATTRIBUTES lpsecattribs)
368 {
369     return CreateDirectoryW(path,lpsecattribs);
370 }
371
372
373 /***********************************************************************
374  *           RemoveDirectory16   (KERNEL)
375  */
376 BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
377 {
378     return (BOOL16)RemoveDirectoryA( path );
379 }
380
381
382 /***********************************************************************
383  *           RemoveDirectory32A   (KERNEL32.437)
384  */
385 BOOL WINAPI RemoveDirectoryA( LPCSTR path )
386 {
387     DOS_FULL_NAME full_name;
388
389     TRACE_(file)("'%s'\n", path );
390
391     if (DOSFS_GetDevice( path ))
392     {
393         TRACE_(file)("cannot remove device '%s'!\n", path);
394         SetLastError( ERROR_FILE_NOT_FOUND );
395         return FALSE;
396     }
397     if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
398     if (rmdir( full_name.long_name ) == -1)
399     {
400         FILE_SetDosError();
401         return FALSE;
402     }
403     return TRUE;
404 }
405
406
407 /***********************************************************************
408  *           RemoveDirectory32W   (KERNEL32.438)
409  */
410 BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
411 {
412     LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
413     BOOL ret = RemoveDirectoryA( xpath );
414     HeapFree( GetProcessHeap(), 0, xpath );
415     return ret;
416 }
417
418
419 /***********************************************************************
420  *           DIR_TryPath
421  *
422  * Helper function for DIR_SearchPath.
423  */
424 static BOOL DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name,
425                            DOS_FULL_NAME *full_name )
426 {
427     LPSTR p_l = full_name->long_name + strlen(dir->long_name) + 1;
428     LPSTR p_s = full_name->short_name + strlen(dir->short_name) + 1;
429
430     if ((p_s >= full_name->short_name + sizeof(full_name->short_name) - 14) ||
431         (p_l >= full_name->long_name + sizeof(full_name->long_name) - 1))
432     {
433         SetLastError( ERROR_PATH_NOT_FOUND );
434         return FALSE;
435     }
436     if (!DOSFS_FindUnixName( dir->long_name, name, p_l,
437                    sizeof(full_name->long_name) - (p_l - full_name->long_name),
438                    p_s, !(DRIVE_GetFlags(dir->drive) & DRIVE_CASE_SENSITIVE) ))
439         return FALSE;
440     strcpy( full_name->long_name, dir->long_name );
441     p_l[-1] = '/';
442     strcpy( full_name->short_name, dir->short_name );
443     p_s[-1] = '\\';
444     return TRUE;
445 }
446
447
448 /***********************************************************************
449  *           DIR_TryEnvironmentPath
450  *
451  * Helper function for DIR_SearchPath.
452  */
453 static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name )
454 {
455     LPSTR path, next, buffer;
456     BOOL ret = FALSE;
457     INT len = strlen(name);
458     DWORD size = GetEnvironmentVariableA( "PATH", NULL, 0 );
459
460     if (!size) return FALSE;
461     if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
462     if (!GetEnvironmentVariableA( "PATH", path, size )) goto done;
463     next = path;
464     while (!ret && next)
465     {
466         LPSTR cur = next;
467         while (*cur == ';') cur++;
468         if (!*cur) break;
469         next = strchr( cur, ';' );
470         if (next) *next++ = '\0';
471         if (!(buffer = HeapAlloc( GetProcessHeap(), 0, strlen(cur) + len + 2)))
472             goto done;
473         strcpy( buffer, cur );
474         strcat( buffer, "\\" );
475         strcat( buffer, name );
476         ret = DOSFS_GetFullName( buffer, TRUE, full_name );
477         HeapFree( GetProcessHeap(), 0, buffer );
478     }
479
480 done:
481     HeapFree( GetProcessHeap(), 0, path );
482     return ret;
483 }
484
485
486 /***********************************************************************
487  *           DIR_TryModulePath
488  *
489  * Helper function for DIR_SearchPath.
490  */
491 static BOOL DIR_TryModulePath( LPCSTR name, DOS_FULL_NAME *full_name )
492 {
493     PDB *pdb = PROCESS_Current();
494
495     /* FIXME: for now, GetModuleFileName32A can't return more */
496     /* than OFS_MAXPATHNAME. This may change with Win32. */
497
498     char buffer[OFS_MAXPATHNAME];
499     LPSTR p;
500
501     if (pdb->flags & PDB32_WIN16_PROC) {
502         if (!GetCurrentTask()) return FALSE;
503         if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
504                 buffer[0]='\0';
505     } else {
506         if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
507                 buffer[0]='\0';
508     }
509     if (!(p = strrchr( buffer, '\\' ))) return FALSE;
510     if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
511     strcpy( p, name );
512     return DOSFS_GetFullName( buffer, TRUE, full_name );
513 }
514
515
516 /***********************************************************************
517  *           DIR_SearchPath
518  *
519  * Implementation of SearchPath32A. 'win32' specifies whether the search
520  * order is Win16 (module path last) or Win32 (module path first).
521  *
522  * FIXME: should return long path names.
523  */
524 DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
525                       DOS_FULL_NAME *full_name, BOOL win32 )
526 {
527     DWORD len;
528     LPCSTR p;
529     LPSTR tmp = NULL;
530     BOOL ret = TRUE;
531
532     /* First check the supplied parameters */
533
534     p = strrchr( name, '.' );
535     if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
536         ext = NULL;  /* Ignore the specified extension */
537     if ((*name && (name[1] == ':')) ||
538         strchr( name, '/' ) || strchr( name, '\\' ))
539         path = NULL;  /* Ignore path if name already contains a path */
540     if (path && !*path) path = NULL;  /* Ignore empty path */
541
542     len = strlen(name);
543     if (ext) len += strlen(ext);
544     if (path) len += strlen(path) + 1;
545
546     /* Allocate a buffer for the file name and extension */
547
548     if (path || ext)
549     {
550         if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
551         {
552             SetLastError( ERROR_OUTOFMEMORY );
553             return 0;
554         }
555         if (path)
556         {
557             strcpy( tmp, path );
558             strcat( tmp, "\\" );
559             strcat( tmp, name );
560         }
561         else strcpy( tmp, name );
562         if (ext) strcat( tmp, ext );
563         name = tmp;
564     }
565     
566     /* If we have an explicit path, everything's easy */
567
568     if (path || (*name && (name[1] == ':')) ||
569         strchr( name, '/' ) || strchr( name, '\\' ))
570     {
571         ret = DOSFS_GetFullName( name, TRUE, full_name );
572         goto done;
573     }
574
575     /* Try the path of the current executable (for Win32 search order) */
576
577     if (win32 && DIR_TryModulePath( name, full_name )) goto done;
578
579     /* Try the current directory */
580
581     if (DOSFS_GetFullName( name, TRUE, full_name )) goto done;
582
583     /* Try the Windows system directory */
584
585     if (DIR_TryPath( &DIR_System, name, full_name ))
586         goto done;
587
588     /* Try the Windows directory */
589
590     if (DIR_TryPath( &DIR_Windows, name, full_name ))
591         goto done;
592
593     /* Try the path of the current executable (for Win16 search order) */
594
595     if (!win32 && DIR_TryModulePath( name, full_name )) goto done;
596
597     /* Try all directories in path */
598
599     ret = DIR_TryEnvironmentPath( name, full_name );
600
601 done:
602     if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
603     return ret;
604 }
605
606
607 /***********************************************************************
608  * SearchPath32A [KERNEL32.447]
609  *
610  * Searches for a specified file in the search path.
611  *
612  * PARAMS
613  *    path      [I] Path to search
614  *    name      [I] Filename to search for.
615  *    ext       [I] File extension to append to file name. The first
616  *                  character must be a period. This parameter is
617  *                  specified only if the filename given does not
618  *                  contain an extension.
619  *    buflen    [I] size of buffer, in characters
620  *    buffer    [O] buffer for found filename
621  *    lastpart  [O] address of pointer to last used character in
622  *                  buffer (the final '\')
623  *
624  * RETURNS
625  *    Success: length of string copied into buffer, not including
626  *             terminating null character. If the filename found is
627  *             longer than the length of the buffer, the length of the
628  *             filename is returned.
629  *    Failure: Zero
630  * 
631  * NOTES
632  *    Should call SetLastError(but currently doesn't).
633  */
634 DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
635                             LPSTR buffer, LPSTR *lastpart )
636 {
637     LPSTR p, res;
638     DOS_FULL_NAME full_name;
639
640     if (!DIR_SearchPath( path, name, ext, &full_name, TRUE )) return 0;
641     lstrcpynA( buffer, full_name.short_name, buflen );
642     res = full_name.long_name +
643               strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
644     while (*res == '/') res++;
645     if (buflen)
646     {
647         if (buflen > 3) lstrcpynA( buffer + 3, res, buflen - 3 );
648         for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
649         if (lastpart) *lastpart = strrchr( buffer, '\\' ) + 1;
650     }
651     TRACE_(dosfs)("Returning %d\n", strlen(res) + 3 );
652     return strlen(res) + 3;
653 }
654
655
656 /***********************************************************************
657  *           SearchPath32W   (KERNEL32.448)
658  */
659 DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext,
660                             DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
661 {
662     LPWSTR p;
663     LPSTR res;
664     DOS_FULL_NAME full_name;
665
666     LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
667     LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
668     LPSTR extA  = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
669     DWORD ret = DIR_SearchPath( pathA, nameA, extA, &full_name, TRUE );
670     HeapFree( GetProcessHeap(), 0, extA );
671     HeapFree( GetProcessHeap(), 0, nameA );
672     HeapFree( GetProcessHeap(), 0, pathA );
673     if (!ret) return 0;
674
675     lstrcpynAtoW( buffer, full_name.short_name, buflen );
676     res = full_name.long_name +
677               strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
678     while (*res == '/') res++;
679     if (buflen)
680     {
681         if (buflen > 3) lstrcpynAtoW( buffer + 3, res, buflen - 3 ); 
682         for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
683         if (lastpart)
684         {
685             for (p = *lastpart = buffer; *p; p++)
686                 if (*p == '\\') *lastpart = p + 1;
687         }
688     }
689     return strlen(res) + 3;
690 }
691
692