Merge pull request #37 from Dennisbonke/master
posix: Implemented fdopendir
This commit is contained in:
commit
899051c3a9
|
@ -1,7 +1,9 @@
|
|||
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <bits/ensure.h>
|
||||
#include <frg/allocation.hpp>
|
||||
|
@ -22,9 +24,28 @@ int dirfd(DIR *) {
|
|||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
DIR *fdopendir(int) {
|
||||
__ensure(!"Not implemented");
|
||||
__builtin_unreachable();
|
||||
DIR *fdopendir(int fd) {
|
||||
struct stat st;
|
||||
|
||||
if(fstat(fd, &st) < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
// Musl implements this, but O_PATH is only declared on the linux abi
|
||||
/*if(fcntl(fd, F_GETFL) & O_PATH) {
|
||||
errno = EBADF;
|
||||
return nullptr;
|
||||
}*/
|
||||
if(!S_ISDIR(st.st_mode)) {
|
||||
errno = ENOTDIR;
|
||||
return nullptr;
|
||||
}
|
||||
auto dir = frg::construct<__mlibc_dir_struct>(getAllocator());
|
||||
__ensure(dir);
|
||||
dir->__ent_next = 0;
|
||||
dir->__ent_limit = 0;
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
dir->__handle = fd;
|
||||
return dir;
|
||||
}
|
||||
DIR *opendir(const char *path) {
|
||||
if(!mlibc::sys_open_dir) {
|
||||
|
|
|
@ -384,9 +384,42 @@ int sys_fcntl(int fd, int request, va_list args, int *result) {
|
|||
*result = resp.flags();
|
||||
return 0;
|
||||
}else if(request == F_SETFD) {
|
||||
mlibc::infoLogger() << "\e[31mmlibc: fcntl(F_SETFD) is not implemented correctly"
|
||||
<< "\e[39m" << frg::endlog;
|
||||
*result = 0;
|
||||
HelAction actions[3];
|
||||
globalQueue.trim();
|
||||
|
||||
managarm::posix::CntRequest<MemoryAllocator> req(getSysdepsAllocator());
|
||||
req.set_request_type(managarm::posix::CntReqType::FD_SET_FLAGS);
|
||||
req.set_fd(fd);
|
||||
req.set_flags(va_arg(args, int));
|
||||
|
||||
frg::string<MemoryAllocator> ser(getSysdepsAllocator());
|
||||
req.SerializeToString(&ser);
|
||||
actions[0].type = kHelActionOffer;
|
||||
actions[0].flags = kHelItemAncillary;
|
||||
actions[1].type = kHelActionSendFromBuffer;
|
||||
actions[1].flags = kHelItemChain;
|
||||
actions[1].buffer = ser.data();
|
||||
actions[1].length = ser.size();
|
||||
actions[2].type = kHelActionRecvInline;
|
||||
actions[2].flags = 0;
|
||||
HEL_CHECK(helSubmitAsync(getPosixLane(), actions, 3,
|
||||
globalQueue.getQueue(), 0, 0));
|
||||
|
||||
auto element = globalQueue.dequeueSingle();
|
||||
auto offer = parseSimple(element);
|
||||
auto send_req = parseSimple(element);
|
||||
auto recv_resp = parseInline(element);
|
||||
|
||||
HEL_CHECK(offer->error);
|
||||
HEL_CHECK(send_req->error);
|
||||
HEL_CHECK(recv_resp->error);
|
||||
|
||||
managarm::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
|
||||
resp.ParseFromArray(recv_resp->data, recv_resp->length);
|
||||
if(resp.error() == managarm::posix::Errors::NO_SUCH_FD)
|
||||
return EBADF;
|
||||
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
|
||||
*result = resp.error();
|
||||
return 0;
|
||||
}else if(request == F_GETFL) {
|
||||
SignalGuard sguard;
|
||||
|
|
Loading…
Reference in a new issue