libc: Fill in a few stubs for weston

This commit is contained in:
Alexander van der Grinten 2018-02-11 20:06:51 +01:00
parent 11bef71d03
commit 21cc551dfd
4 changed files with 44 additions and 15 deletions

View file

@ -3,6 +3,7 @@
#include <bits/ensure.h>
#include <frigg/debug.hpp>
#include <mlibc/sysdeps.hpp>
clock_t clock(void) {
@ -34,14 +35,17 @@ struct tm *gmtime(const time_t *timer) {
__ensure(!"Not implemented");
__builtin_unreachable();
}
struct tm *localtime(const time_t *timer) {
__ensure(!"Not implemented");
__builtin_unreachable();
struct tm *localtime(const time_t *t) {
static thread_local struct tm per_thread_tm;
return localtime_r(t, &per_thread_tm);
}
size_t strftime(char *__restrict dest, size_t max_size,
const char *__restrict format, const struct tm *__restrict ptr) {
__ensure(!"Not implemented");
__builtin_unreachable();
const char *__restrict, const struct tm *__restrict) {
frigg::infoLogger() << "\e[31mmlibc: strftime always writes an"
" empty string\e[39m" << frigg::endLog;
__ensure(max_size > 0);
dest[0] = 0;
return 0;
}
// POSIX extensions.
@ -76,9 +80,11 @@ int utimes(const char *, const struct timeval[2]) {
__builtin_unreachable();
}
struct tm *localtime_r(const time_t *, struct tm *) {
__ensure(!"Not implemented");
__builtin_unreachable();
struct tm *localtime_r(const time_t *t, struct tm *tm) {
frigg::infoLogger() << "\e[31mmlibc: localtime_r always returns a"
" zero date\e[39m" << frigg::endLog;
memset(tm, 0, sizeof(struct tm));
return tm;
}
time_t time(time_t *out) {

View file

@ -1,7 +1,9 @@
#include <errno.h>
#include <stdio.h>
#include <bits/ensure.h>
#include <frigg/debug.hpp>
int fileno(FILE *file) {
return file->fd;
@ -28,7 +30,9 @@ FILE *popen(const char*, const char *) {
}
FILE *open_memstream(char **, size_t *) {
__ensure(!"Not implemented");
__builtin_unreachable();
frigg::infoLogger() << "\e[31mmlibc: open_memstream() always fails"
<< "\e[39m" << frigg::endLog;
errno = ENOMEM;
return nullptr;
}

View file

@ -2,8 +2,16 @@
#include <sys/utsname.h>
#include <bits/ensure.h>
int uname(struct utsname *) {
__ensure(!"Not implemented");
__builtin_unreachable();
#include <frigg/debug.hpp>
int uname(struct utsname *p) {
__ensure(p);
frigg::infoLogger() << "\e[31mmlibc: uname() returns static information\e[39m" << frigg::endLog;
strcpy(p->sysname, "managarm");
strcpy(p->nodename, "foo");
strcpy(p->release, "0.1.0");
strcpy(p->version, "0.1.0 vanilla");
strcpy(p->machine, "x86_64");
return 0;
}

View file

@ -126,6 +126,14 @@ int fcntl(int fd, int request, ...) {
frigg::infoLogger() << "\e[31mmlibc: fcntl(F_DUPFD_CLOEXEC) is not implemented correctly"
<< "\e[39m" << frigg::endLog;
return dup2(fd, -1);
}else if(request == F_GETFD) {
frigg::infoLogger() << "\e[31mmlibc: fcntl(F_GETFD) is not implemented correctly"
<< "\e[39m" << frigg::endLog;
return 0;
}else if(request == F_SETFD) {
frigg::infoLogger() << "\e[31mmlibc: fcntl(F_SETFD) is not implemented correctly"
<< "\e[39m" << frigg::endLog;
return 0;
}else{
frigg::infoLogger() << "\e[31mmlibc: Unexpected fcntl() request: "
<< request << "\e[39m" << frigg::endLog;
@ -351,7 +359,10 @@ int socketpair(int domain, int type, int proto, int *fds) {
#include <sys/epoll.h>
int epoll_create1(int flags) {
__ensure(!flags);
__ensure(!(flags & ~(EPOLL_CLOEXEC)));
if(flags & EPOLL_CLOEXEC)
frigg::infoLogger() << "\e[31mmlibc: epoll_create1(EPOLL_CLOEXEC)"
" is not implemented correctly\e[39m" << frigg::endLog;
HelAction actions[3];
globalQueue.trim();