X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/8dacc30e3a1bd57526c21b701383f69ef93a6703..4dee460f19582a5707e42eb1aa2025f29c7b9d8c:/unix/uxstore.c diff --git a/unix/uxstore.c b/unix/uxstore.c index b049c285..54d35fc9 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include #include @@ -27,7 +29,7 @@ static char *mungestr(const char *in) { char *out, *ret; - if (!in) + if (!in || !*in) in = "Default Settings"; ret = out = snewn(3*strlen(in)+1, char); @@ -125,31 +127,32 @@ static char *fgetline(FILE *fp) return ret; } -/* - * For the moment, the only existing Unix utility is pterm and that - * has no GUI configuration at all, so our write routines need do - * nothing. Eventually I suppose these will read and write an rc - * 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; } @@ -178,6 +181,7 @@ void close_settings_w(void *handle) * PuTTY's inbuilt defaults, but that the disk files will then * override those. This isn't optimal, but it's the best I can * immediately work out. + * FIXME: the above comment is a bit out of date. Did it happen? */ struct keyval { @@ -484,6 +488,7 @@ int verify_host_key(const char *hostname, int port, break; } + fclose(fp); return ret; }