Compare commits

..

No commits in common. "1b4f48b92c23a3bb17b131523eb93139fe988096" and "3a45f4af53abd18d92459981aa614258a77787d3" have entirely different histories.

8 changed files with 3 additions and 112 deletions

View File

@ -74,17 +74,7 @@ int main(int argc, char** argv)
while (1) while (1)
{ {
if (file == "-") if (file == "-") fputs(getuid() == 0 ? "sh# " : "sh$ ", stdout);
{
char* cwd = getcwd(NULL, 0);
if (!cwd)
{
perror("getcwd");
return 1;
}
printf("sh %s%c ", cwd, getuid() == 0 ? '#' : '$');
free(cwd);
}
char cmd[4096]; char cmd[4096];
char* rc = fgets(cmd, sizeof(cmd), f); char* rc = fgets(cmd, sizeof(cmd), f);

View File

@ -36,22 +36,3 @@ Result<u64> sys_chdir(Registers*, SyscallArgs args)
return 0; return 0;
} }
} }
Result<u64> sys_getcwd(Registers*, SyscallArgs args)
{
u8* buf = (u8*)args[0];
usize size = (usize)args[1];
Thread* current = Scheduler::current();
StringView cwd = current->current_directory_path.view();
if (cwd.is_empty()) cwd = "/"_sv;
usize cwd_size = cwd.length() + 1;
if (cwd_size > size) return cwd_size;
if (!MemoryManager::copy_to_user(buf, cwd.chars(), cwd_size)) return err(EFAULT);
return cwd_size;
}

View File

@ -41,7 +41,7 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
// FIXME: Make sure argv & envp are not too big. // FIXME: Make sure argv & envp are not too big.
auto inode = TRY(VFS::resolve_path(path.chars(), current->auth, current->current_directory)); auto inode = TRY(VFS::resolve_path(path.chars(), current->auth));
if (!VFS::can_execute(inode, current->auth)) return err(EACCES); if (!VFS::can_execute(inode, current->auth)) return err(EACCES);

View File

@ -100,9 +100,6 @@ extern "C"
/* Change the current working directory. */ /* Change the current working directory. */
int chdir(const char* path); int chdir(const char* path);
/* Retrieve the current working directory. */
char* getcwd(char* buf, size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -235,69 +235,4 @@ extern "C"
long rc = syscall(SYS_chdir, path); long rc = syscall(SYS_chdir, path);
__errno_return(rc, int); __errno_return(rc, int);
} }
static ssize_t __getcwd_wrapper(char* buf, size_t size)
{
long rc = syscall(SYS_getcwd, buf, size);
__errno_return(rc, ssize_t);
}
char* getcwd(char* buf, size_t size)
{
if (buf)
{
ssize_t rc = __getcwd_wrapper(buf, size);
if (rc < 0) return nullptr;
if (rc > (ssize_t)size)
{
errno = ERANGE;
return nullptr;
}
return buf;
}
else if (size)
{
buf = (char*)malloc(size);
if (!buf) return nullptr;
ssize_t rc = __getcwd_wrapper(buf, size);
if (rc < 0)
{
free(buf);
return nullptr;
}
if (rc > (ssize_t)size)
{
free(buf);
errno = ERANGE;
return nullptr;
}
return buf;
}
else
{
buf = (char*)malloc(1024);
if (!buf) return nullptr;
ssize_t rc = __getcwd_wrapper(buf, 1024);
if (rc < 0)
{
free(buf);
return nullptr;
}
if (rc > 1024)
{
free(buf);
return getcwd(NULL, rc);
}
return buf;
}
}
} }

View File

@ -16,8 +16,6 @@ class StringView
StringView(const StringView&); StringView(const StringView&);
StringView& operator=(const StringView&);
Result<String> to_string(); Result<String> to_string();
const char* chars() const const char* chars() const

View File

@ -4,7 +4,7 @@
_e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \ _e(exit) _e(clock_gettime) _e(mmap) _e(munmap) _e(usleep) _e(open) _e(close) _e(read) _e(getpid) _e(write) \
_e(lseek) _e(mkdir) _e(execve) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents) _e(getuid) \ _e(lseek) _e(mkdir) _e(execve) _e(mknod) _e(fork) _e(waitpid) _e(getppid) _e(fcntl) _e(getdents) _e(getuid) \
_e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \ _e(geteuid) _e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(chmod) _e(chown) \
_e(ioctl) _e(stat) _e(fstat) _e(chdir) _e(getcwd) _e(ioctl) _e(stat) _e(fstat) _e(chdir)
enum Syscalls enum Syscalls
{ {

View File

@ -30,16 +30,6 @@ StringView::StringView(const char* c_str, usize length)
m_length = length; m_length = length;
} }
StringView& StringView::operator=(const StringView& other)
{
if (&other == this) return *this;
m_string = other.m_string;
m_length = other.m_length;
return *this;
}
const char& StringView::operator[](usize index) const const char& StringView::operator[](usize index) const
{ {
expect(index < m_length, "index out of range"); expect(index < m_length, "index out of range");