HGetVol returns the current working directory id

This commit is contained in:
Kelvin Sherlock 2015-01-18 14:28:05 -05:00
parent 3615fbe941
commit 44d19f7d1b
4 changed files with 24 additions and 4 deletions

View File

@ -2,6 +2,8 @@
#include <algorithm>
#include <cassert>
#include <unistd.h>
#include <sys/param.h>
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<std::string> 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;

View File

@ -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

View File

@ -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
*

View File

@ -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);