Fossil SCM

Improved error messages when getcwd() fails. Ticket [f628d183c958c5b12].

drh 2011-06-18 15:51 trunk
Commit 89e6eb9674f5b5521ee9fa35b8253143111c43e1
1 file changed +9 -2
+9 -2
--- src/file.c
+++ src/file.c
@@ -19,10 +19,12 @@
1919
*/
2020
#include "config.h"
2121
#include <sys/types.h>
2222
#include <sys/stat.h>
2323
#include <unistd.h>
24
+#include <string.h>
25
+#include <errno.h>
2426
#include "file.h"
2527
2628
/*
2729
** The file status information from the most recent stat() call.
2830
**
@@ -397,11 +399,11 @@
397399
char *zPwdUtf8;
398400
int nPwd;
399401
int i;
400402
char zPwd[2000];
401403
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.");
403405
}
404406
zPwdUtf8 = fossil_mbcs_to_utf8(zPwd);
405407
nPwd = strlen(zPwdUtf8);
406408
if( nPwd > nBuf-1 ){
407409
fossil_fatal("pwd too big: max %d\n", nBuf-1);
@@ -409,11 +411,16 @@
409411
for(i=0; zPwdUtf8[i]; i++) if( zPwdUtf8[i]=='\\' ) zPwdUtf8[i] = '/';
410412
memcpy(zBuf, zPwdUtf8, nPwd+1);
411413
fossil_mbcs_free(zPwdUtf8);
412414
#else
413415
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
+ }
415422
}
416423
#endif
417424
}
418425
419426
/*
420427
--- 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

Keyboard Shortcuts

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