mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:17:35 +00:00
LibC: Enough compat work to make binutils-2.32 build and run.
This commit is contained in:
parent
d7753c7c8d
commit
a7a456002e
14 changed files with 110 additions and 45 deletions
|
@ -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;
|
||||
}
|
||||
|
|
62
LibC/ctype.h
62
LibC/ctype.h
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -6,6 +6,7 @@ enum {
|
|||
LC_ALL,
|
||||
LC_NUMERIC,
|
||||
LC_CTYPE,
|
||||
LC_COLLATE,
|
||||
};
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
0
LibC/wchar.h
Normal file
Loading…
Add table
Add a link
Reference in a new issue