mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-12-27 18:30:39 +00:00
pathname conversion -- handle dev:null, dev:stdout, dev:stdin, dev:stderr
This commit is contained in:
parent
1339c0891f
commit
a8920e2f53
@ -13,7 +13,10 @@
|
||||
|
||||
|
||||
|
||||
|
||||
namespace ToolBox {
|
||||
std::string MacToUnix(const std::string path);
|
||||
std::string UnixToMac(const std::string path);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T pop(std::vector<T> &v) {
|
||||
@ -42,7 +45,9 @@ int open(const std::string &name, int flags) {
|
||||
|
||||
// dup2 does not copy the O_CLOEXEC flag so it's safe to use.
|
||||
|
||||
int fd = ::open(name.c_str(), flags | O_CLOEXEC, 0666);
|
||||
std::string uname = ToolBox::MacToUnix(name);
|
||||
|
||||
int fd = ::open(uname.c_str(), flags | O_CLOEXEC, 0666);
|
||||
if (fd < 0) {
|
||||
open_error(name);
|
||||
return -1;
|
||||
|
34
pathnames.rl
34
pathnames.rl
@ -117,11 +117,42 @@ namespace {
|
||||
write data;
|
||||
}%%
|
||||
|
||||
%%{
|
||||
machine dev;
|
||||
|
||||
main :=
|
||||
'/dev/null'i $eof{ return "/dev/null"; }
|
||||
|
|
||||
'/dev/stderr'i $eof{ return "/dev/stderr"; }
|
||||
|
|
||||
'/dev/stdout'i $eof{ return "/dev/stdout"; }
|
||||
;
|
||||
write data;
|
||||
}%%
|
||||
|
||||
}
|
||||
|
||||
namespace ToolBox
|
||||
{
|
||||
|
||||
std::string check_dev(std::string &&str) {
|
||||
|
||||
const char *p = str.c_str();
|
||||
const char *pe = p + str.length();
|
||||
const char *eof = pe;
|
||||
|
||||
int cs;
|
||||
%%{
|
||||
machine dev;
|
||||
write init;
|
||||
write exec;
|
||||
|
||||
}%%
|
||||
|
||||
return str;
|
||||
|
||||
}
|
||||
|
||||
std::string MacToUnix(const std::string path)
|
||||
{
|
||||
|
||||
@ -173,8 +204,7 @@ namespace ToolBox
|
||||
write exec;
|
||||
}%%
|
||||
|
||||
|
||||
return rv;
|
||||
return check_dev(std::move(rv));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user