Moved window move/resize syscommand handling to the graphics driver.
[wine/multimedia.git] / files / directory.c
blobef6786b9b731901aad2f78cdeef1bea92c094c4c
1 /*
2 * DOS directories functions
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include "config.h"
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <unistd.h>
16 #include <errno.h>
17 #ifdef HAVE_SYS_ERRNO_H
18 #include <sys/errno.h>
19 #endif
21 #include "winbase.h"
22 #include "wine/winbase16.h"
23 #include "windef.h"
24 #include "wingdi.h"
25 #include "wine/winuser16.h"
26 #include "winerror.h"
27 #include "drive.h"
28 #include "file.h"
29 #include "heap.h"
30 #include "msdos.h"
31 #include "options.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(dosfs);
35 DECLARE_DEBUG_CHANNEL(file);
37 static DOS_FULL_NAME DIR_Windows;
38 static DOS_FULL_NAME DIR_System;
41 /***********************************************************************
42 * DIR_GetPath
44 * Get a path name from the wine.ini file and make sure it is valid.
46 static int DIR_GetPath( const char *keyname, const char *defval,
47 DOS_FULL_NAME *full_name, BOOL warn )
49 char path[MAX_PATHNAME_LEN];
50 BY_HANDLE_FILE_INFORMATION info;
51 const char *mess = "does not exist";
53 PROFILE_GetWineIniString( "wine", keyname, defval, path, sizeof(path) );
54 if (!DOSFS_GetFullName( path, TRUE, full_name ) ||
55 (!FILE_Stat( full_name->long_name, &info ) && (mess=strerror(errno)))||
56 (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (mess="not a directory")))
58 if (warn)
59 MESSAGE("Invalid path '%s' for %s directory: %s\n", path, keyname, mess);
60 return 0;
62 return 1;
66 /***********************************************************************
67 * DIR_Init
69 int DIR_Init(void)
71 char path[MAX_PATHNAME_LEN];
72 DOS_FULL_NAME tmp_dir, profile_dir;
73 int drive;
74 const char *cwd;
76 if (!getcwd( path, MAX_PATHNAME_LEN ))
78 perror( "Could not get current directory" );
79 return 0;
81 cwd = path;
82 if ((drive = DRIVE_FindDriveRoot( &cwd )) == -1)
84 MESSAGE("Warning: could not find wine config [Drive x] entry "
85 "for current working directory %s; "
86 "starting in windows directory.\n", cwd );
88 else
90 DRIVE_SetCurrentDrive( drive );
91 DRIVE_Chdir( drive, cwd );
94 if (!(DIR_GetPath( "windows", "c:\\windows", &DIR_Windows, TRUE )) ||
95 !(DIR_GetPath( "system", "c:\\windows\\system", &DIR_System, TRUE )) ||
96 !(DIR_GetPath( "temp", "c:\\windows", &tmp_dir, TRUE )))
98 PROFILE_UsageWineIni();
99 return 0;
101 if (-1 == access( tmp_dir.long_name, W_OK ))
103 if (errno==EACCES)
105 MESSAGE("Warning: the temporary directory '%s' (specified in wine configuration file) is not writeable.\n", tmp_dir.long_name);
106 PROFILE_UsageWineIni();
108 else
109 MESSAGE("Warning: access to temporary directory '%s' failed (%s).\n",
110 tmp_dir.long_name, strerror(errno));
113 if (drive == -1)
115 drive = DIR_Windows.drive;
116 DRIVE_SetCurrentDrive( drive );
117 DRIVE_Chdir( drive, DIR_Windows.short_name + 2 );
120 PROFILE_GetWineIniString("wine", "path", "c:\\windows;c:\\windows\\system",
121 path, sizeof(path) );
122 if (strchr(path, '/'))
124 MESSAGE("No '/' allowed in [wine] 'Path=' statement of wine config!\n");
125 PROFILE_UsageWineIni();
126 ExitProcess(1);
129 /* Set the environment variables */
131 SetEnvironmentVariableA( "PATH", path );
132 SetEnvironmentVariableA( "TEMP", tmp_dir.short_name );
133 SetEnvironmentVariableA( "TMP", tmp_dir.short_name );
134 SetEnvironmentVariableA( "windir", DIR_Windows.short_name );
135 SetEnvironmentVariableA( "winsysdir", DIR_System.short_name );
137 /* set COMSPEC only if it doesn't exist already */
138 if (!GetEnvironmentVariableA( "COMSPEC", NULL, 0 ))
139 SetEnvironmentVariableA( "COMSPEC", "c:\\command.com" );
141 TRACE("WindowsDir = %s (%s)\n",
142 DIR_Windows.short_name, DIR_Windows.long_name );
143 TRACE("SystemDir = %s (%s)\n",
144 DIR_System.short_name, DIR_System.long_name );
145 TRACE("TempDir = %s (%s)\n",
146 tmp_dir.short_name, tmp_dir.long_name );
147 TRACE("Path = %s\n", path );
148 TRACE("Cwd = %c:\\%s\n",
149 'A' + drive, DRIVE_GetDosCwd( drive ) );
151 if (DIR_GetPath( "profile", "", &profile_dir, FALSE ))
153 TRACE("USERPROFILE= %s\n", profile_dir.short_name );
154 SetEnvironmentVariableA( "USERPROFILE", profile_dir.short_name );
157 TRACE("SYSTEMROOT = %s\n", DIR_Windows.short_name );
158 SetEnvironmentVariableA( "SYSTEMROOT", DIR_Windows.short_name );
160 return 1;
164 /***********************************************************************
165 * GetTempPathA (KERNEL32.292)
167 UINT WINAPI GetTempPathA( UINT count, LPSTR path )
169 UINT ret;
170 if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
171 if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
172 if (!(ret = GetCurrentDirectoryA( count, path )))
173 return 0;
174 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
176 path[ret++] = '\\';
177 path[ret] = '\0';
179 return ret;
183 /***********************************************************************
184 * GetTempPathW (KERNEL32.293)
186 UINT WINAPI GetTempPathW( UINT count, LPWSTR path )
188 static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
189 static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
190 UINT ret;
191 if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
192 if (!(ret = GetEnvironmentVariableW( temp, path, count )))
193 if (!(ret = GetCurrentDirectoryW( count, path )))
194 return 0;
195 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
197 path[ret++] = '\\';
198 path[ret] = '\0';
200 return ret;
204 /***********************************************************************
205 * DIR_GetWindowsUnixDir
207 UINT DIR_GetWindowsUnixDir( LPSTR path, UINT count )
209 if (path) lstrcpynA( path, DIR_Windows.long_name, count );
210 return strlen( DIR_Windows.long_name );
214 /***********************************************************************
215 * DIR_GetSystemUnixDir
217 UINT DIR_GetSystemUnixDir( LPSTR path, UINT count )
219 if (path) lstrcpynA( path, DIR_System.long_name, count );
220 return strlen( DIR_System.long_name );
224 /***********************************************************************
225 * GetTempDrive (KERNEL.92)
226 * A closer look at krnl386.exe shows what the SDK doesn't mention:
228 * returns:
229 * AL: driveletter
230 * AH: ':' - yes, some kernel code even does stosw with
231 * the returned AX.
232 * DX: 1 for success
234 UINT WINAPI GetTempDrive( BYTE ignored )
236 char *buffer;
237 BYTE ret;
238 UINT len = GetTempPathA( 0, NULL );
240 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 )) )
241 ret = DRIVE_GetCurrentDrive() + 'A';
242 else
244 /* FIXME: apparently Windows does something with the ignored byte */
245 if (!GetTempPathA( len, buffer )) buffer[0] = 'C';
246 ret = toupper(buffer[0]);
247 HeapFree( GetProcessHeap(), 0, buffer );
249 return MAKELONG( ret | (':' << 8), 1 );
253 /***********************************************************************
254 * GetWindowsDirectory16 (KERNEL.134)
256 UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
258 return (UINT16)GetWindowsDirectoryA( path, count );
262 /***********************************************************************
263 * GetWindowsDirectoryA (KERNEL32.311)
265 UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
267 if (path) lstrcpynA( path, DIR_Windows.short_name, count );
268 return strlen( DIR_Windows.short_name );
272 /***********************************************************************
273 * GetWindowsDirectoryW (KERNEL32.312)
275 UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
277 UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, NULL, 0 );
278 if (path && count)
280 if (!MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, path, count ))
281 path[count-1] = 0;
283 return len;
287 /***********************************************************************
288 * GetSystemWindowsDirectoryA (KERNEL32) W2K, TS4.0SP4
290 UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count )
292 return GetWindowsDirectoryA( path, count );
296 /***********************************************************************
297 * GetSystemWindowsDirectoryW (KERNEL32) W2K, TS4.0SP4
299 UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
301 return GetWindowsDirectoryW( path, count );
305 /***********************************************************************
306 * GetSystemDirectory16 (KERNEL.135)
308 UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
310 return (UINT16)GetSystemDirectoryA( path, count );
314 /***********************************************************************
315 * GetSystemDirectoryA (KERNEL32.282)
317 UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
319 if (path) lstrcpynA( path, DIR_System.short_name, count );
320 return strlen( DIR_System.short_name );
324 /***********************************************************************
325 * GetSystemDirectoryW (KERNEL32.283)
327 UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
329 UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, NULL, 0 );
330 if (path && count)
332 if (!MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, path, count ))
333 path[count-1] = 0;
335 return len;
339 /***********************************************************************
340 * CreateDirectory16 (KERNEL.144)
342 BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
344 TRACE_(file)("(%s,%p)\n", path, dummy );
345 return (BOOL16)CreateDirectoryA( path, NULL );
349 /***********************************************************************
350 * CreateDirectoryA (KERNEL32.39)
351 * RETURNS:
352 * TRUE : success
353 * FALSE : failure
354 * ERROR_DISK_FULL: on full disk
355 * ERROR_ALREADY_EXISTS: if directory name exists (even as file)
356 * ERROR_ACCESS_DENIED: on permission problems
357 * ERROR_FILENAME_EXCED_RANGE: too long filename(s)
359 BOOL WINAPI CreateDirectoryA( LPCSTR path,
360 LPSECURITY_ATTRIBUTES lpsecattribs )
362 DOS_FULL_NAME full_name;
364 TRACE_(file)("(%s,%p)\n", path, lpsecattribs );
365 if (DOSFS_GetDevice( path ))
367 TRACE_(file)("cannot use device '%s'!\n",path);
368 SetLastError( ERROR_ACCESS_DENIED );
369 return FALSE;
371 if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0;
372 if (mkdir( full_name.long_name, 0777 ) == -1) {
373 WARN_(file)("Error '%s' trying to create directory '%s'\n", strerror(errno), full_name.long_name);
374 /* the FILE_SetDosError() generated error codes don't match the
375 * CreateDirectory ones for some errnos */
376 switch (errno) {
377 case EEXIST: SetLastError(ERROR_ALREADY_EXISTS); break;
378 case ENOSPC: SetLastError(ERROR_DISK_FULL); break;
379 default: FILE_SetDosError();break;
381 return FALSE;
383 return TRUE;
387 /***********************************************************************
388 * CreateDirectoryW (KERNEL32.42)
390 BOOL WINAPI CreateDirectoryW( LPCWSTR path,
391 LPSECURITY_ATTRIBUTES lpsecattribs )
393 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
394 BOOL ret = CreateDirectoryA( xpath, lpsecattribs );
395 HeapFree( GetProcessHeap(), 0, xpath );
396 return ret;
400 /***********************************************************************
401 * CreateDirectoryExA (KERNEL32.40)
403 BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path,
404 LPSECURITY_ATTRIBUTES lpsecattribs)
406 return CreateDirectoryA(path,lpsecattribs);
410 /***********************************************************************
411 * CreateDirectoryExW (KERNEL32.41)
413 BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path,
414 LPSECURITY_ATTRIBUTES lpsecattribs)
416 return CreateDirectoryW(path,lpsecattribs);
420 /***********************************************************************
421 * RemoveDirectory16 (KERNEL)
423 BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
425 return (BOOL16)RemoveDirectoryA( path );
429 /***********************************************************************
430 * RemoveDirectoryA (KERNEL32.437)
432 BOOL WINAPI RemoveDirectoryA( LPCSTR path )
434 DOS_FULL_NAME full_name;
436 TRACE_(file)("'%s'\n", path );
438 if (DOSFS_GetDevice( path ))
440 TRACE_(file)("cannot remove device '%s'!\n", path);
441 SetLastError( ERROR_FILE_NOT_FOUND );
442 return FALSE;
444 if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
445 if (rmdir( full_name.long_name ) == -1)
447 FILE_SetDosError();
448 return FALSE;
450 return TRUE;
454 /***********************************************************************
455 * RemoveDirectoryW (KERNEL32.438)
457 BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
459 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
460 BOOL ret = RemoveDirectoryA( xpath );
461 HeapFree( GetProcessHeap(), 0, xpath );
462 return ret;
466 /***********************************************************************
467 * DIR_TryPath
469 * Helper function for DIR_SearchPath.
471 static BOOL DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name,
472 DOS_FULL_NAME *full_name )
474 LPSTR p_l = full_name->long_name + strlen(dir->long_name) + 1;
475 LPSTR p_s = full_name->short_name + strlen(dir->short_name) + 1;
477 if ((p_s >= full_name->short_name + sizeof(full_name->short_name) - 14) ||
478 (p_l >= full_name->long_name + sizeof(full_name->long_name) - 1))
480 SetLastError( ERROR_PATH_NOT_FOUND );
481 return FALSE;
483 if (!DOSFS_FindUnixName( dir->long_name, name, p_l,
484 sizeof(full_name->long_name) - (p_l - full_name->long_name),
485 p_s, !(DRIVE_GetFlags(dir->drive) & DRIVE_CASE_SENSITIVE) ))
486 return FALSE;
487 strcpy( full_name->long_name, dir->long_name );
488 p_l[-1] = '/';
489 strcpy( full_name->short_name, dir->short_name );
490 p_s[-1] = '\\';
491 return TRUE;
495 /***********************************************************************
496 * DIR_TryEnvironmentPath
498 * Helper function for DIR_SearchPath.
499 * Search in the specified path, or in $PATH if NULL.
501 static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name, LPCSTR envpath )
503 LPSTR path, next, buffer;
504 BOOL ret = FALSE;
505 INT len = strlen(name);
506 DWORD size;
508 size = envpath ? strlen(envpath)+1 : GetEnvironmentVariableA( "PATH", NULL, 0 );
509 if (!size) return FALSE;
510 if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
511 if (envpath) strcpy( path, envpath );
512 else if (!GetEnvironmentVariableA( "PATH", path, size )) goto done;
513 next = path;
514 while (!ret && next)
516 LPSTR cur = next;
517 while (*cur == ';') cur++;
518 if (!*cur) break;
519 next = strchr( cur, ';' );
520 if (next) *next++ = '\0';
521 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, strlen(cur) + len + 2)))
522 goto done;
523 strcpy( buffer, cur );
524 strcat( buffer, "\\" );
525 strcat( buffer, name );
526 ret = DOSFS_GetFullName( buffer, TRUE, full_name );
527 HeapFree( GetProcessHeap(), 0, buffer );
530 done:
531 HeapFree( GetProcessHeap(), 0, path );
532 return ret;
536 /***********************************************************************
537 * DIR_TryModulePath
539 * Helper function for DIR_SearchPath.
541 static BOOL DIR_TryModulePath( LPCSTR name, DOS_FULL_NAME *full_name, BOOL win32 )
543 /* FIXME: for now, GetModuleFileNameA can't return more */
544 /* than OFS_MAXPATHNAME. This may change with Win32. */
546 char buffer[OFS_MAXPATHNAME];
547 LPSTR p;
549 if (!win32)
551 if (!GetCurrentTask()) return FALSE;
552 if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
553 buffer[0]='\0';
554 } else {
555 if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
556 buffer[0]='\0';
558 if (!(p = strrchr( buffer, '\\' ))) return FALSE;
559 if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
560 strcpy( p, name );
561 return DOSFS_GetFullName( buffer, TRUE, full_name );
565 /***********************************************************************
566 * DIR_SearchPath
568 * Implementation of SearchPathA. 'win32' specifies whether the search
569 * order is Win16 (module path last) or Win32 (module path first).
571 * FIXME: should return long path names.
573 DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
574 DOS_FULL_NAME *full_name, BOOL win32 )
576 LPCSTR p;
577 LPSTR tmp = NULL;
578 BOOL ret = TRUE;
580 /* First check the supplied parameters */
582 p = strrchr( name, '.' );
583 if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
584 ext = NULL; /* Ignore the specified extension */
585 if ((*name && (name[1] == ':')) ||
586 strchr( name, '/' ) || strchr( name, '\\' ))
587 path = NULL; /* Ignore path if name already contains a path */
588 if (path && !*path) path = NULL; /* Ignore empty path */
590 /* Allocate a buffer for the file name and extension */
592 if (ext)
594 DWORD len = strlen(name) + strlen(ext);
595 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
597 SetLastError( ERROR_OUTOFMEMORY );
598 return 0;
600 strcpy( tmp, name );
601 strcat( tmp, ext );
602 name = tmp;
605 /* If the name contains an explicit path, everything's easy */
607 if ((*name && (name[1] == ':')) || strchr( name, '/' ) || strchr( name, '\\' ))
609 ret = DOSFS_GetFullName( name, TRUE, full_name );
610 goto done;
613 /* Search in the specified path */
615 if (path)
617 ret = DIR_TryEnvironmentPath( name, full_name, path );
618 goto done;
621 /* Try the path of the current executable (for Win32 search order) */
623 if (win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
625 /* Try the current directory */
627 if (DOSFS_GetFullName( name, TRUE, full_name )) goto done;
629 /* Try the Windows system directory */
631 if (DIR_TryPath( &DIR_System, name, full_name ))
632 goto done;
634 /* Try the Windows directory */
636 if (DIR_TryPath( &DIR_Windows, name, full_name ))
637 goto done;
639 /* Try the path of the current executable (for Win16 search order) */
641 if (!win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
643 /* Try all directories in path */
645 ret = DIR_TryEnvironmentPath( name, full_name, NULL );
647 done:
648 if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
649 return ret;
653 /***********************************************************************
654 * SearchPathA [KERNEL32.447]
656 * Searches for a specified file in the search path.
658 * PARAMS
659 * path [I] Path to search
660 * name [I] Filename to search for.
661 * ext [I] File extension to append to file name. The first
662 * character must be a period. This parameter is
663 * specified only if the filename given does not
664 * contain an extension.
665 * buflen [I] size of buffer, in characters
666 * buffer [O] buffer for found filename
667 * lastpart [O] address of pointer to last used character in
668 * buffer (the final '\')
670 * RETURNS
671 * Success: length of string copied into buffer, not including
672 * terminating null character. If the filename found is
673 * longer than the length of the buffer, the length of the
674 * filename is returned.
675 * Failure: Zero
677 * NOTES
678 * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND)
679 * (tested on NT 4.0)
681 DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
682 LPSTR buffer, LPSTR *lastpart )
684 LPSTR p, res;
685 DOS_FULL_NAME full_name;
687 if (!DIR_SearchPath( path, name, ext, &full_name, TRUE ))
689 SetLastError(ERROR_FILE_NOT_FOUND);
690 return 0;
692 lstrcpynA( buffer, full_name.short_name, buflen );
693 res = full_name.long_name +
694 strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
695 while (*res == '/') res++;
696 if (buflen)
698 if (buflen > 3) lstrcpynA( buffer + 3, res, buflen - 3 );
699 for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
700 if (lastpart) *lastpart = strrchr( buffer, '\\' ) + 1;
702 TRACE("Returning %d\n", strlen(res) + 3 );
703 return strlen(res) + 3;
707 /***********************************************************************
708 * SearchPathW (KERNEL32.448)
710 DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext,
711 DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
713 LPWSTR p;
714 LPSTR res;
715 DOS_FULL_NAME full_name;
717 LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
718 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
719 LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
720 DWORD ret = DIR_SearchPath( pathA, nameA, extA, &full_name, TRUE );
721 HeapFree( GetProcessHeap(), 0, extA );
722 HeapFree( GetProcessHeap(), 0, nameA );
723 HeapFree( GetProcessHeap(), 0, pathA );
724 if (!ret) return 0;
726 if (buflen > 0 && !MultiByteToWideChar( CP_ACP, 0, full_name.short_name, -1, buffer, buflen ))
727 buffer[buflen-1] = 0;
728 res = full_name.long_name +
729 strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
730 while (*res == '/') res++;
731 if (buflen)
733 if (buflen > 3)
735 if (!MultiByteToWideChar( CP_ACP, 0, res, -1, buffer+3, buflen-3 ))
736 buffer[buflen-1] = 0;
738 for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
739 if (lastpart)
741 for (p = *lastpart = buffer; *p; p++)
742 if (*p == '\\') *lastpart = p + 1;
745 return strlen(res) + 3;