aboutsummaryrefslogtreecommitdiff
path: root/src/libc/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/libc/include')
-rw-r--r--src/libc/include/errno.h119
-rw-r--r--src/libc/include/fcntl.h29
-rw-r--r--src/libc/include/inttypes.h34
-rw-r--r--src/libc/include/stdint.h33
-rw-r--r--src/libc/include/stdio.h15
-rw-r--r--src/libc/include/stdlib.h6
-rw-r--r--src/libc/include/string.h23
-rw-r--r--src/libc/include/sys/stat.h40
-rw-r--r--src/libc/include/sys/types.h25
-rw-r--r--src/libc/include/time.h39
10 files changed, 352 insertions, 11 deletions
diff --git a/src/libc/include/errno.h b/src/libc/include/errno.h
index 0456645..60037ef 100644
--- a/src/libc/include/errno.h
+++ b/src/libc/include/errno.h
@@ -1,3 +1,21 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef _ERRNO_H
#define _ERRNO_H
@@ -5,7 +23,7 @@ extern int errno;
enum
{
- OK,
+ SUCCESS,
EPERM,
ENOENT,
ESRCH,
@@ -38,6 +56,105 @@ enum
EROFS,
EMLINK,
EPIPE,
+ EDOM,
+ ERANGE,
+ EDEADLK,
+ ENAMETOOLONG,
+ ENOLCK,
+ ENOSYS,
+ ENOTEMPTY,
+ ELOOP,
+ ENOMSG,
+ EIDRM,
+ ECHRNG,
+ EL2NSYNC,
+ EL3HLT,
+ EL3RST,
+ ELNRNG,
+ EUNATCH,
+ ENOCSI,
+ EL2HLT,
+ EBADE,
+ EBADR,
+ EXFULL,
+ ENOANO,
+ EBADRQC,
+ EBADSLT,
+ EBFONT,
+ ENOSTR,
+ ENODATA,
+ ETIME,
+ ENOSR,
+ ENONET,
+ ENOPKG,
+ EREMOTE,
+ ENOLINK,
+ EADV,
+ ESRMNT,
+ ECOMM,
+ EPROTO,
+ EMULTIHOP,
+ EDOTDOT,
+ EBADMSG,
+ EOVERFLOW,
+ ENOTUNIQ,
+ EBADFD,
+ EREMCHG,
+ ELIBACC,
+ ELIBBAD,
+ ELIBSCN,
+ ELIBMAX,
+ ELIBEXEC,
+ EILSEQ,
+ ERESTART,
+ ESTRPIPE,
+ EUSERS,
+ ENOTSOCK,
+ EDESTADDRREQ,
+ EMSGSIZE,
+ EPROTOTYPE,
+ ENOPROTOOPT,
+ EPROTONOSUPPORT,
+ ESOCKTNOSUPPORT,
+ ENOTSUP,
+ EPFNOSUPPORT,
+ EAFNOSUPPORT,
+ EADDRINUSE,
+ EADDRNOTAVAIL,
+ ENETDOWN,
+ ENETUNREACH,
+ ENETRESET,
+ ECONNABORTED,
+ ECONNRESET,
+ ENOBUFS,
+ EISCONN,
+ ENOTCONN,
+ ESHUTDOWN,
+ ETOOMANYREFS,
+ ETIMEDOUT,
+ ECONNREFUSED,
+ EHOSTDOWN,
+ EHOSTUNREACH,
+ EALREADY,
+ EINPROGRESS,
+ ESTALE,
+ EUCLEAN,
+ ENOTNAM,
+ ENAVAIL,
+ EISNAM,
+ EREMOTEIO,
+ EDQUOT,
+ ENOMEDIUM,
+ EMEDIUMTYPE,
+ ECANCELED,
+ ENOKEY,
+ EKEYEXPIRED,
+ EKEYREVOKED,
+ EKEYREJECTED,
+ EOWNERDEAD,
+ ENOTRECOVERABLE,
+ ERFKILL,
+ EHWPOISON
};
#endif
diff --git a/src/libc/include/fcntl.h b/src/libc/include/fcntl.h
new file mode 100644
index 0000000..9713a9f
--- /dev/null
+++ b/src/libc/include/fcntl.h
@@ -0,0 +1,29 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef _FCNTL_H
+#define _FCNTL_H
+
+enum
+{
+ O_RDONLY = 1,
+ O_WRONLY = 1 << 1,
+ O_RDWR = O_RDONLY | O_WRONLY
+};
+
+#endif
diff --git a/src/libc/include/inttypes.h b/src/libc/include/inttypes.h
new file mode 100644
index 0000000..f07e94b
--- /dev/null
+++ b/src/libc/include/inttypes.h
@@ -0,0 +1,34 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#ifndef _INTTYPES_H
+#define _INTTYPES_H
+
+#define PRIu8 "hhu"
+#define PRIu16 "hu"
+#define PRIu32 "lu"
+#define PRIu64 "llu"
+#define PRIi8 "hhd"
+#define PRIi16 "hd"
+#define PRIi32 "ld"
+#define PRIi64 "lld"
+#define PRIx8 "hhx"
+#define PRIx16 "hx"
+#define PRIx32 "lx"
+#define PRIx64 "llx"
+
+#endif
diff --git a/src/libc/include/stdint.h b/src/libc/include/stdint.h
new file mode 100644
index 0000000..d2701b1
--- /dev/null
+++ b/src/libc/include/stdint.h
@@ -0,0 +1,33 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef _STDINT_H
+#define _STDINT_H
+
+typedef unsigned char uint8_t, uint_least8_t;
+typedef signed char int8_t, int_least8_t;
+typedef unsigned short uint16_t, uint_least16_t;
+typedef short int16_t, int_least16_t;
+typedef unsigned uintptr_t, uint32_t, uint_least32_t, uint_fast8_t,
+ uint_fast16_t, uint_fast32_t;
+typedef int intptr_t, int32_t, int_least32_t, int_fast8_t, int_fast16_t,
+ int_fast32_t;
+typedef unsigned long long uint64_t, uint_least64_t, uint_fast64_t, uintmax_t;
+typedef long long int64_t, int_least64_t, int_fast64_t, intmax_t;
+
+#endif
diff --git a/src/libc/include/stdio.h b/src/libc/include/stdio.h
index 1d0e27c..7c6504a 100644
--- a/src/libc/include/stdio.h
+++ b/src/libc/include/stdio.h
@@ -1,5 +1,5 @@
/*
- * wanix, a Unix-like operating system for WebAssembly
+ * wanix, a Unix-like operating system for WebAssembly applications.
* Copyright (C) 2025 Xavier Del Campo Romero
*
* This program is free software: you can redistribute it and/or modify
@@ -19,17 +19,14 @@
#ifndef _STDIO_H
#define _STDIO_H
-enum
-{
- EOF = -1
-};
-
+enum {EOF = -1};
typedef struct __file FILE;
-FILE *fopen(const char *__path, const char *__mode);
-int printf(const char *__fmt, ...);
-int fprintf(FILE *__stream, const char *__fmt, ...);
+int puts(const char *__s);
+int putchar(int __c);
extern FILE *stdin, *stdout, *stderr;
+#include <printf.h>
+
#endif
diff --git a/src/libc/include/stdlib.h b/src/libc/include/stdlib.h
index 4065f1c..0d2fee7 100644
--- a/src/libc/include/stdlib.h
+++ b/src/libc/include/stdlib.h
@@ -1,5 +1,5 @@
/*
- * wanix, a Unix-like operating system for WebAssembly
+ * wanix, a Unix-like operating system for WebAssembly applications.
* Copyright (C) 2025 Xavier Del Campo Romero
*
* This program is free software: you can redistribute it and/or modify
@@ -24,8 +24,12 @@
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
+#define abort() __abort(__FILE__, __LINE__)
+
void *malloc(size_t __n);
void *calloc(size_t __nemb, size_t __size);
+void *realloc(void *__ptr, size_t __size);
void free(void *__p);
+void __abort(const char *__file, int __lineno);
#endif
diff --git a/src/libc/include/string.h b/src/libc/include/string.h
index 20c9cf3..0a7b7f2 100644
--- a/src/libc/include/string.h
+++ b/src/libc/include/string.h
@@ -1,3 +1,21 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef _STRING_H
#define _STRING_H
@@ -7,7 +25,12 @@ int memcmp(const void *__s1, const void *__s2, size_t __n);
void *memcpy(void *__dst, const void *__src, size_t __n);
void *memset(void *__dst, int __c, size_t __n);
char *strchr(const char *__s, int __n);
+int strcmp(const char *__a, const char *__b);
+char *strdup(const char *__s);
+int strncmp(const char *__a, const char *__b, size_t __n);
+char *strndup(const char *__s, size_t __n);
char *strerror(int errnum);
size_t strlen(const char *__s);
+char *strrchr(const char *__s, int __c);
#endif
diff --git a/src/libc/include/sys/stat.h b/src/libc/include/sys/stat.h
new file mode 100644
index 0000000..0a5dd23
--- /dev/null
+++ b/src/libc/include/sys/stat.h
@@ -0,0 +1,40 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYS_STAT_H
+#define _SYS_STAT_H
+
+#include <sys/types.h>
+#include <time.h>
+
+struct stat
+{
+ dev_t st_dev;
+ ino_t st_ino;
+ mode_t st_mode;
+ nlink_t st_nlink;
+ uid_t st_uid;
+ gid_t st_gid;
+ dev_t st_rdev;
+ off_t st_size;
+ struct timespec st_atim, st_mtim, st_ctim;
+ blksize_t st_blksize;
+ blkcnt_t st_blocks;
+};
+
+#endif
diff --git a/src/libc/include/sys/types.h b/src/libc/include/sys/types.h
new file mode 100644
index 0000000..3175740
--- /dev/null
+++ b/src/libc/include/sys/types.h
@@ -0,0 +1,25 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+typedef unsigned dev_t, mode_t, nlink_t, uid_t, gid_t, blksize_t, blkcnt_t;
+typedef unsigned long ino_t, off_t;
+
+#endif
diff --git a/src/libc/include/time.h b/src/libc/include/time.h
new file mode 100644
index 0000000..99a8e6c
--- /dev/null
+++ b/src/libc/include/time.h
@@ -0,0 +1,39 @@
+/*
+ * wanix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TIME_H
+#define _TIME_H
+
+typedef enum
+{
+ CLOCK_REALTIME
+} clockid_t;
+
+typedef long long time_t;
+
+struct timespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+};
+
+int clock_getres(clockid_t __id, struct timespec *__ts);
+int clock_gettime(clockid_t __id, struct timespec *__ts);
+int clock_settime(clockid_t __id, const struct timespec *__ts);
+
+#endif