[9597] | 1 | /* $Id: directory.cpp,v 1.47 2003-01-03 16:34:33 sandervl Exp $ */
|
---|
[100] | 2 |
|
---|
[4] | 3 | /*
|
---|
| 4 | * Win32 Directory functions for OS/2
|
---|
| 5 | *
|
---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
---|
| 7 | *
|
---|
[21916] | 8 | * NOTE: Directory creation has to be done in install program (odin\win)
|
---|
[3005] | 9 | *
|
---|
[1628] | 10 | * Parts based on Wine code (991031) (files\directory.c)
|
---|
[46] | 11 | *
|
---|
[1628] | 12 | * DOS directories functions
|
---|
| 13 | *
|
---|
| 14 | * Copyright 1995 Alexandre Julliard
|
---|
| 15 | *
|
---|
[21916] | 16 | * TODO:
|
---|
[3693] | 17 | * - System/window directories should be created by install program!
|
---|
[3375] | 18 | *
|
---|
[46] | 19 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 20 | *
|
---|
[4] | 21 | */
|
---|
[1076] | 22 |
|
---|
| 23 |
|
---|
| 24 | /*****************************************************************************
|
---|
| 25 | * Includes *
|
---|
| 26 | *****************************************************************************/
|
---|
| 27 |
|
---|
| 28 | #include <odin.h>
|
---|
| 29 | #include <odinwrap.h>
|
---|
[4] | 30 | #include <os2win.h>
|
---|
| 31 | #include <stdlib.h>
|
---|
[21916] | 32 | #include <string.h>
|
---|
| 33 | #ifdef __GNUC__
|
---|
| 34 | #include <alloca.h>
|
---|
| 35 | #endif
|
---|
[1076] | 36 | #include <unicode.h>
|
---|
| 37 | #include <heapstring.h>
|
---|
[1370] | 38 | #include <options.h>
|
---|
[1410] | 39 | #include "initterm.h"
|
---|
[21916] | 40 | #include <win/file.h>
|
---|
[1628] | 41 | #include "oslibdos.h"
|
---|
[1833] | 42 | #include "profile.h"
|
---|
[6511] | 43 | #include "fileio.h"
|
---|
[4] | 44 |
|
---|
[2802] | 45 | #define DBG_LOCALLOG DBG_directory
|
---|
| 46 | #include "dbglocal.h"
|
---|
| 47 |
|
---|
[1076] | 48 | ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
|
---|
| 49 |
|
---|
| 50 |
|
---|
[3694] | 51 | /*****************************************************************************
|
---|
| 52 | * Local Prototypes *
|
---|
| 53 | *****************************************************************************/
|
---|
| 54 |
|
---|
| 55 |
|
---|
[1628] | 56 | static char DIR_Windows[MAX_PATHNAME_LEN];
|
---|
| 57 | static char DIR_System[MAX_PATHNAME_LEN];
|
---|
[7063] | 58 | static BOOL fDirInit = FALSE;
|
---|
[1628] | 59 |
|
---|
| 60 | //******************************************************************************
|
---|
| 61 | //******************************************************************************
|
---|
[2044] | 62 | char *InternalGetWindowsDirectoryA()
|
---|
| 63 | {
|
---|
| 64 | return DIR_Windows;
|
---|
| 65 | }
|
---|
| 66 | //******************************************************************************
|
---|
| 67 | //******************************************************************************
|
---|
| 68 | char *InternalGetSystemDirectoryA()
|
---|
| 69 | {
|
---|
| 70 | return DIR_System;
|
---|
| 71 | }
|
---|
| 72 | //******************************************************************************
|
---|
| 73 | //******************************************************************************
|
---|
[1628] | 74 | void InitDirectories()
|
---|
| 75 | {
|
---|
[3461] | 76 | char *endofwinpath, *tmp;
|
---|
| 77 | int len;
|
---|
| 78 |
|
---|
[7063] | 79 | if(fDirInit == TRUE) return;
|
---|
| 80 |
|
---|
| 81 | fDirInit = TRUE;
|
---|
[3461] | 82 | strcpy(DIR_System, kernel32Path);
|
---|
| 83 | len = strlen(DIR_System);
|
---|
| 84 | if(DIR_System[len-1] == '\\') {
|
---|
[21916] | 85 | DIR_System[len-1] = 0;
|
---|
[3461] | 86 | }
|
---|
[4387] | 87 | len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",DIR_Windows,sizeof(DIR_Windows));
|
---|
[3461] | 88 | if (len > 2) {
|
---|
| 89 | if(DIR_Windows[len-1] == '\\') {
|
---|
[21916] | 90 | DIR_Windows[len-1] = 0;
|
---|
[3461] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | else {
|
---|
| 94 | strcpy(DIR_Windows, DIR_System);
|
---|
| 95 | endofwinpath = tmp = strchr(DIR_Windows, '\\');
|
---|
| 96 | while(tmp) {
|
---|
| 97 | tmp = strchr(endofwinpath+1, '\\');
|
---|
| 98 | if(tmp)
|
---|
| 99 | endofwinpath = tmp;
|
---|
| 100 | }
|
---|
| 101 | if(endofwinpath) {
|
---|
| 102 | *endofwinpath = 0; //remove \SYSTEM32
|
---|
| 103 | }
|
---|
| 104 | else DebugInt3();
|
---|
| 105 | }
|
---|
[4847] | 106 | dprintf(("Windows dir: %s", DIR_Windows));
|
---|
| 107 | dprintf(("System32 dir: %s", DIR_System));
|
---|
[1628] | 108 | }
|
---|
[7063] | 109 | //*****************************************************************************
|
---|
| 110 | //*****************************************************************************
|
---|
[9597] | 111 | void WIN32API InitDirectoriesCustom(char *szSystemDir, char *szWindowsDir)
|
---|
[7063] | 112 | {
|
---|
| 113 | int len;
|
---|
| 114 |
|
---|
| 115 | if(fDirInit == TRUE) return;
|
---|
| 116 | fDirInit = TRUE;
|
---|
| 117 |
|
---|
| 118 | strcpy(DIR_System, szSystemDir);
|
---|
| 119 | len = strlen(DIR_System);
|
---|
| 120 | if(DIR_System[len-1] == '\\') {
|
---|
[21916] | 121 | DIR_System[len-1] = 0;
|
---|
[7063] | 122 | }
|
---|
| 123 | strcpy(DIR_Windows, szWindowsDir);
|
---|
| 124 | len = strlen(DIR_Windows);
|
---|
| 125 | if(DIR_Windows[len-1] == '\\') {
|
---|
[21916] | 126 | DIR_Windows[len-1] = 0;
|
---|
[7063] | 127 | }
|
---|
| 128 |
|
---|
| 129 | dprintf(("Windows dir: %s", DIR_Windows));
|
---|
| 130 | dprintf(("System32 dir: %s", DIR_System));
|
---|
| 131 | }
|
---|
[1076] | 132 | /*****************************************************************************
|
---|
| 133 | * Name : GetCurrentDirectoryA
|
---|
| 134 | * Purpose : query the current directory
|
---|
| 135 | * Parameters:
|
---|
| 136 | * Variables :
|
---|
| 137 | * Result :
|
---|
[4473] | 138 | * Remark : returned length is number of characters required or used for current dir
|
---|
| 139 | * *excluding* terminator
|
---|
[1076] | 140 | * Status :
|
---|
| 141 | *
|
---|
| 142 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 143 | *****************************************************************************/
|
---|
| 144 |
|
---|
[7849] | 145 | UINT WIN32API GetCurrentDirectoryA(UINT nBufferLength, LPSTR lpBuffer)
|
---|
[4] | 146 | {
|
---|
[4445] | 147 | UINT rc;
|
---|
| 148 |
|
---|
[4473] | 149 | rc = OSLibDosQueryDir(nBufferLength, lpBuffer);
|
---|
| 150 | if(rc && rc < nBufferLength) {
|
---|
[21916] | 151 | dprintf(("CurrentDirectory = %s (%d)", lpBuffer, rc));
|
---|
[4445] | 152 | }
|
---|
[21916] | 153 | else dprintf(("CurrentDirectory returned %d", rc));
|
---|
[4445] | 154 | return rc;
|
---|
[4] | 155 | }
|
---|
[1076] | 156 |
|
---|
| 157 |
|
---|
| 158 | /*****************************************************************************
|
---|
| 159 | * Name : GetCurrentDirectoryW
|
---|
| 160 | * Purpose : query the current directory
|
---|
| 161 | * Parameters:
|
---|
| 162 | * Variables :
|
---|
| 163 | * Result :
|
---|
| 164 | * Remark :
|
---|
| 165 | * Status :
|
---|
| 166 | *
|
---|
| 167 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 168 | *****************************************************************************/
|
---|
| 169 |
|
---|
[7849] | 170 | UINT WIN32API GetCurrentDirectoryW(UINT nBufferLength, LPWSTR lpBuffer)
|
---|
[4] | 171 | {
|
---|
[1076] | 172 | char *asciidir = (char *)malloc(nBufferLength+1);
|
---|
| 173 | int rc;
|
---|
[4] | 174 |
|
---|
[7849] | 175 | rc = GetCurrentDirectoryA(nBufferLength, asciidir);
|
---|
[1076] | 176 | if(rc != 0)
|
---|
| 177 | AsciiToUnicode(asciidir, lpBuffer);
|
---|
| 178 | free(asciidir);
|
---|
| 179 | return(rc);
|
---|
[4] | 180 | }
|
---|
| 181 |
|
---|
[1076] | 182 |
|
---|
| 183 | /*****************************************************************************
|
---|
| 184 | * Name : SetCurrentDirectoryA
|
---|
| 185 | * Purpose :
|
---|
| 186 | * Parameters:
|
---|
| 187 | * Variables :
|
---|
| 188 | * Result :
|
---|
| 189 | * Remark :
|
---|
| 190 | * Status :
|
---|
| 191 | *
|
---|
| 192 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 193 | *****************************************************************************/
|
---|
[7849] | 194 | BOOL WIN32API SetCurrentDirectoryA(LPCSTR lpstrDirectory)
|
---|
[4] | 195 | {
|
---|
[3693] | 196 | if(HIWORD(lpstrDirectory) == 0)
|
---|
| 197 | {
|
---|
| 198 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 199 | return FALSE;
|
---|
[2232] | 200 | }
|
---|
[21916] | 201 |
|
---|
[3693] | 202 | // cut off trailing backslashes
|
---|
| 203 | // not if a process wants to change to the root directory
|
---|
| 204 | int len = lstrlenA(lpstrDirectory);
|
---|
| 205 | if ( ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
| 206 | (lpstrDirectory[len - 1] == '/') ) &&
|
---|
| 207 | (len != 1) )
|
---|
| 208 | {
|
---|
[21916] | 209 | LPSTR lpTemp = (LPSTR)alloca(len);
|
---|
[3699] | 210 | lstrcpynA(lpTemp,
|
---|
[3693] | 211 | lpstrDirectory,
|
---|
[3779] | 212 | len); // len is including trailing NULL!!
|
---|
[3699] | 213 | lpstrDirectory = lpTemp;
|
---|
[3642] | 214 | }
|
---|
[1708] | 215 |
|
---|
[3693] | 216 | dprintf(("SetCurrentDirectoryA %s", lpstrDirectory));
|
---|
| 217 | return O32_SetCurrentDirectory((LPSTR)lpstrDirectory);
|
---|
[4] | 218 | }
|
---|
[1076] | 219 |
|
---|
| 220 |
|
---|
| 221 | /*****************************************************************************
|
---|
| 222 | * Name : SetCurrentDirectoryW
|
---|
| 223 | * Purpose :
|
---|
| 224 | * Parameters:
|
---|
| 225 | * Variables :
|
---|
| 226 | * Result :
|
---|
| 227 | * Remark :
|
---|
| 228 | * Status :
|
---|
| 229 | *
|
---|
| 230 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 231 | *****************************************************************************/
|
---|
| 232 |
|
---|
[7849] | 233 | BOOL WIN32API SetCurrentDirectoryW(LPCWSTR lpPathName)
|
---|
[4] | 234 | {
|
---|
[1076] | 235 | char *asciipath;
|
---|
| 236 | BOOL rc;
|
---|
[4] | 237 |
|
---|
[1076] | 238 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
---|
| 239 | rc = SetCurrentDirectoryA(asciipath);
|
---|
| 240 | FreeAsciiString(asciipath);
|
---|
| 241 | return(rc);
|
---|
[4] | 242 | }
|
---|
[1076] | 243 |
|
---|
| 244 |
|
---|
| 245 | /*****************************************************************************
|
---|
| 246 | * Name : CreateDirectoryA
|
---|
| 247 | * Purpose :
|
---|
| 248 | * Parameters:
|
---|
| 249 | * Variables :
|
---|
| 250 | * Result :
|
---|
| 251 | * Remark :
|
---|
| 252 | * Status :
|
---|
| 253 | *
|
---|
| 254 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 255 | *****************************************************************************/
|
---|
| 256 |
|
---|
[7849] | 257 | BOOL WIN32API CreateDirectoryA(LPCSTR lpstrDirectory, PSECURITY_ATTRIBUTES arg2)
|
---|
[4] | 258 | {
|
---|
[5819] | 259 | // 2001-05-28 PH
|
---|
| 260 | // verify filename first (NT4SP6)
|
---|
| 261 | // @@@PH: if (IsBadStringPtr( (LPVOID)lpstrDirectory, 0xFFFF))
|
---|
| 262 | if (lpstrDirectory == NULL)
|
---|
| 263 | {
|
---|
| 264 | SetLastError(ERROR_PATH_NOT_FOUND);
|
---|
| 265 | return FALSE;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[3693] | 268 | int len = strlen(lpstrDirectory);
|
---|
[21916] | 269 |
|
---|
[3693] | 270 | // cut off trailing backslashes
|
---|
[3694] | 271 | if ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
| 272 | (lpstrDirectory[len - 1] == '/') )
|
---|
[3693] | 273 | {
|
---|
[21916] | 274 | LPSTR lpTemp = (LPSTR)alloca(len);
|
---|
[3699] | 275 | lstrcpynA(lpTemp,
|
---|
[3693] | 276 | lpstrDirectory,
|
---|
[3779] | 277 | len ); // len is including trailing NULL!!
|
---|
[3699] | 278 | lpstrDirectory = lpTemp;
|
---|
[3693] | 279 | }
|
---|
[21916] | 280 |
|
---|
[6094] | 281 | dprintf(("CreateDirectoryA %s", lpstrDirectory));
|
---|
[21916] | 282 |
|
---|
[21302] | 283 | // Creation of an existing directory will fail (verified in NT4 & XP)
|
---|
[3694] | 284 | DWORD dwAttr = GetFileAttributesA(lpstrDirectory);
|
---|
[21916] | 285 | if(dwAttr != -1)
|
---|
[6511] | 286 | {
|
---|
| 287 | if (dwAttr & FILE_ATTRIBUTE_DIRECTORY)
|
---|
| 288 | {
|
---|
[21302] | 289 | SetLastError(ERROR_ALREADY_EXISTS);
|
---|
| 290 | return FALSE;
|
---|
[6511] | 291 | }
|
---|
[21916] | 292 | }
|
---|
[6094] | 293 | return(OSLibDosCreateDirectory(lpstrDirectory));
|
---|
[4] | 294 | }
|
---|
[1076] | 295 |
|
---|
| 296 | /*****************************************************************************
|
---|
| 297 | * Name : CreateDirectoryW
|
---|
| 298 | * Purpose :
|
---|
| 299 | * Parameters:
|
---|
| 300 | * Variables :
|
---|
| 301 | * Result :
|
---|
| 302 | * Remark :
|
---|
| 303 | * Status :
|
---|
| 304 | *
|
---|
| 305 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 306 | *****************************************************************************/
|
---|
| 307 |
|
---|
[7849] | 308 | BOOL WIN32API CreateDirectoryW(LPCWSTR arg1, PSECURITY_ATTRIBUTES arg2)
|
---|
[4] | 309 | {
|
---|
[1076] | 310 | BOOL rc;
|
---|
| 311 | char *astring;
|
---|
[4] | 312 |
|
---|
[1076] | 313 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
[7849] | 314 | rc = CreateDirectoryA(astring, arg2);
|
---|
[1076] | 315 | FreeAsciiString(astring);
|
---|
| 316 | return(rc);
|
---|
[4] | 317 | }
|
---|
[1076] | 318 |
|
---|
[3799] | 319 | /*****************************************************************************
|
---|
| 320 | * Name : BOOL WIN32API CreateDirectoryExA
|
---|
| 321 | * Purpose : The CreateDirectoryExA function creates a new directory with a
|
---|
| 322 | * specified path that retains the attributes of a specified
|
---|
| 323 | * template directory. If the underlying file system supports
|
---|
| 324 | * security on files and directories, the function applies a
|
---|
| 325 | * specified security descriptor to the new directory.
|
---|
| 326 | * The new directory retains the other attributes of the specified
|
---|
| 327 | * template directory. Note that CreateDirectoryEx has a template
|
---|
| 328 | * parameter, while CreateDirectory does not.
|
---|
| 329 | * Parameters: LPCSTR lpTemplateDirectory pointer to path string of template
|
---|
| 330 | * directory
|
---|
| 331 | * LPCSTR lpNewDirectory pointer to path string of directory
|
---|
| 332 | * to create
|
---|
| 333 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
|
---|
| 334 | * descriptor
|
---|
| 335 | *
|
---|
| 336 | * Variables :
|
---|
| 337 | * Result : If the function succeeds, the return value is nonzero.
|
---|
| 338 | * If the function fails, the return value is zero.
|
---|
| 339 | * To get extended error information, call GetLastError.
|
---|
| 340 | * Remark :
|
---|
| 341 | * Status : UNTESTED STUB
|
---|
| 342 | *
|
---|
| 343 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
| 344 | *****************************************************************************/
|
---|
[1076] | 345 |
|
---|
[7342] | 346 | BOOL WIN32API CreateDirectoryExA( LPCSTR lpTemplateDirectory,
|
---|
| 347 | LPCSTR lpNewDirectory,
|
---|
| 348 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
[3799] | 349 | {
|
---|
| 350 |
|
---|
[7342] | 351 | dprintf(("KERNEL32:CreateDirectoryExA(%08x,%08x,%08x) not properly implemented\n",
|
---|
[3799] | 352 | lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
|
---|
| 353 | ));
|
---|
| 354 |
|
---|
| 355 | return CreateDirectoryA(lpNewDirectory, lpSecurityAttributes);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
[1076] | 358 | /*****************************************************************************
|
---|
[3799] | 359 | * Name : BOOL WIN32API CreateDirectoryExW
|
---|
| 360 | * Purpose : The CreateDirectoryExW function creates a new directory with a
|
---|
| 361 | * specified path that retains the attributes of a specified
|
---|
| 362 | * template directory. If the underlying file system supports
|
---|
| 363 | * security on files and directories, the function applies a
|
---|
| 364 | * specified security descriptor to the new directory.
|
---|
| 365 | * The new directory retains the other attributes of the specified
|
---|
| 366 | * template directory. Note that CreateDirectoryEx has a template
|
---|
| 367 | * parameter, while CreateDirectory does not.
|
---|
| 368 | * Parameters: LPCWSTR lpTemplateDirectory pointer to path string of template
|
---|
| 369 | * directory
|
---|
| 370 | * LPCWSTR lpNewDirectory pointer to path string of directory
|
---|
| 371 | * to create
|
---|
| 372 | * LPSECURITY_ATTRIBUTES lpSecurityAttributes pointer to security
|
---|
| 373 | * descriptor
|
---|
| 374 | *
|
---|
| 375 | * Variables :
|
---|
| 376 | * Result : If the function succeeds, the return value is nonzero.
|
---|
| 377 | * If the function fails, the return value is zero.
|
---|
| 378 | * To get extended error information, call GetLastError.
|
---|
| 379 | * Remark :
|
---|
| 380 | * Status : UNTESTED STUB
|
---|
| 381 | *
|
---|
| 382 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
| 383 | *****************************************************************************/
|
---|
| 384 |
|
---|
[7342] | 385 | BOOL WIN32API CreateDirectoryExW( LPCWSTR lpTemplateDirectory,
|
---|
| 386 | LPCWSTR lpNewDirectory,
|
---|
| 387 | LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
---|
[3799] | 388 | {
|
---|
| 389 |
|
---|
| 390 | dprintf(("KERNEL32:CreateDirectoryExW(%08x,%08x,%08x) not properly implemented\n",
|
---|
| 391 | lpTemplateDirectory,lpNewDirectory,lpSecurityAttributes
|
---|
| 392 | ));
|
---|
| 393 |
|
---|
| 394 | return CreateDirectoryW(lpNewDirectory, lpSecurityAttributes);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | /*****************************************************************************
|
---|
[1076] | 398 | * Name : GetSystemDirectoryA
|
---|
| 399 | * Purpose :
|
---|
| 400 | * Parameters:
|
---|
| 401 | * Variables :
|
---|
| 402 | * Result :
|
---|
[3347] | 403 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
[1076] | 404 | * Status :
|
---|
| 405 | *
|
---|
| 406 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 407 | *****************************************************************************/
|
---|
| 408 |
|
---|
[7849] | 409 | UINT WIN32API GetSystemDirectoryA(LPSTR lpBuffer, UINT uSize)
|
---|
[4] | 410 | {
|
---|
[3461] | 411 | int len;
|
---|
| 412 | char *dir;
|
---|
[1076] | 413 |
|
---|
[3461] | 414 | dir = InternalGetSystemDirectoryA();
|
---|
| 415 | len = lstrlenA(dir);
|
---|
[3347] | 416 | if(lpBuffer)
|
---|
[3461] | 417 | lstrcpynA(lpBuffer, dir, uSize);
|
---|
[1490] | 418 | return len;
|
---|
[4] | 419 | }
|
---|
[1076] | 420 |
|
---|
| 421 |
|
---|
| 422 | /*****************************************************************************
|
---|
| 423 | * Name : GetSystemDirectoryW
|
---|
| 424 | * Purpose :
|
---|
| 425 | * Parameters:
|
---|
| 426 | * Variables :
|
---|
| 427 | * Result :
|
---|
[3347] | 428 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
[1076] | 429 | * Status :
|
---|
| 430 | *
|
---|
| 431 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 432 | *****************************************************************************/
|
---|
| 433 |
|
---|
[7849] | 434 | UINT WIN32API GetSystemDirectoryW(LPWSTR lpBuffer, UINT uSize)
|
---|
[4] | 435 | {
|
---|
[3347] | 436 | char *asciibuffer = NULL;
|
---|
[1076] | 437 | UINT rc;
|
---|
[4] | 438 |
|
---|
[3347] | 439 | if(lpBuffer)
|
---|
[3693] | 440 | asciibuffer = (char *)alloca(uSize+1);
|
---|
[3347] | 441 |
|
---|
[21916] | 442 | if(lpBuffer && asciibuffer == NULL)
|
---|
[3693] | 443 | {
|
---|
| 444 | DebugInt3();
|
---|
[3461] | 445 | }
|
---|
| 446 |
|
---|
[1076] | 447 | rc = GetSystemDirectoryA(asciibuffer, uSize);
|
---|
[3347] | 448 | if(rc && asciibuffer)
|
---|
[3693] | 449 | AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
[21916] | 450 |
|
---|
[1076] | 451 | return(rc);
|
---|
[4] | 452 | }
|
---|
[1076] | 453 |
|
---|
| 454 |
|
---|
| 455 | /*****************************************************************************
|
---|
| 456 | * Name : GetWindowsDirectoryA
|
---|
| 457 | * Purpose :
|
---|
| 458 | * Parameters:
|
---|
| 459 | * Variables :
|
---|
| 460 | * Result :
|
---|
[3347] | 461 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
[1076] | 462 | * Status :
|
---|
| 463 | *
|
---|
| 464 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 465 | *****************************************************************************/
|
---|
| 466 |
|
---|
[7849] | 467 | UINT WIN32API GetWindowsDirectoryA(LPSTR lpBuffer, UINT uSize)
|
---|
[4] | 468 | {
|
---|
[3461] | 469 | char *dir;
|
---|
| 470 | int len;
|
---|
[1833] | 471 |
|
---|
[3461] | 472 | dir = InternalGetWindowsDirectoryA();
|
---|
| 473 | len = lstrlenA(dir);
|
---|
[3347] | 474 | if(lpBuffer)
|
---|
[3461] | 475 | lstrcpynA(lpBuffer, dir, uSize);
|
---|
[1833] | 476 | return len;
|
---|
[4] | 477 | }
|
---|
[1076] | 478 |
|
---|
| 479 |
|
---|
| 480 | /*****************************************************************************
|
---|
| 481 | * Name : GetWindowsDirectoryW
|
---|
| 482 | * Purpose :
|
---|
| 483 | * Parameters:
|
---|
| 484 | * Variables :
|
---|
| 485 | * Result :
|
---|
[3347] | 486 | * Remark : Should return length of system dir even if lpBuffer == NULL
|
---|
[1076] | 487 | * Status :
|
---|
| 488 | *
|
---|
| 489 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 490 | *****************************************************************************/
|
---|
| 491 |
|
---|
[7849] | 492 | UINT WIN32API GetWindowsDirectoryW(LPWSTR lpBuffer, UINT uSize)
|
---|
[4] | 493 | {
|
---|
[3347] | 494 | char *asciibuffer = NULL;
|
---|
[1076] | 495 | UINT rc;
|
---|
[4] | 496 |
|
---|
[3347] | 497 | if(lpBuffer)
|
---|
[3693] | 498 | asciibuffer = (char *)alloca(uSize+1);
|
---|
[3347] | 499 |
|
---|
[21916] | 500 | if(lpBuffer && asciibuffer == NULL)
|
---|
[3693] | 501 | {
|
---|
| 502 | DebugInt3();
|
---|
[3461] | 503 | }
|
---|
| 504 |
|
---|
[1076] | 505 | rc = GetWindowsDirectoryA(asciibuffer, uSize);
|
---|
[3347] | 506 | if(rc && asciibuffer)
|
---|
[3693] | 507 | AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
[21916] | 508 |
|
---|
[1076] | 509 | return(rc);
|
---|
[4] | 510 | }
|
---|
[1076] | 511 |
|
---|
| 512 |
|
---|
| 513 | /*****************************************************************************
|
---|
| 514 | * Name : RemoveDirectoryA
|
---|
| 515 | * Purpose :
|
---|
| 516 | * Parameters:
|
---|
| 517 | * Variables :
|
---|
| 518 | * Result :
|
---|
| 519 | * Remark :
|
---|
| 520 | * Status :
|
---|
| 521 | *
|
---|
| 522 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 523 | *****************************************************************************/
|
---|
| 524 |
|
---|
[1646] | 525 |
|
---|
[7849] | 526 | BOOL WIN32API RemoveDirectoryA(LPCSTR lpstrDirectory)
|
---|
[4] | 527 | {
|
---|
[3693] | 528 | int len = strlen(lpstrDirectory);
|
---|
[21916] | 529 |
|
---|
[6090] | 530 | if(lpstrDirectory == NULL) {
|
---|
| 531 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
| 532 | return FALSE;
|
---|
| 533 | }
|
---|
[3693] | 534 | // cut off trailing backslashes
|
---|
[3694] | 535 | if ( (lpstrDirectory[len - 1] == '\\') ||
|
---|
| 536 | (lpstrDirectory[len - 1] == '/') )
|
---|
[3693] | 537 | {
|
---|
[21916] | 538 | LPSTR lpTemp = (LPSTR)alloca(len);
|
---|
[3699] | 539 | lstrcpynA(lpTemp,
|
---|
[3693] | 540 | lpstrDirectory,
|
---|
[3779] | 541 | len ); // len is including trailing NULL!!
|
---|
[3699] | 542 | lpstrDirectory = lpTemp;
|
---|
[3693] | 543 | }
|
---|
[21916] | 544 |
|
---|
[6090] | 545 | dprintf(("RemoveDirectory %s", lpstrDirectory));
|
---|
[1646] | 546 |
|
---|
[6090] | 547 | return OSLibDosRemoveDir(lpstrDirectory);
|
---|
[4] | 548 | }
|
---|
[1076] | 549 |
|
---|
| 550 |
|
---|
| 551 | /*****************************************************************************
|
---|
| 552 | * Name : RemoveDirectoryW
|
---|
| 553 | * Purpose :
|
---|
| 554 | * Parameters:
|
---|
| 555 | * Variables :
|
---|
| 556 | * Result :
|
---|
| 557 | * Remark :
|
---|
| 558 | * Status :
|
---|
| 559 | *
|
---|
| 560 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
---|
| 561 | *****************************************************************************/
|
---|
| 562 |
|
---|
[7849] | 563 | BOOL WIN32API RemoveDirectoryW(LPCWSTR lpPathName)
|
---|
[4] | 564 | {
|
---|
[1076] | 565 | char *asciipath;
|
---|
| 566 | BOOL rc;
|
---|
[4] | 567 |
|
---|
[1076] | 568 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
---|
| 569 | rc = RemoveDirectoryA(asciipath);
|
---|
| 570 | FreeAsciiString(asciipath);
|
---|
| 571 | return(rc);
|
---|
[4] | 572 | }
|
---|
[1076] | 573 |
|
---|
[1628] | 574 | /***********************************************************************
|
---|
| 575 | * DIR_TryModulePath
|
---|
| 576 | *
|
---|
| 577 | * Helper function for DIR_SearchPath.
|
---|
| 578 | */
|
---|
| 579 | static BOOL DIR_TryModulePath( LPCSTR name, char *full_name )
|
---|
| 580 | {
|
---|
| 581 | char buffer[OFS_MAXPATHNAME];
|
---|
| 582 | LPSTR p;
|
---|
| 583 |
|
---|
| 584 | if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) ))
|
---|
| 585 | buffer[0]='\0';
|
---|
| 586 |
|
---|
| 587 | if (!(p = strrchr( buffer, '\\' ))) return FALSE;
|
---|
| 588 | if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE;
|
---|
| 589 | strcpy( p, name );
|
---|
| 590 |
|
---|
| 591 | return OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, buffer, full_name, MAX_PATHNAME_LEN);
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 |
|
---|
| 595 | /***********************************************************************
|
---|
| 596 | * DIR_SearchPath
|
---|
| 597 | *
|
---|
| 598 | * Implementation of SearchPath32A. 'win32' specifies whether the search
|
---|
| 599 | * order is Win16 (module path last) or Win32 (module path first).
|
---|
| 600 | *
|
---|
| 601 | * FIXME: should return long path names.
|
---|
| 602 | */
|
---|
| 603 | DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
---|
| 604 | char *full_name )
|
---|
| 605 | {
|
---|
| 606 | DWORD len;
|
---|
| 607 | LPCSTR p;
|
---|
| 608 | LPSTR tmp = NULL;
|
---|
| 609 | BOOL ret = TRUE;
|
---|
| 610 |
|
---|
| 611 | /* First check the supplied parameters */
|
---|
| 612 |
|
---|
| 613 | p = strrchr( name, '.' );
|
---|
| 614 | if (p && !strchr( p, '/' ) && !strchr( p, '\\' ))
|
---|
| 615 | ext = NULL; /* Ignore the specified extension */
|
---|
| 616 | if ((*name && (name[1] == ':')) ||
|
---|
| 617 | strchr( name, '/' ) || strchr( name, '\\' ))
|
---|
| 618 | path = NULL; /* Ignore path if name already contains a path */
|
---|
| 619 | if (path && !*path) path = NULL; /* Ignore empty path */
|
---|
| 620 |
|
---|
[4526] | 621 | /* See if path is a list of directories to search. If so, only search
|
---|
| 622 | those (according to SDK docs) */
|
---|
| 623 | if ((path != NULL) && strchr(path, ';')) {
|
---|
[21916] | 624 | ret = OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)path, (LPSTR)name,
|
---|
[4526] | 625 | full_name, MAX_PATHNAME_LEN);
|
---|
| 626 | goto done;
|
---|
| 627 | }
|
---|
| 628 |
|
---|
[1628] | 629 | len = strlen(name);
|
---|
| 630 | if (ext) len += strlen(ext);
|
---|
| 631 | if (path) len += strlen(path) + 1;
|
---|
| 632 |
|
---|
| 633 | /* Allocate a buffer for the file name and extension */
|
---|
| 634 |
|
---|
| 635 | if (path || ext)
|
---|
| 636 | {
|
---|
| 637 | if (!(tmp = (LPSTR)HeapAlloc( GetProcessHeap(), 0, len + 1 )))
|
---|
| 638 | {
|
---|
| 639 | SetLastError( ERROR_OUTOFMEMORY );
|
---|
| 640 | return 0;
|
---|
| 641 | }
|
---|
| 642 | if (path)
|
---|
| 643 | {
|
---|
| 644 | strcpy( tmp, path );
|
---|
| 645 | strcat( tmp, "\\" );
|
---|
| 646 | strcat( tmp, name );
|
---|
| 647 | }
|
---|
| 648 | else strcpy( tmp, name );
|
---|
| 649 | if (ext) strcat( tmp, ext );
|
---|
| 650 | name = tmp;
|
---|
| 651 | }
|
---|
[21916] | 652 |
|
---|
[1628] | 653 | /* If we have an explicit path, everything's easy */
|
---|
| 654 |
|
---|
| 655 | if (path || (*name && (name[1] == ':')) ||
|
---|
| 656 | strchr( name, '/' ) || strchr( name, '\\' ))
|
---|
| 657 | {
|
---|
| 658 | ret = OSLibDosSearchPath(OSLIB_SEARCHFILE, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
---|
| 659 | goto done;
|
---|
| 660 | }
|
---|
| 661 |
|
---|
| 662 | /* Try the path of the current executable (for Win32 search order) */
|
---|
| 663 | if (DIR_TryModulePath( name, full_name )) goto done;
|
---|
| 664 |
|
---|
| 665 | /* Try the current directory */
|
---|
| 666 | if (OSLibDosSearchPath(OSLIB_SEARCHCURDIR, NULL, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
| 667 | goto done;
|
---|
| 668 |
|
---|
| 669 | /* Try the Windows system directory */
|
---|
| 670 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_System, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
| 671 | goto done;
|
---|
| 672 |
|
---|
| 673 | /* Try the Windows directory */
|
---|
| 674 | if (OSLibDosSearchPath(OSLIB_SEARCHDIR, (LPSTR)&DIR_Windows, (LPSTR)name, full_name, MAX_PATHNAME_LEN))
|
---|
| 675 | goto done;
|
---|
| 676 |
|
---|
| 677 | /* Try all directories in path */
|
---|
| 678 | ret = OSLibDosSearchPath(OSLIB_SEARCHENV, "PATH", (LPSTR)name, full_name, MAX_PATHNAME_LEN);
|
---|
| 679 |
|
---|
| 680 | done:
|
---|
| 681 | if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
|
---|
| 682 | return ret;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 |
|
---|
| 686 | /***********************************************************************
|
---|
| 687 | * SearchPath32A [KERNEL32.447]
|
---|
| 688 | *
|
---|
| 689 | * Searches for a specified file in the search path.
|
---|
| 690 | *
|
---|
| 691 | * PARAMS
|
---|
| 692 | * path [I] Path to search
|
---|
| 693 | * name [I] Filename to search for.
|
---|
| 694 | * ext [I] File extension to append to file name. The first
|
---|
| 695 | * character must be a period. This parameter is
|
---|
| 696 | * specified only if the filename given does not
|
---|
| 697 | * contain an extension.
|
---|
| 698 | * buflen [I] size of buffer, in characters
|
---|
| 699 | * buffer [O] buffer for found filename
|
---|
| 700 | * lastpart [O] address of pointer to last used character in
|
---|
| 701 | * buffer (the final '\')
|
---|
| 702 | *
|
---|
| 703 | * RETURNS
|
---|
| 704 | * Success: length of string copied into buffer, not including
|
---|
| 705 | * terminating null character. If the filename found is
|
---|
| 706 | * longer than the length of the buffer, the length of the
|
---|
| 707 | * filename is returned.
|
---|
| 708 | * Failure: Zero
|
---|
[21916] | 709 | *
|
---|
[1628] | 710 | * NOTES
|
---|
| 711 | * Should call SetLastError(but currently doesn't).
|
---|
| 712 | */
|
---|
[7342] | 713 | DWORD WINAPI SearchPathA(LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen,
|
---|
| 714 | LPSTR buffer, LPSTR *lastpart )
|
---|
[1628] | 715 | {
|
---|
| 716 | char full_name[MAX_PATHNAME_LEN];
|
---|
| 717 |
|
---|
[7935] | 718 | dprintf(("SearchPathA %s %s %s", path, name, ext));
|
---|
[1628] | 719 | if (!DIR_SearchPath( path, name, ext, (LPSTR)full_name )) return 0;
|
---|
[3779] | 720 | lstrcpynA( buffer, (LPSTR)full_name, buflen);
|
---|
[1628] | 721 | SetLastError(0);
|
---|
[5303] | 722 | return strlen(full_name);
|
---|
[1628] | 723 | }
|
---|
| 724 |
|
---|
| 725 |
|
---|
| 726 | /***********************************************************************
|
---|
| 727 | * SearchPath32W (KERNEL32.448)
|
---|
| 728 | */
|
---|
[7342] | 729 | DWORD WINAPI SearchPathW(LPCWSTR path, LPCWSTR name, LPCWSTR ext,
|
---|
| 730 | DWORD buflen, LPWSTR buffer, LPWSTR *lastpart )
|
---|
[1628] | 731 | {
|
---|
| 732 | char full_name[MAX_PATHNAME_LEN];
|
---|
[7342] | 733 |
|
---|
[1628] | 734 | LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
|
---|
| 735 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
|
---|
| 736 | LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext );
|
---|
[21916] | 737 |
|
---|
[7935] | 738 | dprintf(("SearchPathA %s %s %s", pathA, nameA, extA));
|
---|
[1628] | 739 | DWORD ret = DIR_SearchPath( pathA, nameA, extA, (LPSTR)full_name );
|
---|
[21916] | 740 |
|
---|
[8327] | 741 | if (NULL != extA)
|
---|
| 742 | HeapFree( GetProcessHeap(), 0, extA );
|
---|
[21916] | 743 |
|
---|
[8327] | 744 | if (NULL != nameA)
|
---|
| 745 | HeapFree( GetProcessHeap(), 0, nameA );
|
---|
[21916] | 746 |
|
---|
[8327] | 747 | if (NULL != pathA)
|
---|
| 748 | HeapFree( GetProcessHeap(), 0, pathA );
|
---|
[21916] | 749 |
|
---|
[1628] | 750 | if (!ret) return 0;
|
---|
| 751 |
|
---|
[3779] | 752 | lstrcpynAtoW( buffer, full_name, buflen);
|
---|
[1628] | 753 | SetLastError(0);
|
---|
[5303] | 754 | return ret;
|
---|
[1628] | 755 | }
|
---|
[7798] | 756 | //******************************************************************************
|
---|
| 757 | //******************************************************************************
|
---|
[7849] | 758 | UINT WIN32API GetTempPathA(UINT count, LPSTR path)
|
---|
[7798] | 759 | {
|
---|
| 760 | UINT ret;
|
---|
| 761 | if (!(ret = GetEnvironmentVariableA( "TMP", path, count )))
|
---|
| 762 | if (!(ret = GetEnvironmentVariableA( "TEMP", path, count )))
|
---|
| 763 | if (!(ret = GetCurrentDirectoryA( count, path )))
|
---|
| 764 | return 0;
|
---|
| 765 | if (count && (ret < count - 1) && (path[ret-1] != '\\'))
|
---|
| 766 | {
|
---|
| 767 | path[ret++] = '\\';
|
---|
| 768 | path[ret] = '\0';
|
---|
| 769 | }
|
---|
| 770 | return ret;
|
---|
| 771 | }
|
---|
| 772 | //******************************************************************************
|
---|
| 773 | //******************************************************************************
|
---|
[7849] | 774 | UINT WIN32API GetTempPathW(UINT count, LPWSTR path)
|
---|
[7798] | 775 | {
|
---|
| 776 | static const WCHAR tmp[] = { 'T', 'M', 'P', 0 };
|
---|
| 777 | static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 };
|
---|
| 778 | UINT ret;
|
---|
| 779 | if (!(ret = GetEnvironmentVariableW( tmp, path, count )))
|
---|
| 780 | if (!(ret = GetEnvironmentVariableW( temp, path, count )))
|
---|
| 781 | if (!(ret = GetCurrentDirectoryW( count, path )))
|
---|
| 782 | return 0;
|
---|
| 783 | if (count && (ret < count - 1) && (path[ret-1] != '\\'))
|
---|
| 784 | {
|
---|
| 785 | path[ret++] = '\\';
|
---|
| 786 | path[ret] = '\0';
|
---|
| 787 | }
|
---|
| 788 | return ret;
|
---|
| 789 | }
|
---|
| 790 | //******************************************************************************
|
---|
| 791 | //******************************************************************************
|
---|