Provide a default implementation of chdir, fix #68

The default implementation relies on the sequence open, fchdir, close.
Enable this implementation for the Noux libc plugin.
This commit is contained in:
Julian Stecklina 2012-01-09 21:30:25 +01:00 committed by Norman Feske
parent d43126e8e7
commit 3c54d39307
2 changed files with 13 additions and 1 deletions

View File

@ -110,6 +110,18 @@ bool Plugin::supports_unlink(const char*)
return false;
}
/**
* Default implementations
*/
int Plugin::chdir(const char *path)
{
Libc::File_descriptor *fd = open(path, 0 /* no rights necessary */);
bool success = ((fd != NULL)
and (fchdir(fd) == 0)
and (close(fd) == 0));
return success ? 0 : -1;
}
/**
* Generate dummy member function of Plugin class
@ -161,7 +173,6 @@ DUMMY(ssize_t, -1, write, (File_descriptor *, const void *, ::size_t));
/*
* Misc
*/
DUMMY(int, -1, chdir, (const char*));
DUMMY(void, , freeaddrinfo, (struct ::addrinfo *));
DUMMY(int, -1, getaddrinfo, (const char *, const char *, const struct ::addrinfo *, struct ::addrinfo **));
DUMMY(int, -1, mkdir, (const char*, mode_t));

View File

@ -331,6 +331,7 @@ namespace {
_stderr(Libc::file_descriptor_allocator()->alloc(this, noux_context(2), 2))
{ }
bool supports_chdir(const char *) { return true; }
bool supports_open(const char *, int) { return true; }
bool supports_stat(const char *) { return true; }