| 1 | /* $Id: directory.cpp,v 1.20 2000-04-29 18:26:58 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 Directory functions for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 7 | *
|
|---|
| 8 | * NOTE: Directory creation has to be done in install program (odin\win)
|
|---|
| 9 | *
|
|---|
| 10 | * Parts based on Wine code (991031) (files\directory.c)
|
|---|
| 11 | *
|
|---|
| 12 | * DOS directories functions
|
|---|
| 13 | *
|
|---|
| 14 | * Copyright 1995 Alexandre Julliard
|
|---|
| 15 | *
|
|---|
| 16 | * TODO: System/window directories should be created by install program!
|
|---|
| 17 | *
|
|---|
| 18 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 19 | *
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | /*****************************************************************************
|
|---|
| 24 | * Includes *
|
|---|
| 25 | *****************************************************************************/
|
|---|
| 26 |
|
|---|
| 27 | #include <odin.h>
|
|---|
| 28 | #include <odinwrap.h>
|
|---|
| 29 | #include <os2win.h>
|
|---|
| 30 | #include <stdlib.h>
|
|---|
| 31 | #include <unicode.h>
|
|---|
| 32 | #include <heapstring.h>
|
|---|
| 33 | #include <options.h>
|
|---|
| 34 | #include "initterm.h"
|
|---|
| 35 | #include <win\file.h>
|
|---|
| 36 | #include <string.h>
|
|---|
| 37 | #include "oslibdos.h"
|
|---|
| 38 | #include "profile.h"
|
|---|
| 39 |
|
|---|
| 40 | #define DBG_LOCALLOG DBG_directory
|
|---|
| 41 | #include "dbglocal.h"
|
|---|
| 42 |
|
|---|
| 43 | ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | static char DIR_Windows[MAX_PATHNAME_LEN];
|
|---|
| 47 | static char DIR_System[MAX_PATHNAME_LEN];
|
|---|
| 48 |
|
|---|
| 49 | //******************************************************************************
|
|---|
| 50 | //******************************************************************************
|
|---|
| 51 | char *InternalGetWindowsDirectoryA()
|
|---|
| 52 | {
|
|---|
| 53 | return DIR_Windows;
|
|---|
| 54 | }
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | //******************************************************************************
|
|---|
| 57 | char *InternalGetSystemDirectoryA()
|
|---|
| 58 | {
|
|---|
| 59 | return DIR_System;
|
|---|
| 60 | }
|
|---|
| 61 | //******************************************************************************
|
|---|
| 62 | //******************************************************************************
|
|---|
| 63 | void InitDirectories()
|
|---|
| 64 | {
|
|---|
| 65 | char *endofwinpath, *tmp;
|
|---|
| 66 | int len;
|
|---|
| 67 |
|
|---|
| 68 | strcpy(DIR_System, kernel32Path);
|
|---|
| 69 | len = strlen(DIR_System);
|
|---|
| 70 | if(DIR_System[len-1] == '\\') {
|
|---|
| 71 | DIR_System[len-1] = 0;
|
|---|
| 72 | }
|
|---|
| 73 | len = ODIN_PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",DIR_Windows,sizeof(DIR_Windows));
|
|---|
| 74 | if (len > 2) {
|
|---|
| 75 | if(DIR_Windows[len-1] == '\\') {
|
|---|
| 76 | DIR_Windows[len-1] = 0;
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 | else {
|
|---|
| 80 | strcpy(DIR_Windows, DIR_System);
|
|---|
| 81 | endofwinpath = tmp = strchr(DIR_Windows, '\\');
|
|---|
| 82 | while(tmp) {
|
|---|
| 83 | tmp = strchr(endofwinpath+1, '\\');
|
|---|
| 84 | if(tmp)
|
|---|
| 85 | endofwinpath = tmp;
|
|---|
| 86 | }
|
|---|
| 87 | if(endofwinpath) {
|
|---|
| 88 | *endofwinpath = 0; //remove \SYSTEM32
|
|---|
| 89 | }
|
|---|
| 90 | else DebugInt3();
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 | /*****************************************************************************
|
|---|
| 94 | * Name : GetCurrentDirectoryA
|
|---|
| 95 | * Purpose : query the current directory
|
|---|
| 96 | * Parameters:
|
|---|
| 97 | * Variables :
|
|---|
| 98 | * Result :
|
|---|
| 99 | * Remark :
|
|---|
| 100 | * Status :
|
|---|
| 101 | *
|
|---|
| 102 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 103 | *****************************************************************************/
|
|---|
| 104 |
|
|---|
| 105 | ODINFUNCTION2(UINT, GetCurrentDirectoryA, UINT, nBufferLength,
|
|---|
| 106 | LPSTR, lpBuffer)
|
|---|
| 107 | {
|
|---|
| 108 | return O32_GetCurrentDirectory(nBufferLength, lpBuffer);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 | /*****************************************************************************
|
|---|
| 113 | * Name : GetCurrentDirectoryW
|
|---|
| 114 | * Purpose : query the current directory
|
|---|
| 115 | * Parameters:
|
|---|
| 116 | * Variables :
|
|---|
| 117 | * Result :
|
|---|
| 118 | * Remark :
|
|---|
| 119 | * Status :
|
|---|
| 120 | *
|
|---|
| 121 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 122 | *****************************************************************************/
|
|---|
| 123 |
|
|---|
| 124 | ODINFUNCTION2(UINT, GetCurrentDirectoryW, UINT, nBufferLength,
|
|---|
| 125 | LPWSTR, lpBuffer)
|
|---|
| 126 | {
|
|---|
| 127 | char *asciidir = (char *)malloc(nBufferLength+1);
|
|---|
| 128 | int rc;
|
|---|
| 129 |
|
|---|
| 130 | rc = O32_GetCurrentDirectory(nBufferLength, asciidir);
|
|---|
| 131 | if(rc != 0)
|
|---|
| 132 | AsciiToUnicode(asciidir, lpBuffer);
|
|---|
| 133 | free(asciidir);
|
|---|
| 134 | return(rc);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 | /*****************************************************************************
|
|---|
| 139 | * Name : SetCurrentDirectoryA
|
|---|
| 140 | * Purpose :
|
|---|
| 141 | * Parameters:
|
|---|
| 142 | * Variables :
|
|---|
| 143 | * Result :
|
|---|
| 144 | * Remark :
|
|---|
| 145 | * Status :
|
|---|
| 146 | *
|
|---|
| 147 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 148 | *****************************************************************************/
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | ODINFUNCTION1(BOOL,SetCurrentDirectoryA,LPCSTR,lpPathName)
|
|---|
| 152 | {
|
|---|
| 153 | if(HIWORD(lpPathName) == 0) {
|
|---|
| 154 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 155 | return FALSE;
|
|---|
| 156 | }
|
|---|
| 157 | int len = strlen(lpPathName);
|
|---|
| 158 | char *tmp=(char *)alloca(len + 1);
|
|---|
| 159 |
|
|---|
| 160 | strcpy(tmp, lpPathName);
|
|---|
| 161 | //SvL: Don't remove terminating backslash if it wants to chdir to root dir
|
|---|
| 162 | if(tmp[len -1] == '\\' && len != 1)
|
|---|
| 163 | tmp[len -1] = 0;
|
|---|
| 164 |
|
|---|
| 165 | dprintf(("SetCurrentDirectoryA %s", tmp));
|
|---|
| 166 | return O32_SetCurrentDirectory((LPSTR)tmp);
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 | /*****************************************************************************
|
|---|
| 171 | * Name : SetCurrentDirectoryW
|
|---|
| 172 | * Purpose :
|
|---|
| 173 | * Parameters:
|
|---|
| 174 | * Variables :
|
|---|
| 175 | * Result :
|
|---|
| 176 | * Remark :
|
|---|
| 177 | * Status :
|
|---|
| 178 | *
|
|---|
| 179 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 180 | *****************************************************************************/
|
|---|
| 181 |
|
|---|
| 182 | ODINFUNCTION1(BOOL,SetCurrentDirectoryW,LPCWSTR,lpPathName)
|
|---|
| 183 | {
|
|---|
| 184 | char *asciipath;
|
|---|
| 185 | BOOL rc;
|
|---|
| 186 |
|
|---|
| 187 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
|---|
| 188 | rc = SetCurrentDirectoryA(asciipath);
|
|---|
| 189 | FreeAsciiString(asciipath);
|
|---|
| 190 | return(rc);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | /*****************************************************************************
|
|---|
| 195 | * Name : CreateDirectoryA
|
|---|
| 196 | * Purpose :
|
|---|
| 197 | * Parameters:
|
|---|
| 198 | * Variables :
|
|---|
| 199 | * Result :
|
|---|
| 200 | * Remark :
|
|---|
| 201 | * Status :
|
|---|
| 202 | *
|
|---|
| 203 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 204 | *****************************************************************************/
|
|---|
| 205 |
|
|---|
| 206 | ODINFUNCTION2(BOOL,CreateDirectoryA,LPCSTR, arg1,PSECURITY_ATTRIBUTES,arg2)
|
|---|
| 207 | {
|
|---|
| 208 | int len = strlen(arg1);
|
|---|
| 209 | char *tmp=(char *)alloca(len + 1);
|
|---|
| 210 |
|
|---|
| 211 | strcpy(tmp, arg1);
|
|---|
| 212 | if(tmp[len -1] == '\\')
|
|---|
| 213 | tmp[len -1] = 0;
|
|---|
| 214 | return O32_CreateDirectory(tmp, arg2);
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | /*****************************************************************************
|
|---|
| 218 | * Name : CreateDirectoryW
|
|---|
| 219 | * Purpose :
|
|---|
| 220 | * Parameters:
|
|---|
| 221 | * Variables :
|
|---|
| 222 | * Result :
|
|---|
| 223 | * Remark :
|
|---|
| 224 | * Status :
|
|---|
| 225 | *
|
|---|
| 226 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 227 | *****************************************************************************/
|
|---|
| 228 |
|
|---|
| 229 | ODINFUNCTION2(BOOL,CreateDirectoryW,LPCWSTR, arg1,
|
|---|
| 230 | PSECURITY_ATTRIBUTES,arg2)
|
|---|
| 231 | {
|
|---|
| 232 | BOOL rc;
|
|---|
| 233 | char *astring;
|
|---|
| 234 |
|
|---|
| 235 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 236 | rc = CreateDirectoryA(astring, arg2);
|
|---|
| 237 | FreeAsciiString(astring);
|
|---|
| 238 | return(rc);
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 | /*****************************************************************************
|
|---|
| 243 | * Name : GetSystemDirectoryA
|
|---|
| 244 | * Purpose :
|
|---|
| 245 | * Parameters:
|
|---|
| 246 | * Variables :
|
|---|
| 247 | * Result :
|
|---|
| 248 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
|---|
| 249 | * Status :
|
|---|
| 250 | *
|
|---|
| 251 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 252 | *****************************************************************************/
|
|---|
| 253 |
|
|---|
| 254 | ODINFUNCTION2(UINT,GetSystemDirectoryA,LPSTR,lpBuffer,
|
|---|
| 255 | UINT,uSize)
|
|---|
| 256 | {
|
|---|
| 257 | int len;
|
|---|
| 258 | char *dir;
|
|---|
| 259 |
|
|---|
| 260 | dir = InternalGetSystemDirectoryA();
|
|---|
| 261 | len = lstrlenA(dir);
|
|---|
| 262 | if(lpBuffer)
|
|---|
| 263 | lstrcpynA(lpBuffer, dir, uSize);
|
|---|
| 264 | return len;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 | /*****************************************************************************
|
|---|
| 269 | * Name : GetSystemDirectoryW
|
|---|
| 270 | * Purpose :
|
|---|
| 271 | * Parameters:
|
|---|
| 272 | * Variables :
|
|---|
| 273 | * Result :
|
|---|
| 274 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
|---|
| 275 | * Status :
|
|---|
| 276 | *
|
|---|
| 277 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 278 | *****************************************************************************/
|
|---|
| 279 |
|
|---|
| 280 | ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
|
|---|
| 281 | UINT, uSize)
|
|---|
| 282 | {
|
|---|
| 283 | char *asciibuffer = NULL;
|
|---|
| 284 | UINT rc;
|
|---|
| 285 |
|
|---|
| 286 | if(lpBuffer)
|
|---|
| 287 | asciibuffer = (char *)alloca(uSize+1);
|
|---|
| 288 |
|
|---|
| 289 | if(lpBuffer && asciibuffer == NULL) {
|
|---|
| 290 | DebugInt3();
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | rc = GetSystemDirectoryA(asciibuffer, uSize);
|
|---|
| 294 | if(rc && asciibuffer)
|
|---|
| 295 | AsciiToUnicode(asciibuffer, lpBuffer);
|
|---|
| 296 |
|
|---|
| 297 | return(rc);
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 | /*****************************************************************************
|
|---|
| 302 | * Name : GetWindowsDirectoryA
|
|---|
| 303 | * Purpose :
|
|---|
| 304 | * Parameters:
|
|---|
| 305 | * Variables :
|
|---|
| 306 | * Result :
|
|---|
| 307 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
|---|
| 308 | * Status :
|
|---|
| 309 | *
|
|---|
| 310 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 311 | *****************************************************************************/
|
|---|
| 312 |
|
|---|
| 313 | ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
|
|---|
| 314 | UINT,uSize)
|
|---|
| 315 | {
|
|---|
| 316 | char *dir;
|
|---|
| 317 | int len;
|
|---|
| 318 |
|
|---|
| 319 | dir = InternalGetWindowsDirectoryA();
|
|---|
| 320 | len = lstrlenA(dir);
|
|---|
| 321 | if(lpBuffer)
|
|---|
| 322 | lstrcpynA(lpBuffer, dir, uSize);
|
|---|
| 323 | return len;
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 | /*****************************************************************************
|
|---|
| 328 | * Name : GetWindowsDirectoryW
|
|---|
| 329 | * Purpose :
|
|---|
| 330 | * Parameters:
|
|---|
| 331 | * Variables :
|
|---|
| 332 | * Result :
|
|---|
| 333 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
|---|
| 334 | * Status :
|
|---|
| 335 | *
|
|---|
| 336 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 337 | *****************************************************************************/
|
|---|
| 338 |
|
|---|
| 339 | ODINFUNCTION2(UINT,GetWindowsDirectoryW,LPWSTR,lpBuffer,
|
|---|
| 340 | UINT, uSize)
|
|---|
| 341 | {
|
|---|
| 342 | char *asciibuffer = NULL;
|
|---|
| 343 | UINT rc;
|
|---|
| 344 |
|
|---|
| 345 | if(lpBuffer)
|
|---|
| 346 | asciibuffer = (char *)alloca(uSize+1);
|
|---|
| 347 |
|
|---|
| 348 | if(lpBuffer && asciibuffer == NULL) {
|
|---|
| 349 | DebugInt3();
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | rc = GetWindowsDirectoryA(asciibuffer, uSize);
|
|---|
| 353 | if(rc && asciibuffer)
|
|---|
| 354 | AsciiToUnicode(asciibuffer, lpBuffer);
|
|---|
| 355 |
|
|---|
| 356 | return(rc);
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 | /*****************************************************************************
|
|---|
| 361 | * Name : RemoveDirectoryA
|
|---|
| 362 | * Purpose :
|
|---|
| 363 | * Parameters:
|
|---|
| 364 | * Variables :
|
|---|
| 365 | * Result :
|
|---|
| 366 | * Remark :
|
|---|
| 367 | * Status :
|
|---|
| 368 | *
|
|---|
| 369 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 370 | *****************************************************************************/
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 | ODINFUNCTION1(BOOL,RemoveDirectoryA,LPCSTR,arg1)
|
|---|
| 374 | {
|
|---|
| 375 | int len = strlen(arg1);
|
|---|
| 376 | char *tmp=(char *)alloca(len + 1);
|
|---|
| 377 |
|
|---|
| 378 | strcpy(tmp, arg1);
|
|---|
| 379 | if(tmp[len -1] == '\\')
|
|---|
| 380 | tmp[len -1] = 0;
|
|---|
| 381 |
|
|---|
| 382 | dprintf(("RemoveDirectory %S", arg1));
|
|---|
| 383 |
|
|---|
| 384 | return O32_RemoveDirectory(tmp);
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | /*****************************************************************************
|
|---|
| 389 | * Name : RemoveDirectoryW
|
|---|
| 390 | * Purpose :
|
|---|
| 391 | * Parameters:
|
|---|
| 392 | * Variables :
|
|---|
| 393 | * Result :
|
|---|
| 394 | * Remark :
|
|---|
| 395 | * Status :
|
|---|
| 396 | *
|
|---|
| 397 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 398 | *****************************************************************************/
|
|---|
| 399 |
|
|---|
| 400 | ODINFUNCTION1(BOOL,RemoveDirectoryW,LPCWSTR,lpPathName)
|
|---|
| 401 | {
|
|---|
| 402 | char *asciipath;
|
|---|
| 403 | BOOL rc;
|
|---|
| 404 |
|
|---|
| 405 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
|---|
| 406 | rc = RemoveDirectoryA(asciipath);
|
|---|
| 407 | FreeAsciiString(asciipath);
|
|---|
| 408 | return(rc);
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 | /***********************************************************************
|
|---|
| 412 | * DIR_TryModulePath
|
|---|
| 413 | *
|
|---|
| 414 | * Helper function for DIR_SearchPath.
|
|---|
| 415 | */
|
|---|
| 416 | static BOOL DIR_TryModulePath( LPCSTR name, char *full_name )
|
|---|
| 417 | {
|
|---|
| 418 | char buffer[OFS_MAXPATHNAME];
|
|---|
| 419 | LPSTR p;
|
|---|
| 420 |
|
|---|
| 421 | if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
|
|---|
| 422 | buffer[0]='\0';
|
|---|
| 423 |
|
|---|
| 424 | if (!(p = strrchr( buffer, '\\' ))) return FALSE;
|
|---|
| 425 | if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
|
|---|
| 426 | strcpy( p, name );
|
|---|
| 427 |
|
|---|
| 428 | return OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, buffer, full_name, MAX_PATHNAME_LEN);
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 | /***********************************************************************
|
|---|
| 433 | * DIR_SearchPath
|
|---|
| 434 | *
|
|---|
| 435 | * Implementation of SearchPath32A. 'win32' specifies whether the search
|
|---|
| 436 | * order is Win16 (module path last) or Win32 (module path first).
|
|---|
| 437 | *
|
|---|
| 438 | * FIXME: should return long path names.
|
|---|
| 439 | */
|
|---|
| 440 | DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
|---|
| 441 | char *full_name )
|
|---|
| 442 | {
|
|---|
| 443 | DWORD len;
|
|---|
| 444 | LPCSTR p;
|
|---|
| 445 | LPSTR tmp = NULL;
|
|---|
| 446 | BOOL ret = TRUE;
|
|---|
| 447 |
|
|---|
| 448 | /* First check the supplied parameters */
|
|---|
| 449 |
|
|---|
| 450 | p = strrchr( name, '.' );
|
|---|
| 451 | if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
|
|---|
| 452 | ext = NULL; /* Ignore the specified extension */
|
|---|
| 453 | if ((*name && (name[1] == ':')) ||
|
|---|
| 454 | strchr( name, '/' ) || strchr( name, '\\' ))
|
|---|
| 455 | path = NULL; /* Ignore path if name already contains a path */
|
|---|
| 456 | if (path && !*path) path = NULL; /* Ignore empty path */
|
|---|
| 457 |
|
|---|
| 458 | len = strlen(name);
|
|---|
| 459 | if (ext) len += strlen(ext);
|
|---|
| 460 | if (path) len += strlen(path) + 1;
|
|---|
| 461 |
|
|---|
| 462 | /* Allocate a buffer for the file name and extension */
|
|---|
| 463 |
|
|---|
| 464 | if (path || ext)
|
|---|
| 465 | {
|
|---|
| 466 | if (!(tmp = (LPSTR)HeapAlloc( GetProcessHeap(), 0, len + 1 )))
|
|---|
| 467 | {
|
|---|
| 468 | SetLastError( ERROR_OUTOFMEMORY );
|
|---|
| 469 | return 0;
|
|---|
| 470 | }
|
|---|
| 471 | if (path)
|
|---|
| 472 | {
|
|---|
| 473 | strcpy( tmp, path );
|
|---|
| 474 | strcat( tmp, "\\" );
|
|---|
| 475 | strcat( tmp, name );
|
|---|
| 476 | }
|
|---|
| 477 | else strcpy( tmp, name );
|
|---|
| 478 | if (ext) strcat( tmp, ext );
|
|---|
| 479 | name = tmp;
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | /* If we have an explicit path, everything's easy */
|
|---|
| 483 |
|
|---|
| 484 | if (path || (*name && (name[1] == ':')) ||
|
|---|
| 485 | strchr( name, '/' ) || strchr( name, '\\' ))
|
|---|
| 486 | {
|
|---|
| 487 | ret = OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
|---|
| 488 | goto done;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | /* Try the path of the current executable (for Win32 search order) */
|
|---|
| 492 | if (DIR_TryModulePath( name, full_name )) goto done;
|
|---|
| 493 |
|
|---|
| 494 | /* Try the current directory */
|
|---|
| 495 | if (OSLibDosSearchPath(OSLIB_SEARCHCURDIR, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
|---|
| 496 | goto done;
|
|---|
| 497 |
|
|---|
| 498 | /* Try the Windows system directory */
|
|---|
| 499 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_System, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
|---|
| 500 | goto done;
|
|---|
| 501 |
|
|---|
| 502 | /* Try the Windows directory */
|
|---|
| 503 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_Windows, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
|---|
| 504 | goto done;
|
|---|
| 505 |
|
|---|
| 506 | /* Try all directories in path */
|
|---|
| 507 | ret = OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
|---|
| 508 |
|
|---|
| 509 | done:
|
|---|
| 510 | if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
|
|---|
| 511 | return ret;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 | /***********************************************************************
|
|---|
| 516 | * SearchPath32A [KERNEL32.447]
|
|---|
| 517 | *
|
|---|
| 518 | * Searches for a specified file in the search path.
|
|---|
| 519 | *
|
|---|
| 520 | * PARAMS
|
|---|
| 521 | * path [I] Path to search
|
|---|
| 522 | * name [I] Filename to search for.
|
|---|
| 523 | * ext [I] File extension to append to file name. The first
|
|---|
| 524 | * character must be a period. This parameter is
|
|---|
| 525 | * specified only if the filename given does not
|
|---|
| 526 | * contain an extension.
|
|---|
| 527 | * buflen [I] size of buffer, in characters
|
|---|
| 528 | * buffer [O] buffer for found filename
|
|---|
| 529 | * lastpart [O] address of pointer to last used character in
|
|---|
| 530 | * buffer (the final '\')
|
|---|
| 531 | *
|
|---|
| 532 | * RETURNS
|
|---|
| 533 | * Success: length of string copied into buffer, not including
|
|---|
| 534 | * terminating null character. If the filename found is
|
|---|
| 535 | * longer than the length of the buffer, the length of the
|
|---|
| 536 | * filename is returned.
|
|---|
| 537 | * Failure: Zero
|
|---|
| 538 | *
|
|---|
| 539 | * NOTES
|
|---|
| 540 | * Should call SetLastError(but currently doesn't).
|
|---|
| 541 | */
|
|---|
| 542 | DWORD WINAPI SearchPathA(LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
|
|---|
| 543 | LPSTR buffer, LPSTR *lastpart )
|
|---|
| 544 | {
|
|---|
| 545 | char full_name[MAX_PATHNAME_LEN];
|
|---|
| 546 |
|
|---|
| 547 | if (!DIR_SearchPath( path, name, ext, (LPSTR)full_name )) return 0;
|
|---|
| 548 | lstrcpynA( buffer, (LPSTR)full_name, buflen-1);
|
|---|
| 549 | buffer[buflen-2] = 0;
|
|---|
| 550 | SetLastError(0);
|
|---|
| 551 | return strlen(buffer);
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 | /***********************************************************************
|
|---|
| 556 | * SearchPath32W (KERNEL32.448)
|
|---|
| 557 | */
|
|---|
| 558 | DWORD WINAPI SearchPathW(LPCWSTR path, LPCWSTR name, LPCWSTR ext,
|
|---|
| 559 | DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
|
|---|
| 560 | {
|
|---|
| 561 | char full_name[MAX_PATHNAME_LEN];
|
|---|
| 562 |
|
|---|
| 563 | LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
|
|---|
| 564 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
|
|---|
| 565 | LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
|
|---|
| 566 | DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name );
|
|---|
| 567 | HeapFree( GetProcessHeap(), 0, extA );
|
|---|
| 568 | HeapFree( GetProcessHeap(), 0, nameA );
|
|---|
| 569 | HeapFree( GetProcessHeap(), 0, pathA );
|
|---|
| 570 | if (!ret) return 0;
|
|---|
| 571 |
|
|---|
| 572 | lstrcpynAtoW( buffer, full_name, buflen-1 );
|
|---|
| 573 | buffer[buflen-2] = 0;
|
|---|
| 574 | SetLastError(0);
|
|---|
| 575 | return strlen(full_name);
|
|---|
| 576 | }
|
|---|