Commit da672c41 authored by Lev Walkin's avatar Lev Walkin

better error reporting when destination directory is not available

parent 4645db07
...@@ -36,8 +36,9 @@ int mkstemp(char *template) { ...@@ -36,8 +36,9 @@ int mkstemp(char *template) {
#endif #endif
FILE * FILE *
asn1c_open_file(const char* destdir, const char *name, const char *ext, char **opt_tmpname) { asn1c_open_file(const char *destdir, const char *name, const char *ext,
char fname[PATH_MAX]; char **opt_tmpname) {
char fname[PATH_MAX];
int created = 1; int created = 1;
#ifndef _WIN32 #ifndef _WIN32
struct stat sb; struct stat sb;
...@@ -49,10 +50,8 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o ...@@ -49,10 +50,8 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
/* /*
* Compute filenames. * Compute filenames.
*/ */
ret = snprintf(fname, sizeof(fname), "%s%s%s%s", ret = snprintf(fname, sizeof(fname), "%s%s%s%s", destdir ? destdir : "",
opt_tmpname ? "" : destdir, name, ext, opt_tmpname ? ".XXXXXX" : "");
name, ext,
opt_tmpname ? ".XXXXXX" : "");
assert(ret > 0 && ret < (ssize_t)sizeof(fname)); assert(ret > 0 && ret < (ssize_t)sizeof(fname));
if(opt_tmpname) { if(opt_tmpname) {
...@@ -61,8 +60,10 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o ...@@ -61,8 +60,10 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
*/ */
fd = mkstemp(fname); fd = mkstemp(fname);
#ifndef _WIN32 #ifndef _WIN32
/* fchmod() does not respect umask */ if(fd != -1) {
(void)fchmod(fd, REASONABLE_FILE_MODE); /* fchmod() does not respect umask */
(void)fchmod(fd, REASONABLE_FILE_MODE);
}
#endif #endif
} else { } else {
/* /*
...@@ -75,8 +76,14 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o ...@@ -75,8 +76,14 @@ asn1c_open_file(const char* destdir, const char *name, const char *ext, char **o
} }
} }
if(fd == -1) { if(fd == -1) {
perror(fname); struct stat st;
return NULL; if(destdir && stat(destdir, &st) == -1) {
fprintf(stderr, "%s: No such directory\n", destdir);
return NULL;
} else {
perror(fname);
return NULL;
}
} }
#ifndef _WIN32 #ifndef _WIN32
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment