X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=abook.c;h=fd3e336b76da349f10ac9418384113f13d5197c2;hb=4128f78f5543bebc7cd1868736855207019f1f71;hp=4808dac37abf7e10ea3c05569cc025f53e10f2f6;hpb=ceba9214d8bebe32d0c34c7a82916bcb9d798d69;p=pkg%2Fabook.git diff --git a/abook.c b/abook.c index 4808dac..fd3e336 100644 --- a/abook.c +++ b/abook.c @@ -45,8 +45,8 @@ static void add_email(int); char *datafile = NULL; char *rcfile = NULL; -int alternative_datafile = FALSE; -int alternative_rcfile = FALSE; +bool alternative_datafile = FALSE; +bool alternative_rcfile = FALSE; static int datafile_writeable() @@ -242,7 +242,7 @@ set_filename(char **var, char *path) cwd = my_getcwd(); - *var = strconcat(cwd, path, NULL); + *var = strconcat(cwd, "/", path, NULL); free(cwd); } @@ -604,13 +604,13 @@ abook_fopen (const char *path, const char *mode) { struct stat s; - if( ! strchr(mode, 'r') ) - return fopen(path, mode); - - if ( (stat(path, &s)) == -1 ) + if((stat(path, &s)) == -1) return NULL; - - return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL; + + if(strchr(mode, 'r')) + return S_ISREG(s.st_mode) ? fopen(path, mode) : NULL; + else + return S_ISDIR(s.st_mode) ? NULL : fopen(path, mode); } @@ -754,6 +754,12 @@ add_email(int quiet) { char *line; char *name = NULL, *email = NULL; + struct stat s; + + if( (fstat(fileno(stdin), &s)) == -1 || S_ISDIR(s.st_mode)) { + fprintf(stderr, "stdin is a directory or cannot stat stdin\n"); + exit(1); + } init_add_email();