2 * DOS directories functions
4 * Copyright 1995 Alexandre Julliard
21 #define MAX_PATH_ELEMENTS 20
23 static char *DIR_WindowsDosDir
;
24 static char *DIR_WindowsUnixDir
;
25 static char *DIR_SystemDosDir
;
26 static char *DIR_SystemUnixDir
;
27 static char *DIR_TempDosDir
;
28 static char *DIR_TempUnixDir
;
30 static char *DIR_DosPath
[MAX_PATH_ELEMENTS
]; /* Path in DOS format */
31 static char *DIR_UnixPath
[MAX_PATH_ELEMENTS
]; /* Path in Unix format */
32 static int DIR_PathElements
= 0;
34 /***********************************************************************
37 * Get a path name from the wine.ini file and make sure it is valid.
39 static int DIR_GetPath( const char *keyname
, const char *defval
,
40 char **dos_path
, char **unix_path
)
42 char path
[MAX_PATHNAME_LEN
];
43 const char *dos_name
,*unix_name
;
46 PROFILE_GetWineIniString( "wine", keyname
, defval
, path
, sizeof(path
) );
47 if (!(unix_name
= DOSFS_GetUnixFileName( path
, TRUE
)) ||
48 !FILE_Stat( unix_name
, &attr
, NULL
, NULL
, NULL
) ||
49 !(attr
& FA_DIRECTORY
))
51 fprintf(stderr
, "Invalid path '%s' for %s directory\n", path
, keyname
);
54 if (!(dos_name
= DOSFS_GetDosTrueName( unix_name
, TRUE
)))
56 fprintf( stderr
, "Could not get DOS name for %s directory '%s'\n",
60 *unix_path
= xstrdup( unix_name
);
61 *dos_path
= xstrdup( dos_name
);
66 /***********************************************************************
67 * DIR_ParseWindowsPath
69 void DIR_ParseWindowsPath( char *path
)
72 const char *dos_name
,*unix_name
;
76 for ( ; path
&& *path
; path
= p
)
78 p
= strchr( path
, ';' );
79 if (p
) while (*p
== ';') *p
++ = '\0';
81 if (DIR_PathElements
>= MAX_PATH_ELEMENTS
)
83 fprintf( stderr
, "Warning: path has more than %d elements.\n",
87 if (!(unix_name
= DOSFS_GetUnixFileName( path
, TRUE
)) ||
88 !FILE_Stat( unix_name
, &attr
, NULL
, NULL
, NULL
) ||
89 !(attr
& FA_DIRECTORY
))
91 fprintf(stderr
,"Warning: invalid dir '%s' in path, deleting it.\n",
95 if (!(dos_name
= DOSFS_GetDosTrueName( unix_name
, TRUE
)))
97 fprintf( stderr
, "Warning: could not get DOS name for '%s' in path, deleting it.\n",
101 DIR_UnixPath
[DIR_PathElements
] = xstrdup( unix_name
);
102 DIR_DosPath
[DIR_PathElements
] = xstrdup( dos_name
);
107 for (i
= 0; i
< DIR_PathElements
; i
++)
109 dprintf_dosfs( stddeb
, "Path[%d]: %s = %s\n",
110 i
, DIR_DosPath
[i
], DIR_UnixPath
[i
] );
115 /***********************************************************************
120 char path
[MAX_PATHNAME_LEN
], *env_p
;
124 if (!getcwd( path
, MAX_PATHNAME_LEN
))
126 perror( "Could not get current directory" );
130 if ((drive
= DRIVE_FindDriveRoot( &cwd
)) == -1)
132 fprintf( stderr
, "Warning: could not find DOS drive for cwd %s; starting in windows directory.\n",
137 cwd
= DOSFS_GetDosTrueName( path
, TRUE
);
138 DRIVE_SetCurrentDrive( drive
);
139 DRIVE_Chdir( drive
, cwd
+ 2 );
142 if (!(DIR_GetPath( "windows", "c:\\windows",
143 &DIR_WindowsDosDir
, &DIR_WindowsUnixDir
))) return 0;
144 if (!(DIR_GetPath( "system", "c:\\windows\\system",
145 &DIR_SystemDosDir
, &DIR_SystemUnixDir
))) return 0;
146 if (!(DIR_GetPath( "temp", "c:\\windows",
147 &DIR_TempDosDir
, &DIR_TempUnixDir
))) return 0;
151 drive
= DIR_WindowsDosDir
[0] - 'A';
152 DRIVE_SetCurrentDrive( drive
);
153 DRIVE_Chdir( drive
, DIR_WindowsDosDir
+ 2 );
156 PROFILE_GetWineIniString("wine", "path", "c:\\windows;c:\\windows\\system",
157 path
, sizeof(path
) );
158 DIR_ParseWindowsPath( path
);
160 dprintf_dosfs( stddeb
, "WindowsDir = %s\nSystemDir = %s\n",
161 DIR_WindowsDosDir
, DIR_SystemDosDir
);
162 dprintf_dosfs( stddeb
, "TempDir = %s\nCwd = %c:\\%s\n",
163 DIR_TempDosDir
, 'A' + drive
, DRIVE_GetDosCwd( drive
) );
165 /* Put the temp and Windows directories into the environment */
167 env_p
= (char *)xmalloc( strlen(DIR_TempDosDir
) + 6 );
168 strcpy( env_p
, "TEMP=" );
169 strcpy( env_p
+ 5, DIR_TempDosDir
);
171 env_p
= (char *)xmalloc( strlen(DIR_WindowsDosDir
) + 8 );
172 strcpy( env_p
, "windir=" );
173 strcpy( env_p
+ 7, DIR_WindowsDosDir
);
180 /***********************************************************************
183 UINT
DIR_GetTempDosDir( LPSTR path
, UINT count
)
185 if (path
) lstrcpyn( path
, DIR_TempDosDir
, count
);
186 return strlen( DIR_TempDosDir
);
190 /***********************************************************************
193 UINT
DIR_GetTempUnixDir( LPSTR path
, UINT count
)
195 if (path
) lstrcpyn( path
, DIR_TempUnixDir
, count
);
196 return strlen( DIR_TempUnixDir
);
200 /***********************************************************************
201 * DIR_GetWindowsUnixDir
203 UINT
DIR_GetWindowsUnixDir( LPSTR path
, UINT count
)
205 if (path
) lstrcpyn( path
, DIR_WindowsUnixDir
, count
);
206 return strlen( DIR_WindowsUnixDir
);
210 /***********************************************************************
211 * DIR_GetSystemUnixDir
213 UINT
DIR_GetSystemUnixDir( LPSTR path
, UINT count
)
215 if (path
) lstrcpyn( path
, DIR_SystemUnixDir
, count
);
216 return strlen( DIR_SystemUnixDir
);
220 /***********************************************************************
223 UINT
DIR_GetDosPath( int element
, LPSTR path
, UINT count
)
225 if ((element
< 0) || (element
>= DIR_PathElements
)) return 0;
226 if (path
) lstrcpyn( path
, DIR_DosPath
[element
], count
);
227 return strlen( DIR_DosPath
[element
] );
231 /***********************************************************************
232 * GetTempDrive (KERNEL.92)
234 BYTE
GetTempDrive( BYTE ignored
)
236 return DIR_TempDosDir
[0];
240 /***********************************************************************
241 * GetWindowsDirectory (KERNEL.134)
243 UINT
GetWindowsDirectory( LPSTR path
, UINT count
)
245 if (path
) lstrcpyn( path
, DIR_WindowsDosDir
, count
);
246 return strlen( DIR_WindowsDosDir
);
250 /***********************************************************************
251 * GetSystemDirectory (KERNEL.135)
253 UINT
GetSystemDirectory( LPSTR path
, UINT count
)
255 if (path
) lstrcpyn( path
, DIR_SystemDosDir
, count
);
256 return strlen( DIR_SystemDosDir
);