Fossil SCM

Fix the file_fullexename() function (used by the "info" and "test-which" commands) so that it works correctly on Windows.

drh 2021-07-01 19:27 trunk
Commit d8c32ebdffcef75b0a9e5831da1c18f92021b09d8072594134a8857dd0690068
1 file changed +44
+44
--- src/file.c
+++ src/file.c
@@ -1298,10 +1298,54 @@
12981298
** This routine only works on unix. On Windows, simply return
12991299
** a copy of the input.
13001300
*/
13011301
char *file_fullexename(const char *zCmd){
13021302
#ifdef _WIN32
1303
+ char *zPath;
1304
+ char *z = 0;
1305
+ const char *zExe = "";
1306
+ if( sqlite3_strlike("%.exe",zCmd,0)!=0 ) zExe = ".exe";
1307
+ if( file_is_absolute_path(zCmd) ){
1308
+ return mprintf("%s%s", zCmd, zExe);
1309
+ }
1310
+ if( strchr(zCmd,'\\')!=0 && strchr(zCmd,'/')!=0 ){
1311
+ int i;
1312
+ Blob out = BLOB_INITIALIZER;
1313
+ file_canonical_name(zCmd, &out, 0);
1314
+ blob_append(&out, zExe, -1);
1315
+ z = fossil_strdup(blob_str(&out));
1316
+ blob_reset(&out);
1317
+ for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; }
1318
+ return z;
1319
+ }
1320
+ z = mprintf(".\\%s%s", zCmd, zExe);
1321
+ if( file_isfile(z, ExtFILE) ){
1322
+ int i;
1323
+ Blob out = BLOB_INITIALIZER;
1324
+ file_canonical_name(zCmd, &out, 0);
1325
+ blob_append(&out, zExe, -1);
1326
+ z = fossil_strdup(blob_str(&out));
1327
+ blob_reset(&out);
1328
+ for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; }
1329
+ return z;
1330
+ }
1331
+ fossil_free(z);
1332
+ zPath = fossil_getenv("PATH");
1333
+ while( zPath && zPath[0] ){
1334
+ int n;
1335
+ char *zColon;
1336
+ zColon = strchr(zPath, ';');
1337
+ n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath);
1338
+ while( n>0 && zPath[n-1]=='\\' ){ n--; }
1339
+ z = mprintf("%.*s\\%s%s", n, zPath, zCmd, zExe);
1340
+ if( file_isfile(z, ExtFILE) ){
1341
+ return z;
1342
+ }
1343
+ fossil_free(z);
1344
+ if( zColon==0 ) break;
1345
+ zPath = zColon+1;
1346
+ }
13031347
return fossil_strdup(zCmd);
13041348
#else
13051349
char *zPath;
13061350
char *z;
13071351
if( zCmd[0]=='/' ){
13081352
--- src/file.c
+++ src/file.c
@@ -1298,10 +1298,54 @@
1298 ** This routine only works on unix. On Windows, simply return
1299 ** a copy of the input.
1300 */
1301 char *file_fullexename(const char *zCmd){
1302 #ifdef _WIN32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1303 return fossil_strdup(zCmd);
1304 #else
1305 char *zPath;
1306 char *z;
1307 if( zCmd[0]=='/' ){
1308
--- src/file.c
+++ src/file.c
@@ -1298,10 +1298,54 @@
1298 ** This routine only works on unix. On Windows, simply return
1299 ** a copy of the input.
1300 */
1301 char *file_fullexename(const char *zCmd){
1302 #ifdef _WIN32
1303 char *zPath;
1304 char *z = 0;
1305 const char *zExe = "";
1306 if( sqlite3_strlike("%.exe",zCmd,0)!=0 ) zExe = ".exe";
1307 if( file_is_absolute_path(zCmd) ){
1308 return mprintf("%s%s", zCmd, zExe);
1309 }
1310 if( strchr(zCmd,'\\')!=0 && strchr(zCmd,'/')!=0 ){
1311 int i;
1312 Blob out = BLOB_INITIALIZER;
1313 file_canonical_name(zCmd, &out, 0);
1314 blob_append(&out, zExe, -1);
1315 z = fossil_strdup(blob_str(&out));
1316 blob_reset(&out);
1317 for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; }
1318 return z;
1319 }
1320 z = mprintf(".\\%s%s", zCmd, zExe);
1321 if( file_isfile(z, ExtFILE) ){
1322 int i;
1323 Blob out = BLOB_INITIALIZER;
1324 file_canonical_name(zCmd, &out, 0);
1325 blob_append(&out, zExe, -1);
1326 z = fossil_strdup(blob_str(&out));
1327 blob_reset(&out);
1328 for(i=0; z[i]; i++){ if( z[i]=='/' ) z[i] = '\\'; }
1329 return z;
1330 }
1331 fossil_free(z);
1332 zPath = fossil_getenv("PATH");
1333 while( zPath && zPath[0] ){
1334 int n;
1335 char *zColon;
1336 zColon = strchr(zPath, ';');
1337 n = zColon ? (int)(zColon-zPath) : (int)strlen(zPath);
1338 while( n>0 && zPath[n-1]=='\\' ){ n--; }
1339 z = mprintf("%.*s\\%s%s", n, zPath, zCmd, zExe);
1340 if( file_isfile(z, ExtFILE) ){
1341 return z;
1342 }
1343 fossil_free(z);
1344 if( zColon==0 ) break;
1345 zPath = zColon+1;
1346 }
1347 return fossil_strdup(zCmd);
1348 #else
1349 char *zPath;
1350 char *z;
1351 if( zCmd[0]=='/' ){
1352

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button