AmendHub

Download:

jcs

/

subtext

/

amendments

/

54

db+util: Fix getpath() when already passing in an absolute path


jcs made amendment 54 over 2 years ago
--- db.c Sat Jan 15 20:27:15 2022 +++ db.c Mon Jan 17 15:21:30 2022 @@ -18,9 +18,9 @@ #include <string.h> #include <time.h> +#include "subtext.h" #include "bile.h" #include "db.h" -#include "subtext.h" #include "user.h" #include "util.h" @@ -116,7 +116,10 @@ db_init(Str255 path, short vrefnum, struct bile *bile) } /* we got this far, store it as the last-accessed file */ - getpath(vrefnum, path, &fullpath, true); + if (vrefnum == 0) + memcpy(fullpath, path, sizeof(fullpath)); + else + getpath(vrefnum, path, &fullpath, true); lastfileh = Get1Resource('STR ', STR_LAST_DB); if (lastfileh) xSetHandleSize(lastfileh, fullpath[0] + 1); --- db.h Fri Jan 14 17:42:11 2022 +++ db.h Sun Jan 16 21:16:37 2022 @@ -19,6 +19,7 @@ #include <time.h> +#include "subtext.h" #include "bile.h" #include "sha2.h" @@ -42,6 +43,8 @@ #define DB_TEXT_SHORTMENU_ID 2 #define DB_TEXT_ISSUE_ID 3 +#define DB_USERNAME_LENGTH 16 + struct config { char name[32]; char phone_number[16]; @@ -49,8 +52,6 @@ struct config { char hostname[32]; short telnet_port; }; - -#define DB_USERNAME_LENGTH 16 struct user { /* keep this first so we can quickly read it during caching */ --- util.c Mon Jan 10 22:12:47 2022 +++ util.c Mon Jan 17 15:29:55 2022 @@ -497,6 +497,19 @@ getpath(short vRefNum, Str255 fileName, Str255 *ret, b Str255 name; size_t retlen = 0, len; char tmpret[256], tmp[256]; + char *lastcolon; + + if (strchr((char *)fileName + 1, ':') != NULL) { + /* already a full path */ + memcpy(*ret, fileName, 256); + if (!include_file) { + PtoCstr(*ret); + lastcolon = strrchr((char *)*ret, ':'); + lastcolon[0] = '\0'; + CtoPstr(*ret); + } + return 0; + } wdir.ioVRefNum = wdir.ioWDVRefNum = vRefNum; wdir.ioWDIndex = 0;