From 08829eb32657e7025dc93f33b118707d48c88316 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Tue, 15 Aug 2017 07:37:57 -0700 Subject: [PATCH] Modify getprefsd() to make path optional (we really only need the vRefNum and dirID) --- macssh/source/init/init.c | 3 +- macssh/source/ssh/GUSIPatch1.cp | 51 ++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/macssh/source/init/init.c b/macssh/source/init/init.c index 088fb75..e52ce1c 100755 --- a/macssh/source/init/init.c +++ b/macssh/source/init/init.c @@ -325,7 +325,6 @@ void DoTheGlobalInits(void) { long junk = 0; ParamBlockRec pb; - Str255 tempString; char folderString[256]; int err; char *buf; @@ -377,7 +376,7 @@ void DoTheGlobalInits(void) BlockMoveData(folderString + 1, folderString, junk); folderString[junk] = 0; // WARNING: this initializes GUSI which in turn calls our event handler... - buf = getprefsd(folderString, (char *)tempString, sizeof(tempString), &TelInfo->PrefFolder.vRefNum, &TelInfo->PrefFolder.parID); + buf = getprefsd(folderString, NULL, 0, &TelInfo->PrefFolder.vRefNum, &TelInfo->PrefFolder.parID); if ( !buf ) { FindFolder( kOnSystemDisk, kPreferencesFolderType, kCreateFolder, &(TelInfo->PrefFolder.vRefNum), &(TelInfo->PrefFolder.parID)); diff --git a/macssh/source/ssh/GUSIPatch1.cp b/macssh/source/ssh/GUSIPatch1.cp index 2478b74..a7a95d8 100755 --- a/macssh/source/ssh/GUSIPatch1.cp +++ b/macssh/source/ssh/GUSIPatch1.cp @@ -123,9 +123,6 @@ char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID) Boolean isFolder; Boolean wasAlias; Boolean isDirectory; - short fullPathLength; - short pathLength; - Handle fullPath; *vRefNum = 0; *dirID = 0; @@ -147,24 +144,38 @@ char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID) if (err != noErr || !isDirectory) { return NULL; } - err = FSpGetFullPath(&fileSpec, &fullPathLength, &fullPath); - if (err != noErr) { - return NULL; - } - pathLength = fullPathLength; - if ((*fullPath)[pathLength - 1] == ':' ) - --pathLength; - if (pathLength > size - 2) { - // FIXME: better error message - DisposeHandle(fullPath); - return NULL; - } + *vRefNum = fileSpec.vRefNum; - BlockMoveData(*fullPath, buf, pathLength); - buf[pathLength++] = ':'; - buf[pathLength] = 0; - DisposeHandle(fullPath); - return buf; + + if (buf) { + short fullPathLength; + short pathLength; + Handle fullPath; + + err = FSpGetFullPath(&fileSpec, &fullPathLength, &fullPath); + if (err != noErr) { + return NULL; + } + pathLength = fullPathLength; + if ((*fullPath)[pathLength - 1] == ':' ) + --pathLength; + if (pathLength > size - 2) { + // FIXME: better error message + DisposeHandle(fullPath); + return NULL; + } + + BlockMoveData(*fullPath, buf, pathLength); + buf[pathLength++] = ':'; + buf[pathLength] = 0; + DisposeHandle(fullPath); + + return buf; + } + else { + // return a valid pointer rather than NULL + return ""; + } /* GUSIFileSpec prefs(kPreferencesFolderType, kOnSystemDisk);