1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 18:07:35 +00:00

LibC: Enough compat work to make binutils-2.32 build and run.

This commit is contained in:
Andreas Kling 2019-02-23 17:24:50 +01:00
parent d7753c7c8d
commit a7a456002e
14 changed files with 110 additions and 45 deletions

View file

@ -19,7 +19,7 @@ struct [[gnu::packed]] allocation_t {
size_t nchunk;
};
#define CHUNK_SIZE 64
#define CHUNK_SIZE 32
#define POOL_SIZE (1024 * 1024)
#define ETERNAL_BASE_PHYSICAL 0x100000

View file

@ -4,7 +4,7 @@ if [ $(id -u) != 0 ]; then
fi
rm -vf _fs_contents.lock
rm -vf _fs_contents
dd if=/dev/zero of=_fs_contents bs=1M count=12
dd if=/dev/zero of=_fs_contents bs=1M count=256
mke2fs _fs_contents
chown 1000:1000 _fs_contents
mkdir -vp mnt
@ -32,6 +32,7 @@ ln -s /proc/self/fd/0 mnt/dev/stdin
ln -s /proc/self/fd/1 mnt/dev/stdout
ln -s /proc/self/fd/2 mnt/dev/stderr
cp -vR ../Base/* mnt/
cp -vR ../Root/* mnt/
mkdir mnt/home/anon
mkdir mnt/home/nona
chown -vR 100:100 mnt/home/anon

View file

@ -1,28 +1,3 @@
#include <ctype.h>
#include <string.h>
int ispunct(int c)
{
const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
return !!strchr(punctuation_characters, c);
}
int isprint(int c)
{
return c >= 0x20 && c != 0x7f;
}
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}
int isalpha(int c)
{
return isupper(c) || islower(c);
}
int iscntrl(int c)
{
return (c >= 0 && c <= 0x1f) || c == 0x7f;
}

View file

@ -1,52 +1,86 @@
#pragma once
#include <sys/cdefs.h>
#include <string.h>
__BEGIN_DECLS
ALWAYS_INLINE int isascii(int ch)
ALWAYS_INLINE int __isascii(int ch)
{
return (ch & ~0x7f) == 0;
}
ALWAYS_INLINE int isspace(int ch)
ALWAYS_INLINE int __isspace(int ch)
{
return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v';
}
ALWAYS_INLINE int islower(int c)
ALWAYS_INLINE int __islower(int c)
{
return c >= 'a' && c <= 'z';
}
ALWAYS_INLINE int isupper(int c)
ALWAYS_INLINE int __isupper(int c)
{
return c >= 'A' && c <= 'Z';
}
ALWAYS_INLINE int tolower(int c)
ALWAYS_INLINE int __tolower(int c)
{
if (isupper(c))
if (__isupper(c))
return c | 0x20;
return c;
}
ALWAYS_INLINE int toupper(int c)
ALWAYS_INLINE int __toupper(int c)
{
if (islower(c))
if (__islower(c))
return c & ~0x20;
return c;
}
ALWAYS_INLINE int isdigit(int c)
ALWAYS_INLINE int __isdigit(int c)
{
return c >= '0' && c <= '9';
}
int isalpha(int c);
int isalnum(int c);
int ispunct(int c);
int isprint(int c);
int iscntrl(int c);
ALWAYS_INLINE int __ispunct(int c)
{
const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
return !!strchr(punctuation_characters, c);
}
ALWAYS_INLINE int __isprint(int c)
{
return c >= 0x20 && c != 0x7f;
}
ALWAYS_INLINE int __isalpha(int c)
{
return __isupper(c) || __islower(c);
}
ALWAYS_INLINE int __isalnum(int c)
{
return __isalpha(c) || __isdigit(c);
}
ALWAYS_INLINE int __iscntrl(int c)
{
return (c >= 0 && c <= 0x1f) || c == 0x7f;
}
#define isascii(c) __isascii(c)
#define isspace(c) __isspace(c)
#define islower(c) __islower(c)
#define isupper(c) __isupper(c)
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#define isdigit(c) __isdigit(c)
#define ispunct(c) __ispunct(c)
#define isprint(c) __isprint(c)
#define isalpha(c) __isalpha(c)
#define isalnum(c) __isalnum(c)
#define iscntrl(c) __iscntrl(c)
__END_DECLS

View file

@ -5,3 +5,12 @@
#define PRId8 "d"
#define PRId16 "d"
#define PRId32 "d"
#define PRId64 "lld"
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "u"
#define PRIu64 "llu"
#define PRIx8 "b"
#define PRIx16 "w"
#define PRIx32 "x"
#define PRIx64 "llx"

View file

@ -6,6 +6,7 @@ enum {
LC_ALL,
LC_NUMERIC,
LC_CTYPE,
LC_COLLATE,
};
__BEGIN_DECLS

View file

@ -18,6 +18,12 @@ int killpg(int pgrp, int sig)
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int raise(int sig)
{
// FIXME: Support multi-threaded programs.
return kill(getpid(), sig);
}
sighandler_t signal(int signum, sighandler_t handler)
{
struct sigaction new_act;

View file

@ -33,6 +33,7 @@ int sigdelset(sigset_t*, int sig);
int sigismember(const sigset_t*, int sig);
int sigprocmask(int how, const sigset_t* set, sigset_t* old_set);
int sigpending(sigset_t*);
int raise(int sig);
#define NSIG 32
extern const char* sys_siglist[NSIG];

View file

@ -149,11 +149,12 @@ void __malloc_init()
perror("set_mmap_name failed");
}
void* calloc(size_t nmemb, size_t)
void* calloc(size_t count, size_t size)
{
(void) nmemb;
ASSERT_NOT_REACHED();
return nullptr;
size_t new_size = count * size;
auto* ptr = malloc(new_size);
memset(ptr, 0, new_size);
return ptr;
}
void* realloc(void *ptr, size_t size)
@ -200,6 +201,11 @@ char* getenv(const char* name)
return nullptr;
}
double atof(const char*)
{
assert(false);
}
int atoi(const char* str)
{
size_t len = strlen(str);
@ -298,4 +304,9 @@ ldiv_t ldiv(long numerator, long denominator)
return result;
}
size_t mbstowcs(wchar_t*, const char*, size_t)
{
assert(false);
}
}

View file

@ -83,6 +83,16 @@ struct tm* localtime(const time_t* t)
return &tm_buf;
}
struct tm* gmtime(const time_t* t)
{
return localtime(t);
}
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
{
assert(false);
}
long timezone;
long altzone;
char* tzname[2];

View file

@ -14,6 +14,11 @@
extern "C" {
int chown(const char* pathname, uid_t owner, gid_t group)
{
assert(false);
}
pid_t fork()
{
int rc = syscall(SC_fork);

View file

@ -6,6 +6,8 @@
__BEGIN_DECLS
#define HZ 1000
extern char** environ;
int create_shared_buffer(pid_t peer_pid, size_t, void** buffer);

0
LibC/wchar.h Normal file
View file

View file

@ -263,10 +263,20 @@ static int try_exec(const char* path, char** argv)
int ret = execve(path, argv, environ);
assert(ret < 0);
{
const char* search_path = "/bin";
char pathbuf[128];
sprintf(pathbuf, "%s/%s", search_path, argv[0]);
ret = execve(pathbuf, argv, environ);
assert(ret < 0);
}
{
const char* search_path = "/usr/bin";
char pathbuf[128];
sprintf(pathbuf, "%s/%s", search_path, argv[0]);
ret = execve(pathbuf, argv, environ);
}
if (ret == -1)
return -1;
return ret;