mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibC: Implement various things to get GNU bc building and running.
Looks like that's all we needed, and bc now runs. :^)
This commit is contained in:
parent
3a9c01619f
commit
c2adfd0e2d
Notes:
sideshowbarker
2024-07-19 15:53:10 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c2adfd0e2d1
9 changed files with 51 additions and 2 deletions
|
@ -133,6 +133,11 @@ int getchar()
|
|||
return getc(stdin);
|
||||
}
|
||||
|
||||
int ungetc(int, FILE*)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
int fputc(int ch, FILE* stream)
|
||||
{
|
||||
assert(stream);
|
||||
|
|
|
@ -40,6 +40,7 @@ int fileno(FILE*);
|
|||
int fgetc(FILE*);
|
||||
int getc(FILE*);
|
||||
int getchar();
|
||||
int ungetc(int c, FILE*);
|
||||
FILE* fdopen(int fd, const char* mode);
|
||||
FILE* fopen(const char* pathname, const char* mode);
|
||||
int fclose(FILE*);
|
||||
|
|
|
@ -262,4 +262,9 @@ void srandom(unsigned seed)
|
|||
srand(seed);
|
||||
}
|
||||
|
||||
int system(const char* command)
|
||||
{
|
||||
return execl("/bin/sh", "sh", "-c", command, nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ void abort() __NORETURN;
|
|||
char* ptsname(int fd);
|
||||
int ptsname_r(int fd, char* buffer, size_t);
|
||||
int abs(int);
|
||||
int system(const char* command);
|
||||
|
||||
#define RAND_MAX 32767
|
||||
int rand();
|
||||
|
|
|
@ -186,6 +186,17 @@ char* strchr(const char* str, int c)
|
|||
}
|
||||
}
|
||||
|
||||
void* memchr(const void* ptr, int c, size_t size)
|
||||
{
|
||||
char ch = c;
|
||||
char* cptr = (char*)ptr;
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (cptr[i] == ch)
|
||||
return cptr + i;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* strrchr(const char* str, int ch)
|
||||
{
|
||||
char *last = nullptr;
|
||||
|
|
|
@ -11,6 +11,7 @@ int strncmp(const char*, const char*, size_t);
|
|||
int memcmp(const void*, const void*, size_t);
|
||||
void* memcpy(void*, const void*, size_t);
|
||||
void* memmove(void*, const void*, size_t);
|
||||
void* memchr(const void*, int c, size_t);
|
||||
void bzero(void*, size_t);
|
||||
void bcopy(const void*, void*, size_t);
|
||||
void* memset(void*, int, size_t);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -26,9 +27,28 @@ int execve(const char* filename, char* const argv[], char* const envp[])
|
|||
|
||||
int execvp(const char* filename, char* const argv[])
|
||||
{
|
||||
// FIXME: This should do some sort of shell-like path resolution!
|
||||
return execve(filename, argv, nullptr);
|
||||
}
|
||||
|
||||
int execl(const char* filename, const char* arg0, ...)
|
||||
{
|
||||
Vector<const char*> args;
|
||||
args.append(arg0);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, arg0);
|
||||
for (;;) {
|
||||
const char* arg = va_arg(ap, const char*);
|
||||
if (!arg)
|
||||
break;
|
||||
args.append(arg);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
return execve(filename, (char* const *)args.data(), nullptr);
|
||||
}
|
||||
|
||||
uid_t getuid()
|
||||
{
|
||||
return syscall(SC_getuid);
|
||||
|
|
|
@ -13,6 +13,7 @@ inline int getpagesize() { return 4096; }
|
|||
pid_t fork();
|
||||
int execve(const char* filename, char* const argv[], char* const envp[]);
|
||||
int execvp(const char* filename, char* const argv[]);
|
||||
int execl(const char* filename, const char* arg, ...);
|
||||
void sync();
|
||||
void _exit(int status);
|
||||
pid_t getsid(pid_t);
|
||||
|
|
|
@ -358,13 +358,12 @@ static void greeting()
|
|||
printf("\n%s/%s on %s\n\n", uts.sysname, uts.machine, g->ttyname);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
g = new GlobalState;
|
||||
g->uid = getuid();
|
||||
g->sid = setsid();
|
||||
tcsetpgrp(0, getpgrp());
|
||||
|
||||
tcgetattr(0, &g->termios);
|
||||
|
||||
{
|
||||
|
@ -391,6 +390,11 @@ int main(int, char**)
|
|||
endpwent();
|
||||
}
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-c")) {
|
||||
fprintf(stderr, "FIXME: Implement /bin/sh -c\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
greeting();
|
||||
|
||||
char linebuf[128];
|
||||
|
|
Loading…
Reference in a new issue