blob: ef6786b9b731901aad2f78cdeef1bea92c094c4c [file] [log] [blame]
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +00001/*
2 * DOS directories functions
3 *
4 * Copyright 1995 Alexandre Julliard
5 */
6
Patrik Stridvall96336321999-10-24 22:13:47 +00007#include "config.h"
8
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00009#include <ctype.h>
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000010#include <stdlib.h>
Jeremy Whited3e22d92000-02-10 19:03:02 +000011#include <stdio.h>
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000012#include <string.h>
Alexandre Julliardc6c09441997-01-12 18:32:19 +000013#include <sys/types.h>
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000014#include <sys/stat.h>
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000015#include <unistd.h>
Alexandre Julliard139a4b11996-11-02 14:24:07 +000016#include <errno.h>
Howard Abrams13277481999-07-10 13:16:29 +000017#ifdef HAVE_SYS_ERRNO_H
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000018#include <sys/errno.h>
Howard Abrams13277481999-07-10 13:16:29 +000019#endif
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000020
Marcus Meissner04c3e1d1999-02-19 10:37:02 +000021#include "winbase.h"
22#include "wine/winbase16.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000023#include "windef.h"
24#include "wingdi.h"
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +000025#include "wine/winuser16.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000026#include "winerror.h"
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000027#include "drive.h"
28#include "file.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000029#include "heap.h"
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000030#include "msdos.h"
Alexandre Julliard7e56f681996-01-31 19:02:28 +000031#include "options.h"
Alexandre Julliard06c275a1999-05-02 14:32:27 +000032#include "debugtools.h"
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000033
Jeremy Whited3e22d92000-02-10 19:03:02 +000034DEFAULT_DEBUG_CHANNEL(dosfs);
35DECLARE_DEBUG_CHANNEL(file);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000036
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000037static DOS_FULL_NAME DIR_Windows;
38static DOS_FULL_NAME DIR_System;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000039
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000040
41/***********************************************************************
42 * DIR_GetPath
43 *
44 * Get a path name from the wine.ini file and make sure it is valid.
45 */
46static int DIR_GetPath( const char *keyname, const char *defval,
Gerard Pateld52e1c42001-02-16 19:05:42 +000047 DOS_FULL_NAME *full_name, BOOL warn )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000048{
49 char path[MAX_PATHNAME_LEN];
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000050 BY_HANDLE_FILE_INFORMATION info;
Lawson Whitney03482122000-12-14 20:30:13 +000051 const char *mess = "does not exist";
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000052
Alexandre Julliard7e56f681996-01-31 19:02:28 +000053 PROFILE_GetWineIniString( "wine", keyname, defval, path, sizeof(path) );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000054 if (!DOSFS_GetFullName( path, TRUE, full_name ) ||
Lawson Whitney03482122000-12-14 20:30:13 +000055 (!FILE_Stat( full_name->long_name, &info ) && (mess=strerror(errno)))||
56 (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (mess="not a directory")))
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000057 {
Gerard Pateld52e1c42001-02-16 19:05:42 +000058 if (warn)
59 MESSAGE("Invalid path '%s' for %s directory: %s\n", path, keyname, mess);
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000060 return 0;
61 }
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000062 return 1;
63}
64
65
66/***********************************************************************
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000067 * DIR_Init
68 */
69int DIR_Init(void)
70{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000071 char path[MAX_PATHNAME_LEN];
Juergen Schmied8573cc72000-01-30 03:03:23 +000072 DOS_FULL_NAME tmp_dir, profile_dir;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000073 int drive;
74 const char *cwd;
75
76 if (!getcwd( path, MAX_PATHNAME_LEN ))
77 {
78 perror( "Could not get current directory" );
79 return 0;
80 }
81 cwd = path;
82 if ((drive = DRIVE_FindDriveRoot( &cwd )) == -1)
83 {
Chris Morgane4055502001-01-12 19:55:19 +000084 MESSAGE("Warning: could not find wine config [Drive x] entry "
Andreas Mohrdf8cdfd1999-02-28 16:56:48 +000085 "for current working directory %s; "
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000086 "starting in windows directory.\n", cwd );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000087 }
88 else
89 {
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000090 DRIVE_SetCurrentDrive( drive );
Alexandre Julliardc6c09441997-01-12 18:32:19 +000091 DRIVE_Chdir( drive, cwd );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +000092 }
93
Gerard Pateld52e1c42001-02-16 19:05:42 +000094 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 )))
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000097 {
98 PROFILE_UsageWineIni();
Alexandre Julliardc7c217b1998-04-13 12:21:30 +000099 return 0;
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000100 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000101 if (-1 == access( tmp_dir.long_name, W_OK ))
102 {
Alexandre Julliard8bbf8181996-09-13 16:50:47 +0000103 if (errno==EACCES)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000104 {
Andreas Mohra6d83eb2000-12-27 04:02:46 +0000105 MESSAGE("Warning: the temporary directory '%s' (specified in wine configuration file) is not writeable.\n", tmp_dir.long_name);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000106 PROFILE_UsageWineIni();
107 }
Alexandre Julliard8bbf8181996-09-13 16:50:47 +0000108 else
Andreas Mohra6d83eb2000-12-27 04:02:46 +0000109 MESSAGE("Warning: access to temporary directory '%s' failed (%s).\n",
110 tmp_dir.long_name, strerror(errno));
Alexandre Julliard8bbf8181996-09-13 16:50:47 +0000111 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000112
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000113 if (drive == -1)
114 {
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000115 drive = DIR_Windows.drive;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000116 DRIVE_SetCurrentDrive( drive );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000117 DRIVE_Chdir( drive, DIR_Windows.short_name + 2 );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000118 }
119
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000120 PROFILE_GetWineIniString("wine", "path", "c:\\windows;c:\\windows\\system",
121 path, sizeof(path) );
Andreas Mohr0b160062000-01-26 02:04:09 +0000122 if (strchr(path, '/'))
123 {
Chris Morgane4055502001-01-12 19:55:19 +0000124 MESSAGE("No '/' allowed in [wine] 'Path=' statement of wine config!\n");
Andreas Mohr0b160062000-01-26 02:04:09 +0000125 PROFILE_UsageWineIni();
126 ExitProcess(1);
127 }
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000128
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000129 /* Set the environment variables */
130
Alexandre Julliarda3960291999-02-26 11:11:13 +0000131 SetEnvironmentVariableA( "PATH", path );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000132 SetEnvironmentVariableA( "TEMP", tmp_dir.short_name );
Dmitry Timoshkovb6ac7702000-12-24 20:01:12 +0000133 SetEnvironmentVariableA( "TMP", tmp_dir.short_name );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000134 SetEnvironmentVariableA( "windir", DIR_Windows.short_name );
135 SetEnvironmentVariableA( "winsysdir", DIR_System.short_name );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000136
Alexandre Julliard2e9f7862000-08-01 23:34:01 +0000137 /* set COMSPEC only if it doesn't exist already */
138 if (!GetEnvironmentVariableA( "COMSPEC", NULL, 0 ))
139 SetEnvironmentVariableA( "COMSPEC", "c:\\command.com" );
140
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000141 TRACE("WindowsDir = %s (%s)\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000142 DIR_Windows.short_name, DIR_Windows.long_name );
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000143 TRACE("SystemDir = %s (%s)\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000144 DIR_System.short_name, DIR_System.long_name );
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000145 TRACE("TempDir = %s (%s)\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000146 tmp_dir.short_name, tmp_dir.long_name );
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000147 TRACE("Path = %s\n", path );
148 TRACE("Cwd = %c:\\%s\n",
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000149 'A' + drive, DRIVE_GetDosCwd( drive ) );
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000150
Gerard Pateld52e1c42001-02-16 19:05:42 +0000151 if (DIR_GetPath( "profile", "", &profile_dir, FALSE ))
Juergen Schmied8573cc72000-01-30 03:03:23 +0000152 {
153 TRACE("USERPROFILE= %s\n", profile_dir.short_name );
154 SetEnvironmentVariableA( "USERPROFILE", profile_dir.short_name );
155 }
156
157 TRACE("SYSTEMROOT = %s\n", DIR_Windows.short_name );
158 SetEnvironmentVariableA( "SYSTEMROOT", DIR_Windows.short_name );
159
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000160 return 1;
161}
162
163
164/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000165 * GetTempPathA (KERNEL32.292)
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000166 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000167UINT WINAPI GetTempPathA( UINT count, LPSTR path )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000168{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000169 UINT ret;
170 if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
171 if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
172 if (!(ret = GetCurrentDirectoryA( count, path )))
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000173 return 0;
Huw D M Daviesa03f0641998-12-15 18:04:58 +0000174 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000175 {
176 path[ret++] = '\\';
177 path[ret] = '\0';
178 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000179 return ret;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000180}
181
182
183/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000184 * GetTempPathW (KERNEL32.293)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000185 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000186UINT WINAPI GetTempPathW( UINT count, LPWSTR path )
Alexandre Julliard3051b641996-07-05 17:14:13 +0000187{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000188 static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
189 static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
Alexandre Julliarda3960291999-02-26 11:11:13 +0000190 UINT ret;
191 if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
192 if (!(ret = GetEnvironmentVariableW( temp, path, count )))
193 if (!(ret = GetCurrentDirectoryW( count, path )))
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000194 return 0;
Huw D M Daviesa03f0641998-12-15 18:04:58 +0000195 if (count && (ret < count - 1) && (path[ret-1] != '\\'))
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000196 {
197 path[ret++] = '\\';
198 path[ret] = '\0';
199 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000200 return ret;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000201}
202
203
204/***********************************************************************
205 * DIR_GetWindowsUnixDir
206 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000207UINT DIR_GetWindowsUnixDir( LPSTR path, UINT count )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000208{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000209 if (path) lstrcpynA( path, DIR_Windows.long_name, count );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000210 return strlen( DIR_Windows.long_name );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000211}
212
213
214/***********************************************************************
215 * DIR_GetSystemUnixDir
216 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000217UINT DIR_GetSystemUnixDir( LPSTR path, UINT count )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000218{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000219 if (path) lstrcpynA( path, DIR_System.long_name, count );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000220 return strlen( DIR_System.long_name );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000221}
222
223
224/***********************************************************************
225 * GetTempDrive (KERNEL.92)
Alexandre Julliardac7efef2000-11-27 21:54:01 +0000226 * A closer look at krnl386.exe shows what the SDK doesn't mention:
227 *
228 * returns:
229 * AL: driveletter
230 * AH: ':' - yes, some kernel code even does stosw with
231 * the returned AX.
232 * DX: 1 for success
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000233 */
Alexandre Julliardac7efef2000-11-27 21:54:01 +0000234UINT WINAPI GetTempDrive( BYTE ignored )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000235{
Uwe Bonnes3dbc7881999-02-14 17:32:46 +0000236 char *buffer;
237 BYTE ret;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000238 UINT len = GetTempPathA( 0, NULL );
Uwe Bonnes3dbc7881999-02-14 17:32:46 +0000239
240 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 )) )
Alexandre Julliardac7efef2000-11-27 21:54:01 +0000241 ret = DRIVE_GetCurrentDrive() + 'A';
242 else
243 {
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 );
248 }
249 return MAKELONG( ret | (':' << 8), 1 );
Alexandre Julliardca22b331996-07-12 19:02:39 +0000250}
251
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000252
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000253/***********************************************************************
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000254 * GetWindowsDirectory16 (KERNEL.134)
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000255 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000256UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000257{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000258 return (UINT16)GetWindowsDirectoryA( path, count );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000259}
260
261
262/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000263 * GetWindowsDirectoryA (KERNEL32.311)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000264 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000265UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000266{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000267 if (path) lstrcpynA( path, DIR_Windows.short_name, count );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000268 return strlen( DIR_Windows.short_name );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000269}
270
271
272/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000273 * GetWindowsDirectoryW (KERNEL32.312)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000274 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000275UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000276{
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000277 UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, NULL, 0 );
278 if (path && count)
279 {
280 if (!MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, path, count ))
281 path[count-1] = 0;
282 }
283 return len;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000284}
285
286
287/***********************************************************************
David Elliott44f84b52000-10-29 01:24:54 +0000288 * GetSystemWindowsDirectoryA (KERNEL32) W2K, TS4.0SP4
289 */
290UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count )
291{
292 return GetWindowsDirectoryA( path, count );
293}
294
295
296/***********************************************************************
297 * GetSystemWindowsDirectoryW (KERNEL32) W2K, TS4.0SP4
298 */
299UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count )
300{
301 return GetWindowsDirectoryW( path, count );
302}
303
304
305/***********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000306 * GetSystemDirectory16 (KERNEL.135)
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000307 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000308UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count )
Alexandre Julliard3051b641996-07-05 17:14:13 +0000309{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000310 return (UINT16)GetSystemDirectoryA( path, count );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000311}
312
313
314/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000315 * GetSystemDirectoryA (KERNEL32.282)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000316 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000317UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count )
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000318{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000319 if (path) lstrcpynA( path, DIR_System.short_name, count );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000320 return strlen( DIR_System.short_name );
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +0000321}
Alexandre Julliard3051b641996-07-05 17:14:13 +0000322
323
324/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000325 * GetSystemDirectoryW (KERNEL32.283)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000326 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000327UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count )
Alexandre Julliard3051b641996-07-05 17:14:13 +0000328{
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000329 UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, NULL, 0 );
330 if (path && count)
331 {
332 if (!MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, path, count ))
333 path[count-1] = 0;
334 }
335 return len;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000336}
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000337
338
339/***********************************************************************
340 * CreateDirectory16 (KERNEL.144)
341 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000342BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000343{
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000344 TRACE_(file)("(%s,%p)\n", path, dummy );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000345 return (BOOL16)CreateDirectoryA( path, NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000346}
347
348
349/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000350 * CreateDirectoryA (KERNEL32.39)
Marcus Meissner412d0251999-02-28 19:50:39 +0000351 * 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)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000358 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000359BOOL WINAPI CreateDirectoryA( LPCSTR path,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000360 LPSECURITY_ATTRIBUTES lpsecattribs )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000361{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000362 DOS_FULL_NAME full_name;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000363
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000364 TRACE_(file)("(%s,%p)\n", path, lpsecattribs );
Alexandre Julliard829fe321998-07-26 14:27:39 +0000365 if (DOSFS_GetDevice( path ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000366 {
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000367 TRACE_(file)("cannot use device '%s'!\n",path);
Alexandre Julliard4ff2a271999-01-31 15:23:45 +0000368 SetLastError( ERROR_ACCESS_DENIED );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000369 return FALSE;
370 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000371 if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0;
Marcus Meissner412d0251999-02-28 19:50:39 +0000372 if (mkdir( full_name.long_name, 0777 ) == -1) {
Andreas Mohr8c2f4b12001-03-03 00:22:50 +0000373 WARN_(file)("Error '%s' trying to create directory '%s'\n", strerror(errno), full_name.long_name);
Marcus Meissner412d0251999-02-28 19:50:39 +0000374 /* 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;
380 }
381 return FALSE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000382 }
383 return TRUE;
384}
385
386
387/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000388 * CreateDirectoryW (KERNEL32.42)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000389 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000390BOOL WINAPI CreateDirectoryW( LPCWSTR path,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000391 LPSECURITY_ATTRIBUTES lpsecattribs )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000392{
393 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000394 BOOL ret = CreateDirectoryA( xpath, lpsecattribs );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000395 HeapFree( GetProcessHeap(), 0, xpath );
396 return ret;
397}
398
399
400/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000401 * CreateDirectoryExA (KERNEL32.40)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000402 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000403BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000404 LPSECURITY_ATTRIBUTES lpsecattribs)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000405{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000406 return CreateDirectoryA(path,lpsecattribs);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000407}
408
409
410/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000411 * CreateDirectoryExW (KERNEL32.41)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000412 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000413BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000414 LPSECURITY_ATTRIBUTES lpsecattribs)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000415{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000416 return CreateDirectoryW(path,lpsecattribs);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000417}
418
419
420/***********************************************************************
421 * RemoveDirectory16 (KERNEL)
422 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000423BOOL16 WINAPI RemoveDirectory16( LPCSTR path )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000424{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000425 return (BOOL16)RemoveDirectoryA( path );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000426}
427
428
429/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000430 * RemoveDirectoryA (KERNEL32.437)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000431 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000432BOOL WINAPI RemoveDirectoryA( LPCSTR path )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000433{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000434 DOS_FULL_NAME full_name;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000435
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000436 TRACE_(file)("'%s'\n", path );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000437
Alexandre Julliard829fe321998-07-26 14:27:39 +0000438 if (DOSFS_GetDevice( path ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000439 {
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000440 TRACE_(file)("cannot remove device '%s'!\n", path);
Alexandre Julliard4ff2a271999-01-31 15:23:45 +0000441 SetLastError( ERROR_FILE_NOT_FOUND );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000442 return FALSE;
443 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000444 if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
445 if (rmdir( full_name.long_name ) == -1)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000446 {
447 FILE_SetDosError();
448 return FALSE;
449 }
450 return TRUE;
451}
452
453
454/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000455 * RemoveDirectoryW (KERNEL32.438)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000456 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000457BOOL WINAPI RemoveDirectoryW( LPCWSTR path )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000458{
459 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000460 BOOL ret = RemoveDirectoryA( xpath );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000461 HeapFree( GetProcessHeap(), 0, xpath );
462 return ret;
463}
464
465
466/***********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000467 * DIR_TryPath
468 *
469 * Helper function for DIR_SearchPath.
470 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000471static BOOL DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name,
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000472 DOS_FULL_NAME *full_name )
473{
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000474 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;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000476
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))
479 {
Alexandre Julliard4ff2a271999-01-31 15:23:45 +0000480 SetLastError( ERROR_PATH_NOT_FOUND );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000481 return FALSE;
482 }
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000483 if (!DOSFS_FindUnixName( dir->long_name, name, p_l,
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000484 sizeof(full_name->long_name) - (p_l - full_name->long_name),
Andreas Mohr04718411999-08-07 12:36:11 +0000485 p_s, !(DRIVE_GetFlags(dir->drive) & DRIVE_CASE_SENSITIVE) ))
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000486 return FALSE;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000487 strcpy( full_name->long_name, dir->long_name );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000488 p_l[-1] = '/';
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000489 strcpy( full_name->short_name, dir->short_name );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000490 p_s[-1] = '\\';
491 return TRUE;
492}
493
494
495/***********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000496 * DIR_TryEnvironmentPath
497 *
498 * Helper function for DIR_SearchPath.
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000499 * Search in the specified path, or in $PATH if NULL.
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000500 */
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000501static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name, LPCSTR envpath )
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000502{
503 LPSTR path, next, buffer;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000504 BOOL ret = FALSE;
505 INT len = strlen(name);
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000506 DWORD size;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000507
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000508 size = envpath ? strlen(envpath)+1 : GetEnvironmentVariableA( "PATH", NULL, 0 );
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000509 if (!size) return FALSE;
510 if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000511 if (envpath) strcpy( path, envpath );
512 else if (!GetEnvironmentVariableA( "PATH", path, size )) goto done;
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000513 next = path;
514 while (!ret && next)
515 {
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 );
528 }
529
530done:
531 HeapFree( GetProcessHeap(), 0, path );
532 return ret;
533}
534
535
536/***********************************************************************
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000537 * DIR_TryModulePath
538 *
539 * Helper function for DIR_SearchPath.
540 */
Alexandre Julliardb18dbd22000-07-25 12:11:53 +0000541static BOOL DIR_TryModulePath( LPCSTR name, DOS_FULL_NAME *full_name, BOOL win32 )
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000542{
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000543 /* FIXME: for now, GetModuleFileNameA can't return more */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000544 /* than OFS_MAXPATHNAME. This may change with Win32. */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000545
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000546 char buffer[OFS_MAXPATHNAME];
547 LPSTR p;
548
Alexandre Julliardb18dbd22000-07-25 12:11:53 +0000549 if (!win32)
550 {
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000551 if (!GetCurrentTask()) return FALSE;
Alexandre Julliarda845b881998-06-01 10:44:35 +0000552 if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) ))
553 buffer[0]='\0';
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000554 } else {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000555 if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
Alexandre Julliarda845b881998-06-01 10:44:35 +0000556 buffer[0]='\0';
Alexandre Julliarddadf78f1998-05-17 17:13:43 +0000557 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000558 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 );
562}
563
564
565/***********************************************************************
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000566 * DIR_SearchPath
567 *
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000568 * Implementation of SearchPathA. 'win32' specifies whether the search
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000569 * order is Win16 (module path last) or Win32 (module path first).
570 *
571 * FIXME: should return long path names.
572 */
573DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000574 DOS_FULL_NAME *full_name, BOOL win32 )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000575{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000576 LPCSTR p;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000577 LPSTR tmp = NULL;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000578 BOOL ret = TRUE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000579
580 /* First check the supplied parameters */
581
Alexandre Julliard641ee761997-08-04 16:34:36 +0000582 p = strrchr( name, '.' );
583 if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
584 ext = NULL; /* Ignore the specified extension */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000585 if ((*name && (name[1] == ':')) ||
586 strchr( name, '/' ) || strchr( name, '\\' ))
587 path = NULL; /* Ignore path if name already contains a path */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000588 if (path && !*path) path = NULL; /* Ignore empty path */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000589
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000590 /* Allocate a buffer for the file name and extension */
591
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000592 if (ext)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000593 {
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000594 DWORD len = strlen(name) + strlen(ext);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000595 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
596 {
597 SetLastError( ERROR_OUTOFMEMORY );
598 return 0;
599 }
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000600 strcpy( tmp, name );
601 strcat( tmp, ext );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000602 name = tmp;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000603 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000604
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000605 /* If the name contains an explicit path, everything's easy */
606
607 if ((*name && (name[1] == ':')) || strchr( name, '/' ) || strchr( name, '\\' ))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000608 {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000609 ret = DOSFS_GetFullName( name, TRUE, full_name );
610 goto done;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000611 }
612
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000613 /* Search in the specified path */
614
615 if (path)
616 {
617 ret = DIR_TryEnvironmentPath( name, full_name, path );
618 goto done;
619 }
620
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000621 /* Try the path of the current executable (for Win32 search order) */
622
Alexandre Julliardb18dbd22000-07-25 12:11:53 +0000623 if (win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000624
625 /* Try the current directory */
626
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000627 if (DOSFS_GetFullName( name, TRUE, full_name )) goto done;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000628
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000629 /* Try the Windows system directory */
630
Alexandre Julliardc7c217b1998-04-13 12:21:30 +0000631 if (DIR_TryPath( &DIR_System, name, full_name ))
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000632 goto done;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000633
Guy Albertellie40c9b01999-06-05 11:47:25 +0000634 /* Try the Windows directory */
635
636 if (DIR_TryPath( &DIR_Windows, name, full_name ))
637 goto done;
638
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000639 /* Try the path of the current executable (for Win16 search order) */
640
Alexandre Julliardb18dbd22000-07-25 12:11:53 +0000641 if (!win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000642
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000643 /* Try all directories in path */
644
Alexandre Julliard9400e2d2000-11-01 21:48:38 +0000645 ret = DIR_TryEnvironmentPath( name, full_name, NULL );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000646
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000647done:
648 if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
649 return ret;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000650}
651
652
653/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000654 * SearchPathA [KERNEL32.447]
Alexandre Julliarda845b881998-06-01 10:44:35 +0000655 *
656 * Searches for a specified file in the search path.
657 *
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 '\')
669 *
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
676 *
677 * NOTES
James Juran65020b32000-05-23 01:13:50 +0000678 * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND)
679 * (tested on NT 4.0)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000680 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000681DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000682 LPSTR buffer, LPSTR *lastpart )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000683{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000684 LPSTR p, res;
685 DOS_FULL_NAME full_name;
686
James Juran65020b32000-05-23 01:13:50 +0000687 if (!DIR_SearchPath( path, name, ext, &full_name, TRUE ))
688 {
689 SetLastError(ERROR_FILE_NOT_FOUND);
690 return 0;
691 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000692 lstrcpynA( buffer, full_name.short_name, buflen );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000693 res = full_name.long_name +
694 strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
Alexandre Julliard349a9531997-02-02 19:01:52 +0000695 while (*res == '/') res++;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000696 if (buflen)
697 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000698 if (buflen > 3) lstrcpynA( buffer + 3, res, buflen - 3 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000699 for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
700 if (lastpart) *lastpart = strrchr( buffer, '\\' ) + 1;
701 }
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000702 TRACE("Returning %d\n", strlen(res) + 3 );
Guy Albertellie711ba21999-04-06 07:14:09 +0000703 return strlen(res) + 3;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000704}
705
706
707/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000708 * SearchPathW (KERNEL32.448)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000709 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000710DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000711 DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000712{
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000713 LPWSTR p;
714 LPSTR res;
715 DOS_FULL_NAME full_name;
716
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000717 LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
718 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
719 LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000720 DWORD ret = DIR_SearchPath( pathA, nameA, extA, &full_name, TRUE );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000721 HeapFree( GetProcessHeap(), 0, extA );
722 HeapFree( GetProcessHeap(), 0, nameA );
723 HeapFree( GetProcessHeap(), 0, pathA );
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000724 if (!ret) return 0;
725
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000726 if (buflen > 0 && !MultiByteToWideChar( CP_ACP, 0, full_name.short_name, -1, buffer, buflen ))
727 buffer[buflen-1] = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000728 res = full_name.long_name +
729 strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' ));
Alexandre Julliard349a9531997-02-02 19:01:52 +0000730 while (*res == '/') res++;
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000731 if (buflen)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000732 {
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000733 if (buflen > 3)
734 {
735 if (!MultiByteToWideChar( CP_ACP, 0, res, -1, buffer+3, buflen-3 ))
736 buffer[buflen-1] = 0;
737 }
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000738 for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
739 if (lastpart)
740 {
741 for (p = *lastpart = buffer; *p; p++)
742 if (*p == '\\') *lastpart = p + 1;
743 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000744 }
Guy Albertellie711ba21999-04-06 07:14:09 +0000745 return strlen(res) + 3;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000746}
747
748