diff --git a/toolbox/fs_spec.cpp b/toolbox/fs_spec.cpp index 2cc0f16..cb864fb 100644 --- a/toolbox/fs_spec.cpp +++ b/toolbox/fs_spec.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include namespace OS { @@ -15,8 +17,8 @@ namespace OS { if (!initialized) { - // "/" is item #1 - //IDForPath("/", true); + // "/" is item #2. 0 and 1 are reserved. + //can't just call IDForPath because that calls... Init(); static std::string RootPath("/"); std::hash hasher; @@ -25,9 +27,22 @@ namespace OS { assert(_pathQueue.size() == 1); initialized = true; } - } + int32_t FSSpecManager::IDForCWD() + { + char buffer[MAXPATHLEN]; + char *cp; + + cp = getcwd(buffer, sizeof(buffer)); + if (cp < 0) return 0; + + std::string path(cp); + + return FSSpecManager::IDForPath(std::move(path), true); + } + + int32_t FSSpecManager::IDForPath(const std::string &path, bool insert) { if (path.empty()) return -1; diff --git a/toolbox/fs_spec.h b/toolbox/fs_spec.h index 20a8183..e88f9f1 100644 --- a/toolbox/fs_spec.h +++ b/toolbox/fs_spec.h @@ -16,8 +16,11 @@ namespace OS { static int32_t IDForPath(const std::string &path, bool insert = true); static int32_t IDForPath(std::string &&path, bool insert = true); + static int32_t IDForCWD(); + static void Init(); + private: struct Entry diff --git a/toolbox/os_highlevel.cpp b/toolbox/os_highlevel.cpp index ca655a3..e08b2a2 100644 --- a/toolbox/os_highlevel.cpp +++ b/toolbox/os_highlevel.cpp @@ -104,6 +104,8 @@ namespace OS { { // FSMakeFSSpec(vRefNum: Integer; dirID: LongInt; fileName: Str255; VAR spec: FSSpec): OSErr; + // todo -- if the file does not exist (but the path is otherwise valid), create the spec but return fnfErr. + /* * See Chapter 2, File Manager / Using the File Manager, 2-35 * diff --git a/toolbox/os_volume.cpp b/toolbox/os_volume.cpp index b8c4b6e..6f4ae18 100644 --- a/toolbox/os_volume.cpp +++ b/toolbox/os_volume.cpp @@ -292,7 +292,7 @@ namespace OS { // the current wd and return the id. // (FSMakeSpec handles 0 as a dir, so ok for now) // ioWDDirID - memoryWriteLong(0, parm + _ioWDDirID); + memoryWriteLong(FSSpecManager::IDForCWD(), parm + _ioWDDirID); std::string tmp = "MacOS"; ToolBox::WritePString(namePtr, tmp);