X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/d765248486faa03be34ddb77e2f7a49319df24ec..b537dd42c1da03890c832e94a4f47369ca3d99af:/mac/macstore.c diff --git a/mac/macstore.c b/mac/macstore.c index 66e82014..75c88763 100644 --- a/mac/macstore.c +++ b/mac/macstore.c @@ -1,4 +1,4 @@ -/* $Id: macstore.c,v 1.10 2003/01/18 16:10:21 ben Exp $ */ +/* $Id: macstore.c,v 1.11 2003/01/18 20:09:21 ben Exp $ */ /* * macstore.c: Macintosh-specific impementation of the interface @@ -11,6 +11,7 @@ #include #include +#include #include #include "putty.h" @@ -18,11 +19,6 @@ #include "mac.h" #include "macresid.h" -#define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY') -#define INTERNAL_CREATOR FOUR_CHAR_CODE('pTTI') -#define SESS_TYPE FOUR_CHAR_CODE('Sess') -#define SEED_TYPE FOUR_CHAR_CODE('Seed') - OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit); @@ -123,30 +119,45 @@ struct write_settings { }; void *open_settings_w(char const *sessionname) { - short sessVRefNum, tmpVRefNum; - long sessDirID, tmpDirID; + short sessVRefNum; + long sessDirID; OSErr error; Str255 psessionname; - struct write_settings *ws; + FSSpec dstfile; - ws = safemalloc(sizeof *ws); error = get_session_dir(kCreateFolder, &sessVRefNum, &sessDirID); - if (error != noErr) goto out; + if (error != noErr) return NULL; c2pstrcpy(psessionname, sessionname); - error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &ws->dstfile); - if (error != noErr && error != fnfErr) goto out; + error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &dstfile); if (error == fnfErr) { - FSpCreateResFile(&ws->dstfile, PUTTY_CREATOR, SESS_TYPE, - smSystemScript); - if ((error = ResError()) != noErr) goto out; - } + FSpCreateResFile(&dstfile, PUTTY_CREATOR, SESS_TYPE, smSystemScript); + if ((error = ResError()) != noErr) return NULL; + } else if (error != noErr) return NULL; + + return open_settings_w_fsp(&dstfile); +} + +/* + * NB: Destination file must exist. + */ +void *open_settings_w_fsp(FSSpec *dstfile) +{ + short tmpVRefNum; + long tmpDirID; + struct write_settings *ws; + OSErr error; + Str255 tmpname; + + ws = smalloc(sizeof *ws); + ws->dstfile = *dstfile; /* Create a temporary file to save to first. */ - error = FindFolder(sessVRefNum, kTemporaryFolderType, kCreateFolder, - &tmpVRefNum, &tmpDirID); + error = FindFolder(ws->dstfile.vRefNum, kTemporaryFolderType, + kCreateFolder, &tmpVRefNum, &tmpDirID); if (error != noErr) goto out; - error = FSMakeFSSpec(tmpVRefNum, tmpDirID, psessionname, &ws->tmpfile); + c2pstrcpy(tmpname, tmpnam(NULL)); + error = FSMakeFSSpec(tmpVRefNum, tmpDirID, tmpname, &ws->tmpfile); if (error != noErr && error != fnfErr) goto out; if (error == noErr) { error = FSpDelete(&ws->tmpfile);