Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * DOS directories functions |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 23 | #include <ctype.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 26 | #include <string.h> |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 27 | #include <sys/types.h> |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 28 | #include <sys/stat.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 30 | #include <errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 31 | #ifdef HAVE_SYS_ERRNO_H |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 32 | #include <sys/errno.h> |
Howard Abrams | 1327748 | 1999-07-10 13:16:29 +0000 | [diff] [blame] | 33 | #endif |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 34 | |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 35 | #include "winbase.h" |
| 36 | #include "wine/winbase16.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 37 | #include "windef.h" |
| 38 | #include "wingdi.h" |
Patrik Stridvall | 1ed4ecf | 1999-06-26 14:58:24 +0000 | [diff] [blame] | 39 | #include "wine/winuser16.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 40 | #include "winerror.h" |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 41 | #include "winreg.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 42 | #include "drive.h" |
| 43 | #include "file.h" |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 44 | #include "heap.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 45 | #include "msdos.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 46 | #include "wine/debug.h" |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 48 | WINE_DEFAULT_DEBUG_CHANNEL(dosfs); |
| 49 | WINE_DECLARE_DEBUG_CHANNEL(file); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 50 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 51 | static DOS_FULL_NAME DIR_Windows; |
| 52 | static DOS_FULL_NAME DIR_System; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 53 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 54 | |
| 55 | /*********************************************************************** |
| 56 | * DIR_GetPath |
| 57 | * |
| 58 | * Get a path name from the wine.ini file and make sure it is valid. |
| 59 | */ |
| 60 | static int DIR_GetPath( const char *keyname, const char *defval, |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 61 | DOS_FULL_NAME *full_name, char * longname, BOOL warn ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 62 | { |
| 63 | char path[MAX_PATHNAME_LEN]; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 64 | BY_HANDLE_FILE_INFORMATION info; |
Lawson Whitney | 0348212 | 2000-12-14 20:30:13 +0000 | [diff] [blame] | 65 | const char *mess = "does not exist"; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 66 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 67 | PROFILE_GetWineIniString( "wine", keyname, defval, path, sizeof(path) ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 68 | if (!DOSFS_GetFullName( path, TRUE, full_name ) || |
Lawson Whitney | 0348212 | 2000-12-14 20:30:13 +0000 | [diff] [blame] | 69 | (!FILE_Stat( full_name->long_name, &info ) && (mess=strerror(errno)))|| |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 70 | (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (mess="not a directory")) || |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 71 | (!(GetLongPathNameA(full_name->short_name, longname, MAX_PATHNAME_LEN))) ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 72 | { |
Gerard Patel | d52e1c4 | 2001-02-16 19:05:42 +0000 | [diff] [blame] | 73 | if (warn) |
| 74 | MESSAGE("Invalid path '%s' for %s directory: %s\n", path, keyname, mess); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 75 | return 0; |
| 76 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | /*********************************************************************** |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 82 | * DIR_Init |
| 83 | */ |
| 84 | int DIR_Init(void) |
| 85 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 86 | char path[MAX_PATHNAME_LEN]; |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 87 | char longpath[MAX_PATHNAME_LEN]; |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame] | 88 | DOS_FULL_NAME tmp_dir, profile_dir; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 89 | int drive; |
| 90 | const char *cwd; |
| 91 | |
| 92 | if (!getcwd( path, MAX_PATHNAME_LEN )) |
| 93 | { |
| 94 | perror( "Could not get current directory" ); |
| 95 | return 0; |
| 96 | } |
| 97 | cwd = path; |
| 98 | if ((drive = DRIVE_FindDriveRoot( &cwd )) == -1) |
| 99 | { |
Chris Morgan | e405550 | 2001-01-12 19:55:19 +0000 | [diff] [blame] | 100 | MESSAGE("Warning: could not find wine config [Drive x] entry " |
Andreas Mohr | df8cdfd | 1999-02-28 16:56:48 +0000 | [diff] [blame] | 101 | "for current working directory %s; " |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 102 | "starting in windows directory.\n", cwd ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 103 | } |
| 104 | else |
| 105 | { |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 106 | DRIVE_SetCurrentDrive( drive ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 107 | DRIVE_Chdir( drive, cwd ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 110 | if (!(DIR_GetPath( "windows", "c:\\windows", &DIR_Windows, longpath, TRUE )) || |
| 111 | !(DIR_GetPath( "system", "c:\\windows\\system", &DIR_System, longpath, TRUE )) || |
| 112 | !(DIR_GetPath( "temp", "c:\\windows", &tmp_dir, longpath, TRUE ))) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 113 | { |
| 114 | PROFILE_UsageWineIni(); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 115 | return 0; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 116 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 117 | if (-1 == access( tmp_dir.long_name, W_OK )) |
| 118 | { |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 119 | if (errno==EACCES) |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 120 | { |
Andreas Mohr | a6d83eb | 2000-12-27 04:02:46 +0000 | [diff] [blame] | 121 | MESSAGE("Warning: the temporary directory '%s' (specified in wine configuration file) is not writeable.\n", tmp_dir.long_name); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 122 | PROFILE_UsageWineIni(); |
| 123 | } |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 124 | else |
Andreas Mohr | a6d83eb | 2000-12-27 04:02:46 +0000 | [diff] [blame] | 125 | MESSAGE("Warning: access to temporary directory '%s' failed (%s).\n", |
| 126 | tmp_dir.long_name, strerror(errno)); |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 127 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 128 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 129 | if (drive == -1) |
| 130 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 131 | drive = DIR_Windows.drive; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 132 | DRIVE_SetCurrentDrive( drive ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 133 | DRIVE_Chdir( drive, DIR_Windows.short_name + 2 ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 136 | PROFILE_GetWineIniString("wine", "path", "c:\\windows;c:\\windows\\system", |
| 137 | path, sizeof(path) ); |
Andreas Mohr | 0b16006 | 2000-01-26 02:04:09 +0000 | [diff] [blame] | 138 | if (strchr(path, '/')) |
| 139 | { |
Andreas Mohr | 9cef2d0 | 2001-11-19 02:30:01 +0000 | [diff] [blame] | 140 | MESSAGE("Fix your wine config to use DOS drive syntax in [wine] 'Path=' statement! (no '/' allowed)\n"); |
Andreas Mohr | 0b16006 | 2000-01-26 02:04:09 +0000 | [diff] [blame] | 141 | PROFILE_UsageWineIni(); |
| 142 | ExitProcess(1); |
| 143 | } |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 144 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 145 | /* Set the environment variables */ |
| 146 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 147 | SetEnvironmentVariableA( "PATH", path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 148 | SetEnvironmentVariableA( "TEMP", tmp_dir.short_name ); |
Dmitry Timoshkov | b6ac770 | 2000-12-24 20:01:12 +0000 | [diff] [blame] | 149 | SetEnvironmentVariableA( "TMP", tmp_dir.short_name ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 150 | SetEnvironmentVariableA( "windir", DIR_Windows.short_name ); |
| 151 | SetEnvironmentVariableA( "winsysdir", DIR_System.short_name ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 152 | |
Alexandre Julliard | 2e9f786 | 2000-08-01 23:34:01 +0000 | [diff] [blame] | 153 | /* set COMSPEC only if it doesn't exist already */ |
| 154 | if (!GetEnvironmentVariableA( "COMSPEC", NULL, 0 )) |
| 155 | SetEnvironmentVariableA( "COMSPEC", "c:\\command.com" ); |
| 156 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 157 | TRACE("WindowsDir = %s (%s)\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 158 | DIR_Windows.short_name, DIR_Windows.long_name ); |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 159 | TRACE("SystemDir = %s (%s)\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 160 | DIR_System.short_name, DIR_System.long_name ); |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 161 | TRACE("TempDir = %s (%s)\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 162 | tmp_dir.short_name, tmp_dir.long_name ); |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 163 | TRACE("Path = %s\n", path ); |
| 164 | TRACE("Cwd = %c:\\%s\n", |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 165 | 'A' + drive, DRIVE_GetDosCwd( drive ) ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 166 | |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 167 | if (DIR_GetPath( "profile", "", &profile_dir, longpath, FALSE )) |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame] | 168 | { |
Juergen Schmied | 6b27977 | 2002-05-09 19:35:22 +0000 | [diff] [blame] | 169 | TRACE("USERPROFILE= %s\n", longpath ); |
| 170 | SetEnvironmentVariableA( "USERPROFILE", longpath ); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 171 | } |
Juergen Schmied | 8573cc7 | 2000-01-30 03:03:23 +0000 | [diff] [blame] | 172 | |
| 173 | TRACE("SYSTEMROOT = %s\n", DIR_Windows.short_name ); |
| 174 | SetEnvironmentVariableA( "SYSTEMROOT", DIR_Windows.short_name ); |
| 175 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 176 | return 1; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 181 | * GetTempPathA (KERNEL32.@) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 182 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 183 | UINT WINAPI GetTempPathA( UINT count, LPSTR path ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 184 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 185 | UINT ret; |
| 186 | if (!(ret = GetEnvironmentVariableA( "TMP", path, count ))) |
| 187 | if (!(ret = GetEnvironmentVariableA( "TEMP", path, count ))) |
| 188 | if (!(ret = GetCurrentDirectoryA( count, path ))) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 189 | return 0; |
Huw D M Davies | a03f064 | 1998-12-15 18:04:58 +0000 | [diff] [blame] | 190 | if (count && (ret < count - 1) && (path[ret-1] != '\\')) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 191 | { |
| 192 | path[ret++] = '\\'; |
| 193 | path[ret] = '\0'; |
| 194 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 195 | return ret; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | |
| 199 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 200 | * GetTempPathW (KERNEL32.@) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 201 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 202 | UINT WINAPI GetTempPathW( UINT count, LPWSTR path ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 203 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 204 | static const WCHAR tmp[] = { 'T', 'M', 'P', 0 }; |
| 205 | static const WCHAR temp[] = { 'T', 'E', 'M', 'P', 0 }; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 206 | UINT ret; |
| 207 | if (!(ret = GetEnvironmentVariableW( tmp, path, count ))) |
| 208 | if (!(ret = GetEnvironmentVariableW( temp, path, count ))) |
| 209 | if (!(ret = GetCurrentDirectoryW( count, path ))) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 210 | return 0; |
Huw D M Davies | a03f064 | 1998-12-15 18:04:58 +0000 | [diff] [blame] | 211 | if (count && (ret < count - 1) && (path[ret-1] != '\\')) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 212 | { |
| 213 | path[ret++] = '\\'; |
| 214 | path[ret] = '\0'; |
| 215 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 216 | return ret; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | /*********************************************************************** |
| 221 | * DIR_GetWindowsUnixDir |
| 222 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 223 | UINT DIR_GetWindowsUnixDir( LPSTR path, UINT count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 224 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 225 | if (path) lstrcpynA( path, DIR_Windows.long_name, count ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 226 | return strlen( DIR_Windows.long_name ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
| 230 | /*********************************************************************** |
| 231 | * DIR_GetSystemUnixDir |
| 232 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 233 | UINT DIR_GetSystemUnixDir( LPSTR path, UINT count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 234 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 235 | if (path) lstrcpynA( path, DIR_System.long_name, count ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 236 | return strlen( DIR_System.long_name ); |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | |
| 240 | /*********************************************************************** |
| 241 | * GetTempDrive (KERNEL.92) |
Alexandre Julliard | ac7efef | 2000-11-27 21:54:01 +0000 | [diff] [blame] | 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 |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 249 | */ |
Alexandre Julliard | ac7efef | 2000-11-27 21:54:01 +0000 | [diff] [blame] | 250 | UINT WINAPI GetTempDrive( BYTE ignored ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 251 | { |
Uwe Bonnes | 3dbc788 | 1999-02-14 17:32:46 +0000 | [diff] [blame] | 252 | char *buffer; |
| 253 | BYTE ret; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 254 | UINT len = GetTempPathA( 0, NULL ); |
Uwe Bonnes | 3dbc788 | 1999-02-14 17:32:46 +0000 | [diff] [blame] | 255 | |
| 256 | if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len + 1 )) ) |
Alexandre Julliard | ac7efef | 2000-11-27 21:54:01 +0000 | [diff] [blame] | 257 | ret = DRIVE_GetCurrentDrive() + 'A'; |
| 258 | else |
| 259 | { |
| 260 | /* FIXME: apparently Windows does something with the ignored byte */ |
| 261 | if (!GetTempPathA( len, buffer )) buffer[0] = 'C'; |
| 262 | ret = toupper(buffer[0]); |
| 263 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 264 | } |
| 265 | return MAKELONG( ret | (':' << 8), 1 ); |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 268 | |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 269 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 270 | * GetWindowsDirectory (KERNEL.134) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 271 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 272 | UINT16 WINAPI GetWindowsDirectory16( LPSTR path, UINT16 count ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 273 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 274 | return (UINT16)GetWindowsDirectoryA( path, count ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | |
| 278 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 279 | * GetWindowsDirectoryA (KERNEL32.@) |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 280 | * |
| 281 | * See comment for GetWindowsDirectoryW. |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 282 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 283 | UINT WINAPI GetWindowsDirectoryA( LPSTR path, UINT count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 284 | { |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 285 | UINT len = strlen( DIR_Windows.short_name ) + 1; |
| 286 | if (path && count >= len) |
| 287 | { |
| 288 | strcpy( path, DIR_Windows.short_name ); |
| 289 | len--; |
| 290 | } |
| 291 | return len; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | |
| 295 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 296 | * GetWindowsDirectoryW (KERNEL32.@) |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 297 | * |
| 298 | * Return value: |
| 299 | * If buffer is large enough to hold full path and terminating '\0' character |
| 300 | * function copies path to buffer and returns length of the path without '\0'. |
| 301 | * Otherwise function returns required size including '\0' character and |
| 302 | * does not touch the buffer. |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 303 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 304 | UINT WINAPI GetWindowsDirectoryW( LPWSTR path, UINT count ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 305 | { |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 306 | UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, NULL, 0 ); |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 307 | if (path && count >= len) |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 308 | { |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 309 | MultiByteToWideChar( CP_ACP, 0, DIR_Windows.short_name, -1, path, count ); |
| 310 | len--; |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 311 | } |
| 312 | return len; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
| 316 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 317 | * GetSystemWindowsDirectoryA (KERNEL32.@) W2K, TS4.0SP4 |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 318 | */ |
| 319 | UINT WINAPI GetSystemWindowsDirectoryA( LPSTR path, UINT count ) |
| 320 | { |
| 321 | return GetWindowsDirectoryA( path, count ); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /*********************************************************************** |
Patrik Stridvall | 3ca9823 | 2001-06-20 23:03:14 +0000 | [diff] [blame] | 326 | * GetSystemWindowsDirectoryW (KERNEL32.@) W2K, TS4.0SP4 |
David Elliott | 44f84b5 | 2000-10-29 01:24:54 +0000 | [diff] [blame] | 327 | */ |
| 328 | UINT WINAPI GetSystemWindowsDirectoryW( LPWSTR path, UINT count ) |
| 329 | { |
| 330 | return GetWindowsDirectoryW( path, count ); |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 335 | * GetSystemDirectory (KERNEL.135) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 336 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 337 | UINT16 WINAPI GetSystemDirectory16( LPSTR path, UINT16 count ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 338 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 339 | return (UINT16)GetSystemDirectoryA( path, count ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | |
| 343 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 344 | * GetSystemDirectoryA (KERNEL32.@) |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 345 | * |
| 346 | * See comment for GetWindowsDirectoryW. |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 347 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 348 | UINT WINAPI GetSystemDirectoryA( LPSTR path, UINT count ) |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 349 | { |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 350 | UINT len = strlen( DIR_System.short_name ) + 1; |
| 351 | if (path && count >= len) |
| 352 | { |
| 353 | strcpy( path, DIR_System.short_name ); |
| 354 | len--; |
| 355 | } |
| 356 | return len; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 357 | } |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 358 | |
| 359 | |
| 360 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 361 | * GetSystemDirectoryW (KERNEL32.@) |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 362 | * |
| 363 | * See comment for GetWindowsDirectoryW. |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 364 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 365 | UINT WINAPI GetSystemDirectoryW( LPWSTR path, UINT count ) |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 366 | { |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 367 | UINT len = MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, NULL, 0 ); |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 368 | if (path && count >= len) |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 369 | { |
Dmitry Timoshkov | 4291e45 | 2002-01-18 18:53:11 +0000 | [diff] [blame] | 370 | MultiByteToWideChar( CP_ACP, 0, DIR_System.short_name, -1, path, count ); |
| 371 | len--; |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 372 | } |
| 373 | return len; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 374 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 375 | |
| 376 | |
| 377 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 378 | * CreateDirectory (KERNEL.144) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 379 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 380 | BOOL16 WINAPI CreateDirectory16( LPCSTR path, LPVOID dummy ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 381 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 382 | TRACE_(file)("(%s,%p)\n", path, dummy ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 383 | return (BOOL16)CreateDirectoryA( path, NULL ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | |
| 387 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 388 | * CreateDirectoryA (KERNEL32.@) |
Marcus Meissner | 412d025 | 1999-02-28 19:50:39 +0000 | [diff] [blame] | 389 | * RETURNS: |
| 390 | * TRUE : success |
| 391 | * FALSE : failure |
| 392 | * ERROR_DISK_FULL: on full disk |
| 393 | * ERROR_ALREADY_EXISTS: if directory name exists (even as file) |
| 394 | * ERROR_ACCESS_DENIED: on permission problems |
| 395 | * ERROR_FILENAME_EXCED_RANGE: too long filename(s) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 396 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 397 | BOOL WINAPI CreateDirectoryA( LPCSTR path, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 398 | LPSECURITY_ATTRIBUTES lpsecattribs ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 399 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 400 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 401 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 402 | TRACE_(file)("(%s,%p)\n", path, lpsecattribs ); |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 403 | if (DOSFS_GetDevice( path )) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 404 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 405 | TRACE_(file)("cannot use device '%s'!\n",path); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 406 | SetLastError( ERROR_ACCESS_DENIED ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 407 | return FALSE; |
| 408 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 409 | if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0; |
Marcus Meissner | 412d025 | 1999-02-28 19:50:39 +0000 | [diff] [blame] | 410 | if (mkdir( full_name.long_name, 0777 ) == -1) { |
Andreas Mohr | 8c2f4b1 | 2001-03-03 00:22:50 +0000 | [diff] [blame] | 411 | WARN_(file)("Error '%s' trying to create directory '%s'\n", strerror(errno), full_name.long_name); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 412 | /* the FILE_SetDosError() generated error codes don't match the |
Marcus Meissner | 412d025 | 1999-02-28 19:50:39 +0000 | [diff] [blame] | 413 | * CreateDirectory ones for some errnos */ |
| 414 | switch (errno) { |
| 415 | case EEXIST: SetLastError(ERROR_ALREADY_EXISTS); break; |
| 416 | case ENOSPC: SetLastError(ERROR_DISK_FULL); break; |
| 417 | default: FILE_SetDosError();break; |
| 418 | } |
| 419 | return FALSE; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 420 | } |
| 421 | return TRUE; |
| 422 | } |
| 423 | |
| 424 | |
| 425 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 426 | * CreateDirectoryW (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 427 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 428 | BOOL WINAPI CreateDirectoryW( LPCWSTR path, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 429 | LPSECURITY_ATTRIBUTES lpsecattribs ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 430 | { |
| 431 | LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 432 | BOOL ret = CreateDirectoryA( xpath, lpsecattribs ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 433 | HeapFree( GetProcessHeap(), 0, xpath ); |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | |
| 438 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 439 | * CreateDirectoryExA (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 440 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 441 | BOOL WINAPI CreateDirectoryExA( LPCSTR template, LPCSTR path, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 442 | LPSECURITY_ATTRIBUTES lpsecattribs) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 443 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 444 | return CreateDirectoryA(path,lpsecattribs); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | |
| 448 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 449 | * CreateDirectoryExW (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 450 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 451 | BOOL WINAPI CreateDirectoryExW( LPCWSTR template, LPCWSTR path, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 452 | LPSECURITY_ATTRIBUTES lpsecattribs) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 453 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 454 | return CreateDirectoryW(path,lpsecattribs); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
| 458 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 459 | * RemoveDirectory (KERNEL.145) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 460 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 461 | BOOL16 WINAPI RemoveDirectory16( LPCSTR path ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 462 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 463 | return (BOOL16)RemoveDirectoryA( path ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 468 | * RemoveDirectoryA (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 469 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 470 | BOOL WINAPI RemoveDirectoryA( LPCSTR path ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 471 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 472 | DOS_FULL_NAME full_name; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 473 | |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 474 | TRACE_(file)("'%s'\n", path ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 475 | |
Alexandre Julliard | 829fe32 | 1998-07-26 14:27:39 +0000 | [diff] [blame] | 476 | if (DOSFS_GetDevice( path )) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 477 | { |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 478 | TRACE_(file)("cannot remove device '%s'!\n", path); |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 479 | SetLastError( ERROR_FILE_NOT_FOUND ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 480 | return FALSE; |
| 481 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 482 | if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE; |
| 483 | if (rmdir( full_name.long_name ) == -1) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 484 | { |
| 485 | FILE_SetDosError(); |
| 486 | return FALSE; |
| 487 | } |
| 488 | return TRUE; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 493 | * RemoveDirectoryW (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 494 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 495 | BOOL WINAPI RemoveDirectoryW( LPCWSTR path ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 496 | { |
| 497 | LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 498 | BOOL ret = RemoveDirectoryA( xpath ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 499 | HeapFree( GetProcessHeap(), 0, xpath ); |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | /*********************************************************************** |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 505 | * DIR_TryPath |
| 506 | * |
| 507 | * Helper function for DIR_SearchPath. |
| 508 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 509 | static BOOL DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 510 | DOS_FULL_NAME *full_name ) |
| 511 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 512 | LPSTR p_l = full_name->long_name + strlen(dir->long_name) + 1; |
| 513 | LPSTR p_s = full_name->short_name + strlen(dir->short_name) + 1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 514 | |
| 515 | if ((p_s >= full_name->short_name + sizeof(full_name->short_name) - 14) || |
| 516 | (p_l >= full_name->long_name + sizeof(full_name->long_name) - 1)) |
| 517 | { |
Alexandre Julliard | 4ff2a27 | 1999-01-31 15:23:45 +0000 | [diff] [blame] | 518 | SetLastError( ERROR_PATH_NOT_FOUND ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 519 | return FALSE; |
| 520 | } |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 521 | if (!DOSFS_FindUnixName( dir->long_name, name, p_l, |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 522 | sizeof(full_name->long_name) - (p_l - full_name->long_name), |
Andreas Mohr | 0471841 | 1999-08-07 12:36:11 +0000 | [diff] [blame] | 523 | p_s, !(DRIVE_GetFlags(dir->drive) & DRIVE_CASE_SENSITIVE) )) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 524 | return FALSE; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 525 | strcpy( full_name->long_name, dir->long_name ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 526 | p_l[-1] = '/'; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 527 | strcpy( full_name->short_name, dir->short_name ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 528 | p_s[-1] = '\\'; |
| 529 | return TRUE; |
| 530 | } |
| 531 | |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 532 | static BOOL DIR_SearchSemicolonedPaths(LPCSTR name, DOS_FULL_NAME *full_name, LPSTR pathlist) |
| 533 | { |
| 534 | LPSTR next, buffer = NULL; |
| 535 | INT len = strlen(name), newlen, currlen = 0; |
| 536 | BOOL ret = FALSE; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 537 | |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 538 | next = pathlist; |
| 539 | while (!ret && next) |
| 540 | { |
| 541 | LPSTR cur = next; |
| 542 | while (*cur == ';') cur++; |
| 543 | if (!*cur) break; |
| 544 | next = strchr( cur, ';' ); |
| 545 | if (next) *next++ = '\0'; |
| 546 | newlen = strlen(cur) + len + 2; |
| 547 | if (newlen > currlen) |
| 548 | { |
| 549 | if (!(buffer = HeapReAlloc( GetProcessHeap(), 0, buffer, newlen))) |
| 550 | goto done; |
| 551 | currlen = newlen; |
| 552 | } |
| 553 | strcpy( buffer, cur ); |
| 554 | strcat( buffer, "\\" ); |
| 555 | strcat( buffer, name ); |
| 556 | ret = DOSFS_GetFullName( buffer, TRUE, full_name ); |
| 557 | } |
| 558 | done: |
| 559 | HeapFree( GetProcessHeap(), 0, buffer ); |
| 560 | return ret; |
| 561 | } |
| 562 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 563 | |
| 564 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 565 | * DIR_TryEnvironmentPath |
| 566 | * |
| 567 | * Helper function for DIR_SearchPath. |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 568 | * Search in the specified path, or in $PATH if NULL. |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 569 | */ |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 570 | static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name, LPCSTR envpath ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 571 | { |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 572 | LPSTR path; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 573 | BOOL ret = FALSE; |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 574 | DWORD size; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 575 | |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 576 | size = envpath ? strlen(envpath)+1 : GetEnvironmentVariableA( "PATH", NULL, 0 ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 577 | if (!size) return FALSE; |
| 578 | if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE; |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 579 | if (envpath) strcpy( path, envpath ); |
| 580 | else if (!GetEnvironmentVariableA( "PATH", path, size )) goto done; |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 581 | |
| 582 | ret = DIR_SearchSemicolonedPaths(name, full_name, path); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 583 | |
| 584 | done: |
| 585 | HeapFree( GetProcessHeap(), 0, path ); |
| 586 | return ret; |
| 587 | } |
| 588 | |
| 589 | |
| 590 | /*********************************************************************** |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 591 | * DIR_TryModulePath |
| 592 | * |
| 593 | * Helper function for DIR_SearchPath. |
| 594 | */ |
Alexandre Julliard | b18dbd2 | 2000-07-25 12:11:53 +0000 | [diff] [blame] | 595 | static BOOL DIR_TryModulePath( LPCSTR name, DOS_FULL_NAME *full_name, BOOL win32 ) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 596 | { |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 597 | /* FIXME: for now, GetModuleFileNameA can't return more */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 598 | /* than OFS_MAXPATHNAME. This may change with Win32. */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 599 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 600 | char buffer[OFS_MAXPATHNAME]; |
| 601 | LPSTR p; |
| 602 | |
Alexandre Julliard | b18dbd2 | 2000-07-25 12:11:53 +0000 | [diff] [blame] | 603 | if (!win32) |
| 604 | { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 605 | if (!GetCurrentTask()) return FALSE; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 606 | if (!GetModuleFileName16( GetCurrentTask(), buffer, sizeof(buffer) )) |
| 607 | buffer[0]='\0'; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 608 | } else { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 609 | if (!GetModuleFileNameA( 0, buffer, sizeof(buffer) )) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 610 | buffer[0]='\0'; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 611 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 612 | if (!(p = strrchr( buffer, '\\' ))) return FALSE; |
| 613 | if (sizeof(buffer) - (++p - buffer) <= strlen(name)) return FALSE; |
| 614 | strcpy( p, name ); |
| 615 | return DOSFS_GetFullName( buffer, TRUE, full_name ); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | /*********************************************************************** |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 620 | * DIR_TryAppPath |
| 621 | * |
| 622 | * Helper function for DIR_SearchPath. |
| 623 | */ |
| 624 | static BOOL DIR_TryAppPath( LPCSTR name, DOS_FULL_NAME *full_name ) |
| 625 | { |
| 626 | HKEY hkAppPaths, hkApp; |
| 627 | char lpAppName[MAX_PATHNAME_LEN], lpAppPaths[MAX_PATHNAME_LEN]; |
| 628 | LPSTR lpFileName; |
| 629 | BOOL res = FALSE; |
| 630 | DWORD type, count; |
| 631 | |
| 632 | if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths", &hkAppPaths) != ERROR_SUCCESS) |
| 633 | return FALSE; |
| 634 | |
| 635 | if (GetModuleFileNameA(0, lpAppName, sizeof(lpAppName)) == 0) |
| 636 | { |
| 637 | WARN("huh, module not found ??\n"); |
| 638 | goto end; |
| 639 | } |
| 640 | lpFileName = strrchr(lpAppName, '\\'); |
| 641 | if (!lpFileName) |
| 642 | goto end; |
| 643 | else lpFileName++; /* skip '\\' */ |
| 644 | if (RegOpenKeyA(hkAppPaths, lpFileName, &hkApp) != ERROR_SUCCESS) |
| 645 | goto end; |
| 646 | count = sizeof(lpAppPaths); |
| 647 | if (RegQueryValueExA(hkApp, "Path", 0, &type, (LPBYTE)lpAppPaths, &count) != ERROR_SUCCESS) |
| 648 | goto end; |
| 649 | TRACE("successfully opened App Paths for '%s'\n", lpFileName); |
| 650 | |
| 651 | res = DIR_SearchSemicolonedPaths(name, full_name, lpAppPaths); |
| 652 | end: |
| 653 | if (hkApp) |
| 654 | RegCloseKey(hkApp); |
| 655 | if (hkAppPaths) |
| 656 | RegCloseKey(hkAppPaths); |
| 657 | return res; |
| 658 | } |
| 659 | |
| 660 | /*********************************************************************** |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 661 | * DIR_SearchPath |
| 662 | * |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 663 | * Implementation of SearchPathA. 'win32' specifies whether the search |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 664 | * order is Win16 (module path last) or Win32 (module path first). |
| 665 | * |
| 666 | * FIXME: should return long path names. |
| 667 | */ |
| 668 | DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 669 | DOS_FULL_NAME *full_name, BOOL win32 ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 670 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 671 | LPCSTR p; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 672 | LPSTR tmp = NULL; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 673 | BOOL ret = TRUE; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 674 | |
| 675 | /* First check the supplied parameters */ |
| 676 | |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 677 | p = strrchr( name, '.' ); |
| 678 | if (p && !strchr( p, '/' ) && !strchr( p, '\\' )) |
| 679 | ext = NULL; /* Ignore the specified extension */ |
Bill Medland | 65fc1c9 | 2001-08-24 21:13:02 +0000 | [diff] [blame] | 680 | if (FILE_contains_path (name)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 681 | path = NULL; /* Ignore path if name already contains a path */ |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 682 | if (path && !*path) path = NULL; /* Ignore empty path */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 683 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 684 | /* Allocate a buffer for the file name and extension */ |
| 685 | |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 686 | if (ext) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 687 | { |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 688 | DWORD len = strlen(name) + strlen(ext); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 689 | if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) |
| 690 | { |
| 691 | SetLastError( ERROR_OUTOFMEMORY ); |
| 692 | return 0; |
| 693 | } |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 694 | strcpy( tmp, name ); |
| 695 | strcat( tmp, ext ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 696 | name = tmp; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 697 | } |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 698 | |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 699 | /* If the name contains an explicit path, everything's easy */ |
| 700 | |
Bill Medland | 65fc1c9 | 2001-08-24 21:13:02 +0000 | [diff] [blame] | 701 | if (FILE_contains_path(name)) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 702 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 703 | ret = DOSFS_GetFullName( name, TRUE, full_name ); |
| 704 | goto done; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 707 | /* Search in the specified path */ |
| 708 | |
| 709 | if (path) |
| 710 | { |
| 711 | ret = DIR_TryEnvironmentPath( name, full_name, path ); |
| 712 | goto done; |
| 713 | } |
| 714 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 715 | /* Try the path of the current executable (for Win32 search order) */ |
| 716 | |
Alexandre Julliard | b18dbd2 | 2000-07-25 12:11:53 +0000 | [diff] [blame] | 717 | if (win32 && DIR_TryModulePath( name, full_name, win32 )) goto done; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 718 | |
| 719 | /* Try the current directory */ |
| 720 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 721 | if (DOSFS_GetFullName( name, TRUE, full_name )) goto done; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 722 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 723 | /* Try the Windows system directory */ |
| 724 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 725 | if (DIR_TryPath( &DIR_System, name, full_name )) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 726 | goto done; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 727 | |
Guy Albertelli | e40c9b0 | 1999-06-05 11:47:25 +0000 | [diff] [blame] | 728 | /* Try the Windows directory */ |
| 729 | |
| 730 | if (DIR_TryPath( &DIR_Windows, name, full_name )) |
| 731 | goto done; |
| 732 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 733 | /* Try the path of the current executable (for Win16 search order) */ |
| 734 | |
Alexandre Julliard | b18dbd2 | 2000-07-25 12:11:53 +0000 | [diff] [blame] | 735 | if (!win32 && DIR_TryModulePath( name, full_name, win32 )) goto done; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 736 | |
Andreas Mohr | 8f925ae | 2002-02-27 18:49:40 +0000 | [diff] [blame] | 737 | /* Try the "App Paths" entry if existing (undocumented ??) */ |
| 738 | if (DIR_TryAppPath(name, full_name)) |
| 739 | goto done; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 740 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 741 | /* Try all directories in path */ |
| 742 | |
Alexandre Julliard | 9400e2d | 2000-11-01 21:48:38 +0000 | [diff] [blame] | 743 | ret = DIR_TryEnvironmentPath( name, full_name, NULL ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 744 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 745 | done: |
| 746 | if (tmp) HeapFree( GetProcessHeap(), 0, tmp ); |
| 747 | return ret; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | |
| 751 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 752 | * SearchPathA [KERNEL32.@] |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 753 | * |
| 754 | * Searches for a specified file in the search path. |
| 755 | * |
| 756 | * PARAMS |
| 757 | * path [I] Path to search |
| 758 | * name [I] Filename to search for. |
| 759 | * ext [I] File extension to append to file name. The first |
| 760 | * character must be a period. This parameter is |
| 761 | * specified only if the filename given does not |
| 762 | * contain an extension. |
| 763 | * buflen [I] size of buffer, in characters |
| 764 | * buffer [O] buffer for found filename |
| 765 | * lastpart [O] address of pointer to last used character in |
| 766 | * buffer (the final '\') |
| 767 | * |
| 768 | * RETURNS |
| 769 | * Success: length of string copied into buffer, not including |
| 770 | * terminating null character. If the filename found is |
| 771 | * longer than the length of the buffer, the length of the |
| 772 | * filename is returned. |
| 773 | * Failure: Zero |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 774 | * |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 775 | * NOTES |
James Juran | 65020b3 | 2000-05-23 01:13:50 +0000 | [diff] [blame] | 776 | * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND) |
| 777 | * (tested on NT 4.0) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 778 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 779 | DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext, DWORD buflen, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 780 | LPSTR buffer, LPSTR *lastpart ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 781 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 782 | LPSTR p, res; |
| 783 | DOS_FULL_NAME full_name; |
| 784 | |
James Juran | 65020b3 | 2000-05-23 01:13:50 +0000 | [diff] [blame] | 785 | if (!DIR_SearchPath( path, name, ext, &full_name, TRUE )) |
| 786 | { |
| 787 | SetLastError(ERROR_FILE_NOT_FOUND); |
| 788 | return 0; |
| 789 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 790 | lstrcpynA( buffer, full_name.short_name, buflen ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 791 | res = full_name.long_name + |
| 792 | strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' )); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 793 | while (*res == '/') res++; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 794 | if (buflen) |
| 795 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 796 | if (buflen > 3) lstrcpynA( buffer + 3, res, buflen - 3 ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 797 | for (p = buffer; *p; p++) if (*p == '/') *p = '\\'; |
| 798 | if (lastpart) *lastpart = strrchr( buffer, '\\' ) + 1; |
| 799 | } |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 800 | TRACE("Returning %d\n", strlen(res) + 3 ); |
Guy Albertelli | e711ba2 | 1999-04-06 07:14:09 +0000 | [diff] [blame] | 801 | return strlen(res) + 3; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | |
| 805 | /*********************************************************************** |
Patrik Stridvall | dae8de6 | 2001-06-13 20:13:18 +0000 | [diff] [blame] | 806 | * SearchPathW (KERNEL32.@) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 807 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 808 | DWORD WINAPI SearchPathW( LPCWSTR path, LPCWSTR name, LPCWSTR ext, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 809 | DWORD buflen, LPWSTR buffer, LPWSTR *lastpart ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 810 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 811 | LPWSTR p; |
| 812 | LPSTR res; |
| 813 | DOS_FULL_NAME full_name; |
| 814 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 815 | LPSTR pathA = HEAP_strdupWtoA( GetProcessHeap(), 0, path ); |
| 816 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name ); |
| 817 | LPSTR extA = HEAP_strdupWtoA( GetProcessHeap(), 0, ext ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 818 | DWORD ret = DIR_SearchPath( pathA, nameA, extA, &full_name, TRUE ); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 819 | HeapFree( GetProcessHeap(), 0, extA ); |
| 820 | HeapFree( GetProcessHeap(), 0, nameA ); |
| 821 | HeapFree( GetProcessHeap(), 0, pathA ); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 822 | if (!ret) return 0; |
| 823 | |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 824 | if (buflen > 0 && !MultiByteToWideChar( CP_ACP, 0, full_name.short_name, -1, buffer, buflen )) |
| 825 | buffer[buflen-1] = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 826 | res = full_name.long_name + |
| 827 | strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' )); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 828 | while (*res == '/') res++; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 829 | if (buflen) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 830 | { |
Alexandre Julliard | 24a62ab | 2000-11-28 22:40:56 +0000 | [diff] [blame] | 831 | if (buflen > 3) |
| 832 | { |
| 833 | if (!MultiByteToWideChar( CP_ACP, 0, res, -1, buffer+3, buflen-3 )) |
| 834 | buffer[buflen-1] = 0; |
| 835 | } |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 836 | for (p = buffer; *p; p++) if (*p == '/') *p = '\\'; |
| 837 | if (lastpart) |
| 838 | { |
| 839 | for (p = *lastpart = buffer; *p; p++) |
| 840 | if (*p == '\\') *lastpart = p + 1; |
| 841 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 842 | } |
Guy Albertelli | e711ba2 | 1999-04-06 07:14:09 +0000 | [diff] [blame] | 843 | return strlen(res) + 3; |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | |
Bill Medland | 65fc1c9 | 2001-08-24 21:13:02 +0000 | [diff] [blame] | 847 | /*********************************************************************** |
| 848 | * search_alternate_path |
| 849 | * |
| 850 | * |
| 851 | * FIXME: should return long path names.? |
| 852 | */ |
| 853 | static BOOL search_alternate_path(LPCSTR dll_path, LPCSTR name, LPCSTR ext, |
| 854 | DOS_FULL_NAME *full_name) |
| 855 | { |
| 856 | LPCSTR p; |
| 857 | LPSTR tmp = NULL; |
| 858 | BOOL ret = TRUE; |
| 859 | |
| 860 | /* First check the supplied parameters */ |
| 861 | |
| 862 | p = strrchr( name, '.' ); |
| 863 | if (p && !strchr( p, '/' ) && !strchr( p, '\\' )) |
| 864 | ext = NULL; /* Ignore the specified extension */ |
| 865 | |
| 866 | /* Allocate a buffer for the file name and extension */ |
| 867 | |
| 868 | if (ext) |
| 869 | { |
| 870 | DWORD len = strlen(name) + strlen(ext); |
| 871 | if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 ))) |
| 872 | { |
| 873 | SetLastError( ERROR_OUTOFMEMORY ); |
| 874 | return 0; |
| 875 | } |
| 876 | strcpy( tmp, name ); |
| 877 | strcat( tmp, ext ); |
| 878 | name = tmp; |
| 879 | } |
| 880 | |
| 881 | if (DIR_TryEnvironmentPath (name, full_name, dll_path)) |
| 882 | ; |
| 883 | else if (DOSFS_GetFullName (name, TRUE, full_name)) /* current dir */ |
| 884 | ; |
| 885 | else if (DIR_TryPath (&DIR_System, name, full_name)) /* System dir */ |
| 886 | ; |
| 887 | else if (DIR_TryPath (&DIR_Windows, name, full_name)) /* Windows dir */ |
| 888 | ; |
| 889 | else |
| 890 | ret = DIR_TryEnvironmentPath( name, full_name, NULL ); |
| 891 | |
| 892 | if (tmp) HeapFree( GetProcessHeap(), 0, tmp ); |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | |
| 897 | /*********************************************************************** |
| 898 | * DIR_SearchAlternatePath |
| 899 | * |
| 900 | * Searches for a specified file in the search path. |
| 901 | * |
| 902 | * PARAMS |
| 903 | * dll_path [I] Path to search |
| 904 | * name [I] Filename to search for. |
| 905 | * ext [I] File extension to append to file name. The first |
| 906 | * character must be a period. This parameter is |
| 907 | * specified only if the filename given does not |
| 908 | * contain an extension. |
| 909 | * buflen [I] size of buffer, in characters |
| 910 | * buffer [O] buffer for found filename |
| 911 | * lastpart [O] address of pointer to last used character in |
| 912 | * buffer (the final '\') (May be NULL) |
| 913 | * |
| 914 | * RETURNS |
| 915 | * Success: length of string copied into buffer, not including |
| 916 | * terminating null character. If the filename found is |
| 917 | * longer than the length of the buffer, the length of the |
| 918 | * filename is returned. |
| 919 | * Failure: Zero |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 920 | * |
Bill Medland | 65fc1c9 | 2001-08-24 21:13:02 +0000 | [diff] [blame] | 921 | * NOTES |
| 922 | * If the file is not found, calls SetLastError(ERROR_FILE_NOT_FOUND) |
| 923 | */ |
| 924 | DWORD DIR_SearchAlternatePath( LPCSTR dll_path, LPCSTR name, LPCSTR ext, |
| 925 | DWORD buflen, LPSTR buffer, LPSTR *lastpart ) |
| 926 | { |
| 927 | LPSTR p, res; |
| 928 | DOS_FULL_NAME full_name; |
| 929 | |
| 930 | if (!search_alternate_path( dll_path, name, ext, &full_name)) |
| 931 | { |
| 932 | SetLastError(ERROR_FILE_NOT_FOUND); |
| 933 | return 0; |
| 934 | } |
| 935 | lstrcpynA( buffer, full_name.short_name, buflen ); |
| 936 | res = full_name.long_name + |
| 937 | strlen(DRIVE_GetRoot( full_name.short_name[0] - 'A' )); |
| 938 | while (*res == '/') res++; |
| 939 | if (buflen) |
| 940 | { |
| 941 | if (buflen > 3) lstrcpynA( buffer + 3, res, buflen - 3 ); |
| 942 | for (p = buffer; *p; p++) if (*p == '/') *p = '\\'; |
| 943 | if (lastpart) *lastpart = strrchr( buffer, '\\' ) + 1; |
| 944 | } |
| 945 | TRACE("Returning %d\n", strlen(res) + 3 ); |
| 946 | return strlen(res) + 3; |
| 947 | } |