Skip to content

Commit 303577d

Browse files
committed
Various stubs while trying to get an old coreutils to build.
1 parent e440c3f commit 303577d

20 files changed

+132
-23
lines changed

LibC/dirent.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55
#include <string.h>
66
#include <errno.h>
7+
#include <fcntl.h>
78
#include <Kernel/Syscall.h>
89

910
extern "C" {

LibC/errno_numbers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
__ERROR(EOPNOTSUPP, "Operation not supported") \
4141
__ERROR(ENOSYS, "No such syscall") \
4242
__ERROR(ENOTIMPL, "Not implemented") \
43+
__ERROR(EAFNOSUPPORT, "Address family not supported") \
4344

4445
enum __errno_values {
4546
#undef __ERROR

LibC/fcntl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ __BEGIN_DECLS
1212

1313
#define FD_CLOEXEC 1
1414

15+
#define O_RDONLY 0
16+
#define O_WRONLY 1
17+
#define O_RDWR 2
18+
#define O_CREAT 0100
19+
#define O_EXCL 0200
20+
#define O_NOCTTY 0400
21+
#define O_TRUNC 01000
22+
#define O_APPEND 02000
23+
#define O_NONBLOCK 04000
24+
#define O_DIRECTORY 00200000
25+
#define O_NOFOLLOW 00400000
26+
#define O_CLOEXEC 02000000
27+
1528
int fcntl(int fd, int cmd, ...);
1629

1730
__END_DECLS

LibC/limits.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
#define INT_MAX INT32_MAX
99
#define INT_MIN INT32_MIN
1010

11+
#define UINT_MAX UINT32_MAX
12+
#define UINT_MIN UINT32_MIN
13+
1114
#define CHAR_BIT 8
1215
#define SCHAR_MIN (-128)
1316
#define SCHAR_MAX 127
1417
#define UCHAR_MAX 255
18+
19+
#define LONG_MAX 2147483647L
20+
#define LONG_MIN (-LONG_MAX - 1L)
21+
22+
#define CHAR_MIN SCHAR_MIN
23+
#define CHAR_MAX SCHAR_MAX
24+
25+
#define MB_LEN_MAX 16

LibC/locale.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <sys/cdefs.h>
4+
5+
enum {
6+
LC_ALL,
7+
LC_NUMERIC,
8+
};
9+
10+
__BEGIN_DECLS
11+
12+
char* setlocale(int category, const char* locale);
13+
14+
__END_DECLS
15+

LibC/stdio.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <assert.h>
88
#include <stdlib.h>
99
#include <unistd.h>
10+
#include <fcntl.h>
1011
#include <Kernel/Syscall.h>
1112
#include <AK/printf.cpp>
1213

LibC/stdlib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ void* realloc(void *ptr, size_t size)
6666

6767
void exit(int status)
6868
{
69-
Syscall::invoke(Syscall::SC_exit, (dword)status);
70-
for (;;);
69+
_exit(status);
70+
assert(false);
7171
}
7272

7373
void abort()

LibC/stdlib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
__BEGIN_DECLS
77

8+
#define EXIT_SUCCESS 0
9+
#define EXIT_FAILURE 1
10+
811
void* malloc(size_t) __MALLOC;
912
void free(void*);
1013
void* calloc(size_t nmemb, size_t);

LibC/string.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ int memcmp(const void* v1, const void* v2, size_t n)
9090
return 0;
9191
}
9292

93-
void memcpy(void* dest, const void* src, size_t n)
93+
void* memcpy(void* dest, const void* src, size_t n)
9494
{
9595
auto* bdest = (unsigned char*)dest;
9696
auto* bsrc = (const unsigned char*)src;
9797
for (; n; --n)
9898
*(bdest++) = *(bsrc++);
99+
return dest;
99100
}
100101

101-
void memmove(void* dest, const void* src, size_t n)
102+
void* memmove(void* dest, const void* src, size_t n)
102103
{
103104
if (dest < src)
104105
return memcpy(dest, src, n);

LibC/string.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ size_t strlen(const char*);
99
int strcmp(const char*, const char*);
1010
int strncmp(const char*, const char*, size_t);
1111
int memcmp(const void*, const void*, size_t);
12-
void memcpy(void*, const void*, size_t);
13-
void memmove(void*, const void*, size_t);
12+
void* memcpy(void*, const void*, size_t);
13+
void* memmove(void*, const void*, size_t);
1414
void bzero(void*, size_t);
1515
void bcopy(const void*, void*, size_t);
1616
void* memset(void*, int, size_t);

0 commit comments

Comments
 (0)