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