X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/3bb2f32264efd14ce4a39bea59be27c039646f6c..3f935d5bf975b26836da2fac5cd6e3df67a5e184:/unix/uxstore.c diff --git a/unix/uxstore.c b/unix/uxstore.c index b049c285..b04d557c 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include #include @@ -132,24 +134,32 @@ static char *fgetline(FILE *fp) * file somewhere or other. */ -void *open_settings_w(const char *sessionname) +void *open_settings_w(const char *sessionname, char **errmsg) { char filename[FILENAME_MAX]; FILE *fp; + *errmsg = NULL; + /* - * Start by making sure the sessions subdir exists. Ignore the - * error return from mkdir since it's perfectly likely to be - * `already exists', and any other error will trip us up later - * on so there's no real need to catch it now. + * Start by making sure the .putty directory and its sessions + * subdir actually exist. Ignore error returns from mkdir since + * they're perfectly likely to be `already exists', and any + * other error will trip us up later on so there's no real need + * to catch it now. */ + make_filename(filename, INDEX_DIR, sessionname); + mkdir(filename, 0700); make_filename(filename, INDEX_SESSIONDIR, sessionname); mkdir(filename, 0700); make_filename(filename, INDEX_SESSION, sessionname); fp = fopen(filename, "w"); - if (!fp) - return NULL; /* can't open */ + if (!fp) { + *errmsg = dupprintf("Unable to create %s: %s", + filename, strerror(errno)); + return NULL; /* can't open */ + } return fp; }