LibC/Shell: set PWD env in Shell, not libc
I have no idea why I was doing it in the libc
This commit is contained in:
parent
2d19b5074e
commit
28275d86ea
|
@ -426,10 +426,9 @@ char* getcwd(char* buf, size_t size)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((char*)syscall(SYS_GET_PWD, buf, size) == nullptr)
|
if (syscall(SYS_GET_PWD, buf, size) == 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
setenv("PWD", buf, 1);
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,21 +134,20 @@ void Builtin::initialize()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::StringView path;
|
const char* path = nullptr;
|
||||||
|
if (arguments.size() == 2)
|
||||||
if (arguments.size() == 1)
|
path = arguments[1].data();
|
||||||
{
|
|
||||||
if (const char* path_env = getenv("HOME"))
|
|
||||||
path = path_env;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
path = arguments[1];
|
path = getenv("HOME");
|
||||||
|
|
||||||
if (chdir(path.data()) == -1)
|
if (path == nullptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (chdir(path) == -1)
|
||||||
ERROR_RETURN("chdir", 1);
|
ERROR_RETURN("chdir", 1);
|
||||||
|
|
||||||
|
setenv("PWD", path, 1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}, true
|
}, true
|
||||||
));
|
));
|
||||||
|
|
|
@ -28,6 +28,12 @@ int main(int argc, char** argv)
|
||||||
sigaction(SIGTTOU, &sa, nullptr);
|
sigaction(SIGTTOU, &sa, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
char cwd_buffer[PATH_MAX];
|
||||||
|
if (getcwd(cwd_buffer, sizeof(cwd_buffer)))
|
||||||
|
setenv("PWD", cwd_buffer, 1);
|
||||||
|
}
|
||||||
|
|
||||||
Builtin::get().initialize();
|
Builtin::get().initialize();
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
|
|
Loading…
Reference in New Issue