Fossil SCM
Improved error messages when getcwd() fails. Ticket [f628d183c958c5b12].
Commit
89e6eb9674f5b5521ee9fa35b8253143111c43e1
Parent
b707622f29b6081…
1 file changed
+9
-2
+9
-2
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -19,10 +19,12 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | #include "config.h" |
| 21 | 21 | #include <sys/types.h> |
| 22 | 22 | #include <sys/stat.h> |
| 23 | 23 | #include <unistd.h> |
| 24 | +#include <string.h> | |
| 25 | +#include <errno.h> | |
| 24 | 26 | #include "file.h" |
| 25 | 27 | |
| 26 | 28 | /* |
| 27 | 29 | ** The file status information from the most recent stat() call. |
| 28 | 30 | ** |
| @@ -397,11 +399,11 @@ | ||
| 397 | 399 | char *zPwdUtf8; |
| 398 | 400 | int nPwd; |
| 399 | 401 | int i; |
| 400 | 402 | char zPwd[2000]; |
| 401 | 403 | if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){ |
| 402 | - fossil_fatal("pwd too big: max %d\n", (int)sizeof(zPwd)-1); | |
| 404 | + fossil_fatal("cannot find the current working directory."); | |
| 403 | 405 | } |
| 404 | 406 | zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); |
| 405 | 407 | nPwd = strlen(zPwdUtf8); |
| 406 | 408 | if( nPwd > nBuf-1 ){ |
| 407 | 409 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| @@ -409,11 +411,16 @@ | ||
| 409 | 411 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 410 | 412 | memcpy(zBuf, zPwdUtf8, nPwd+1); |
| 411 | 413 | fossil_mbcs_free(zPwdUtf8); |
| 412 | 414 | #else |
| 413 | 415 | if( getcwd(zBuf, nBuf-1)==0 ){ |
| 414 | - fossil_fatal("pwd too big: max %d\n", nBuf-1); | |
| 416 | + if( errno==ERANGE ){ | |
| 417 | + fossil_fatal("pwd too big: max %d\n", nBuf-1); | |
| 418 | + }else{ | |
| 419 | + fossil_fatal("cannot find current working directory; %s", | |
| 420 | + strerror(errno)); | |
| 421 | + } | |
| 415 | 422 | } |
| 416 | 423 | #endif |
| 417 | 424 | } |
| 418 | 425 | |
| 419 | 426 | /* |
| 420 | 427 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -19,10 +19,12 @@ | |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <unistd.h> |
| 24 | #include "file.h" |
| 25 | |
| 26 | /* |
| 27 | ** The file status information from the most recent stat() call. |
| 28 | ** |
| @@ -397,11 +399,11 @@ | |
| 397 | char *zPwdUtf8; |
| 398 | int nPwd; |
| 399 | int i; |
| 400 | char zPwd[2000]; |
| 401 | if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){ |
| 402 | fossil_fatal("pwd too big: max %d\n", (int)sizeof(zPwd)-1); |
| 403 | } |
| 404 | zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); |
| 405 | nPwd = strlen(zPwdUtf8); |
| 406 | if( nPwd > nBuf-1 ){ |
| 407 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| @@ -409,11 +411,16 @@ | |
| 409 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 410 | memcpy(zBuf, zPwdUtf8, nPwd+1); |
| 411 | fossil_mbcs_free(zPwdUtf8); |
| 412 | #else |
| 413 | if( getcwd(zBuf, nBuf-1)==0 ){ |
| 414 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 415 | } |
| 416 | #endif |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -19,10 +19,12 @@ | |
| 19 | */ |
| 20 | #include "config.h" |
| 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <unistd.h> |
| 24 | #include <string.h> |
| 25 | #include <errno.h> |
| 26 | #include "file.h" |
| 27 | |
| 28 | /* |
| 29 | ** The file status information from the most recent stat() call. |
| 30 | ** |
| @@ -397,11 +399,11 @@ | |
| 399 | char *zPwdUtf8; |
| 400 | int nPwd; |
| 401 | int i; |
| 402 | char zPwd[2000]; |
| 403 | if( getcwd(zPwd, sizeof(zPwd)-1)==0 ){ |
| 404 | fossil_fatal("cannot find the current working directory."); |
| 405 | } |
| 406 | zPwdUtf8 = fossil_mbcs_to_utf8(zPwd); |
| 407 | nPwd = strlen(zPwdUtf8); |
| 408 | if( nPwd > nBuf-1 ){ |
| 409 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| @@ -409,11 +411,16 @@ | |
| 411 | for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/'; |
| 412 | memcpy(zBuf, zPwdUtf8, nPwd+1); |
| 413 | fossil_mbcs_free(zPwdUtf8); |
| 414 | #else |
| 415 | if( getcwd(zBuf, nBuf-1)==0 ){ |
| 416 | if( errno==ERANGE ){ |
| 417 | fossil_fatal("pwd too big: max %d\n", nBuf-1); |
| 418 | }else{ |
| 419 | fossil_fatal("cannot find current working directory; %s", |
| 420 | strerror(errno)); |
| 421 | } |
| 422 | } |
| 423 | #endif |
| 424 | } |
| 425 | |
| 426 | /* |
| 427 |