X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=abook.c;h=fd3e336b76da349f10ac9418384113f13d5197c2;hb=f23af6b90ad6dbe1180c0e660112739be70fd86a;hp=faa8055cbf1b4e668f652cf7e81fe83b0f099fc2;hpb=c94cf7103ac134c27a6734a8813c609ee9175a01;p=pkg%2Fabook.git diff --git a/abook.c b/abook.c index faa8055..fd3e336 100644 --- a/abook.c +++ b/abook.c @@ -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();