mirror of
https://github.com/ksherlock/mpw.git
synced 2024-11-22 00:32:44 +00:00
temporary realpath workaround
This commit is contained in:
parent
6787eb1f1a
commit
b60d23ea60
@ -35,6 +35,8 @@
|
|||||||
#include <sys/xattr.h>
|
#include <sys/xattr.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/paths.h>
|
#include <sys/paths.h>
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -72,6 +74,31 @@ namespace OS {
|
|||||||
// MacOS: -> { -1, 1, "MacOS" }
|
// MacOS: -> { -1, 1, "MacOS" }
|
||||||
// MacOS:dumper -> {-1, 2 "dumper"}
|
// MacOS:dumper -> {-1, 2 "dumper"}
|
||||||
|
|
||||||
|
std::string realpath(const std::string &path)
|
||||||
|
{
|
||||||
|
char buffer[PATH_MAX + 1];
|
||||||
|
|
||||||
|
// TODO -- FSSpecs are valid for non-existant files
|
||||||
|
// but not non-existant directories.
|
||||||
|
// realpath does not behave in such a manner.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// expand the path. Also handles relative paths.
|
||||||
|
char *cp = ::realpath(path.c_str(), buffer);
|
||||||
|
if (!cp)
|
||||||
|
{
|
||||||
|
// temporary workaround - return if it's just a filename w/o a path.
|
||||||
|
if (path.find('/') == path.npos) return path;
|
||||||
|
|
||||||
|
fprintf(stderr, "realpath failed %s\n", path.c_str());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string(cp);
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t FSMakeFSSpec(void)
|
uint16_t FSMakeFSSpec(void)
|
||||||
{
|
{
|
||||||
// FSMakeFSSpec(vRefNum: Integer; dirID: LongInt; fileName: Str255; VAR spec: FSSpec): OSErr;
|
// FSMakeFSSpec(vRefNum: Integer; dirID: LongInt; fileName: Str255; VAR spec: FSSpec): OSErr;
|
||||||
@ -114,42 +141,32 @@ namespace OS {
|
|||||||
bool absolute = sname.length() ? sname[0] == '/' : false;
|
bool absolute = sname.length() ? sname[0] == '/' : false;
|
||||||
if (absolute || (vRefNum == 0 && dirID == 0))
|
if (absolute || (vRefNum == 0 && dirID == 0))
|
||||||
{
|
{
|
||||||
char buffer[PATH_MAX + 1];
|
|
||||||
|
|
||||||
// TODO -- FSSpecs are valid for non-existant files
|
|
||||||
// but not non-existant directories.
|
|
||||||
// realpath does not behave in such a manner.
|
|
||||||
|
|
||||||
// expand the path. Also handles relative paths.
|
|
||||||
char *cp = realpath(sname.c_str(), buffer);
|
|
||||||
if (!cp)
|
|
||||||
{
|
|
||||||
std::memset(memoryPointer(spec), 0, 8);
|
|
||||||
return MacOS::mFulErr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string leaf;
|
std::string leaf;
|
||||||
std::string path;
|
std::string path;
|
||||||
|
int parentID;
|
||||||
|
|
||||||
|
path = realpath(sname);
|
||||||
path.assign(cp);
|
if (path.empty())
|
||||||
|
{
|
||||||
// if sname is null then the target is the default directory...
|
std::memset(memoryPointer(spec), 0, 8);
|
||||||
// so this should be ok.
|
return MacOS::mFulErr;
|
||||||
|
}
|
||||||
|
|
||||||
int pos = path.find_last_of('/');
|
int pos = path.find_last_of('/');
|
||||||
if (pos == path.npos)
|
if (pos == path.npos)
|
||||||
{
|
{
|
||||||
// ? should never happen...
|
// file is relative to cwd.
|
||||||
std::swap(leaf, path);
|
leaf = std::move(path);
|
||||||
|
parentID = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
leaf = path.substr(pos + 1);
|
leaf = path.substr(pos + 1);
|
||||||
path = path.substr(0, pos + 1); // include the /
|
path = path.substr(0, pos + 1); // include the /
|
||||||
|
parentID = FSSpecManager::IDForPath(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parentID = FSSpecManager::IDForPath(path, true);
|
|
||||||
|
|
||||||
memoryWriteWord(vRefNum, spec + 0);
|
memoryWriteWord(vRefNum, spec + 0);
|
||||||
memoryWriteLong(parentID, spec + 2);
|
memoryWriteLong(parentID, spec + 2);
|
||||||
@ -305,7 +322,7 @@ namespace OS {
|
|||||||
return RM::FSpOpenResFile();
|
return RM::FSpOpenResFile();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "selector %04x not yet supported\n", selector);
|
fprintf(stderr, "HighLevelHFSDispatch selector %04x not yet supported\n", selector);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user