mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-08-27 22:14:59 +00:00
refactor(userspace): build using cmake
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
@@ -15,10 +15,15 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef EOK
|
||||
#define EOK 0
|
||||
#endif
|
||||
|
||||
__iptr __check_errno(__iptr status, __iptr err)
|
||||
{
|
||||
if ((int)status >= EOK)
|
||||
@@ -37,9 +42,6 @@ export char *strerror(int errnum)
|
||||
if (errnum < 0)
|
||||
errnum = -errnum;
|
||||
|
||||
if (errnum > __ERRNO_MAX)
|
||||
return (char *)"Not a valid error number";
|
||||
|
||||
switch (errnum)
|
||||
{
|
||||
case EOK:
|
||||
|
@@ -15,8 +15,8 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -37,7 +37,7 @@ export int open(const char *path, int oflag, ...)
|
||||
mode = va_arg(args, mode_t);
|
||||
va_end(args);
|
||||
}
|
||||
return __check_errno(call_open(path, oflag, mode), -1);
|
||||
return __check_errno(sysdep(Open)(path, oflag, mode), -1);
|
||||
}
|
||||
|
||||
export int openat(int fd, const char *path, int oflag, ...);
|
||||
|
@@ -15,6 +15,7 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <sys/types.h>
|
||||
#include <fenv.h>
|
||||
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <float.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <bits/libc.h>
|
||||
#include <fenv.h>
|
||||
|
||||
export int signgam;
|
||||
|
@@ -15,6 +15,7 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@@ -15,13 +15,14 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
export int kill(pid_t pid, int sig)
|
||||
{
|
||||
return call_kill(pid, sig);
|
||||
return sysdep(Kill)(pid, sig);
|
||||
}
|
||||
|
||||
export int killpg(pid_t, int);
|
||||
|
@@ -19,7 +19,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <fcntl.h>
|
||||
#include "../print/printf.h"
|
||||
|
||||
struct _IO_FILE *_i_open_files[256];
|
||||
@@ -74,7 +75,7 @@ export int fclose(FILE *stream)
|
||||
if (stream->buffer)
|
||||
free(stream->buffer);
|
||||
|
||||
call_close(stream->fd);
|
||||
sysdep(Close)(stream->fd);
|
||||
_i_open_files[stream->fd] = NULL;
|
||||
free(stream);
|
||||
return 0;
|
||||
@@ -105,7 +106,7 @@ export int fflush(FILE *stream)
|
||||
{
|
||||
if (stream->buffer_pos > 0)
|
||||
{
|
||||
ssize_t written = call_write(stream->fd, stream->buffer, stream->buffer_pos);
|
||||
ssize_t written = sysdep(Write)(stream->fd, stream->buffer, stream->buffer_pos);
|
||||
if (written < 0)
|
||||
{
|
||||
stream->error = 1;
|
||||
@@ -129,7 +130,7 @@ export int fgetc(FILE *stream)
|
||||
|
||||
if (stream->buffer_pos >= stream->buffer_size)
|
||||
{
|
||||
int res = call_read(stream->fd, stream->buffer, 4096);
|
||||
int res = sysdep(Read)(stream->fd, stream->buffer, 4096);
|
||||
if (res <= 0)
|
||||
{
|
||||
if (res == 0)
|
||||
@@ -180,33 +181,33 @@ export FILE *fopen(const char *restrict pathname, const char *restrict mode)
|
||||
mode_t perm = 0;
|
||||
|
||||
if (strcmp(mode, "r") == 0)
|
||||
flags = __SYS_O_RDONLY;
|
||||
flags = O_RDONLY;
|
||||
else if (strcmp(mode, "r+") == 0)
|
||||
flags = __SYS_O_RDWR;
|
||||
flags = O_RDWR;
|
||||
else if (strcmp(mode, "w") == 0)
|
||||
{
|
||||
flags = __SYS_O_WRONLY | __SYS_O_CREAT | __SYS_O_TRUNC;
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
perm = 0644;
|
||||
}
|
||||
else if (strcmp(mode, "w+") == 0)
|
||||
{
|
||||
flags = __SYS_O_RDWR | __SYS_O_CREAT | __SYS_O_TRUNC;
|
||||
flags = O_RDWR | O_CREAT | O_TRUNC;
|
||||
perm = 0644;
|
||||
}
|
||||
else if (strcmp(mode, "a") == 0)
|
||||
{
|
||||
flags = __SYS_O_WRONLY | __SYS_O_CREAT | __SYS_O_APPEND;
|
||||
flags = O_WRONLY | O_CREAT | O_APPEND;
|
||||
perm = 0644;
|
||||
}
|
||||
else if (strcmp(mode, "a+") == 0)
|
||||
{
|
||||
flags = __SYS_O_RDWR | __SYS_O_CREAT | __SYS_O_APPEND;
|
||||
flags = O_RDWR | O_CREAT | O_APPEND;
|
||||
perm = 0644;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
||||
int fd = call_open(pathname, flags, perm);
|
||||
int fd = sysdep(Open)(pathname, flags, perm);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -274,7 +275,7 @@ export size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restri
|
||||
{
|
||||
if (stream->buffer_pos >= stream->buffer_size)
|
||||
{
|
||||
int res = call_read(stream->fd, stream->buffer, stream->buffer_size);
|
||||
int res = sysdep(Read)(stream->fd, stream->buffer, stream->buffer_size);
|
||||
if (res <= 0)
|
||||
{
|
||||
if (res == 0)
|
||||
@@ -305,7 +306,7 @@ export int fscanf(FILE *restrict, const char *restrict, ...);
|
||||
|
||||
export int fseek(FILE *stream, long offset, int whence)
|
||||
{
|
||||
int res = call_seek(stream->fd, offset, whence);
|
||||
int res = sysdep(Seek)(stream->fd, offset, whence);
|
||||
if (res < 0)
|
||||
{
|
||||
stream->error = 1;
|
||||
@@ -321,7 +322,7 @@ export int fsetpos(FILE *, const fpos_t *);
|
||||
|
||||
export long ftell(FILE *stream)
|
||||
{
|
||||
return call_tell(stream->fd);
|
||||
return sysdep(Tell)(stream->fd);
|
||||
}
|
||||
|
||||
export off_t ftello(FILE *);
|
||||
@@ -347,7 +348,7 @@ export size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE
|
||||
|
||||
if (stream->buffer_pos == stream->buffer_size)
|
||||
{
|
||||
if (call_write(stream->fd, stream->buffer, stream->buffer_size) != stream->buffer_size)
|
||||
if (sysdep(Write)(stream->fd, stream->buffer, stream->buffer_size) != stream->buffer_size)
|
||||
{
|
||||
stream->error = 1;
|
||||
break;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
@@ -27,6 +27,6 @@ export int ioctl(int fd, unsigned long op, ...)
|
||||
va_start(args, op);
|
||||
arg = va_arg(args, void *);
|
||||
va_end(args);
|
||||
int ret = call_ioctl(fd, op, arg);
|
||||
int ret = sysdep(IOControl)(fd, op, arg);
|
||||
return __check_errno(ret, -1);
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <errno.h>
|
||||
|
||||
export int mlock(const void *, size_t);
|
||||
@@ -24,12 +24,12 @@ export int mlockall(int);
|
||||
|
||||
export void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
|
||||
{
|
||||
return (void *)__check_errno((__iptr)call_mmap(addr, len, prot, flags, fildes, off), (__iptr)MAP_FAILED);
|
||||
return (void *)__check_errno((__iptr)sysdep(MemoryMap)(addr, len, prot, flags, fildes, off), (__iptr)MAP_FAILED);
|
||||
}
|
||||
|
||||
export int mprotect(void *addr, size_t len, int prot)
|
||||
{
|
||||
return __check_errno(call_mprotect(addr, len, prot), -1);
|
||||
return __check_errno(sysdep(MemoryProtect)(addr, len, prot), -1);
|
||||
}
|
||||
|
||||
export int msync(void *, size_t, int);
|
||||
@@ -38,7 +38,7 @@ export int munlockall(void);
|
||||
|
||||
export int munmap(void *addr, size_t len)
|
||||
{
|
||||
return __check_errno(call_munmap(addr, len), -1);
|
||||
return __check_errno(sysdep(MemoryUnmap)(addr, len), -1);
|
||||
}
|
||||
|
||||
export int posix_madvise(void *, size_t, int);
|
||||
|
@@ -17,23 +17,23 @@
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
|
||||
export int accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len)
|
||||
{
|
||||
return __check_errno(call_accept(socket, address, address_len), -1);
|
||||
return __check_errno(sysdep(Accept)(socket, address, address_len), -1);
|
||||
}
|
||||
|
||||
export int accept4(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len, int flag);
|
||||
|
||||
export int bind(int socket, const struct sockaddr *address, socklen_t address_len)
|
||||
{
|
||||
return __check_errno(call_bind(socket, address, address_len), -1);
|
||||
return __check_errno(sysdep(Bind)(socket, address, address_len), -1);
|
||||
}
|
||||
|
||||
export int connect(int socket, const struct sockaddr *address, socklen_t address_len)
|
||||
{
|
||||
return __check_errno(call_connect(socket, address, address_len), -1);
|
||||
return __check_errno(sysdep(Connect)(socket, address, address_len), -1);
|
||||
}
|
||||
|
||||
export int getpeername(int, struct sockaddr *restrict, socklen_t *restrict);
|
||||
@@ -42,7 +42,7 @@ export int getsockopt(int, int, int, void *restrict, socklen_t *restrict);
|
||||
|
||||
export int listen(int socket, int backlog)
|
||||
{
|
||||
return __check_errno(call_listen(socket, backlog), -1);
|
||||
return __check_errno(sysdep(Listen)(socket, backlog), -1);
|
||||
}
|
||||
|
||||
export ssize_t recv(int, void *, size_t, int);
|
||||
@@ -57,7 +57,7 @@ export int sockatmark(int);
|
||||
|
||||
export int socket(int domain, int type, int protocol)
|
||||
{
|
||||
return __check_errno(call_socket(domain, type, protocol), -1);
|
||||
return __check_errno(sysdep(Socket)(domain, type, protocol), -1);
|
||||
}
|
||||
|
||||
export int socketpair(int, int, int, int[2]);
|
||||
|
@@ -15,6 +15,7 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@@ -31,7 +32,7 @@ export int fstat(int fildes, struct stat *buf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __check_errno(call_fstat(fildes, buf), -1);
|
||||
return __check_errno(sysdep(FStat)(fildes, buf), -1);
|
||||
}
|
||||
|
||||
export int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag)
|
||||
@@ -58,12 +59,12 @@ export int lstat(const char *restrict path, struct stat *restrict buf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __check_errno(call_lstat(path, buf), -1);
|
||||
return __check_errno(sysdep(LStat)(path, buf), -1);
|
||||
}
|
||||
|
||||
export int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
return __check_errno(call_mkdir(path, mode), -1);
|
||||
return __check_errno(sysdep(MakeDirectory)(path, mode), -1);
|
||||
}
|
||||
|
||||
export int mkdirat(int fd, const char *path, mode_t mode)
|
||||
@@ -85,7 +86,7 @@ export int stat(const char *restrict path, struct stat *restrict buf)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return __check_errno(call_stat(path, buf), -1);
|
||||
return __check_errno(sysdep(Stat)(path, buf), -1);
|
||||
}
|
||||
|
||||
export mode_t umask(mode_t);
|
||||
|
@@ -21,7 +21,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
|
||||
export int uname(struct utsname *name)
|
||||
{
|
||||
@@ -31,16 +31,8 @@ export int uname(struct utsname *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct kutsname kname;
|
||||
int result = call_uname(&kname);
|
||||
if (result == 0)
|
||||
{
|
||||
strcpy(name->sysname, kname.sysname);
|
||||
strcpy(name->release, kname.release);
|
||||
strcpy(name->version, kname.version);
|
||||
strcpy(name->machine, kname.machine);
|
||||
}
|
||||
else
|
||||
int result = sysdep(UnixName)(name);
|
||||
if (result != 0)
|
||||
{
|
||||
errno = result;
|
||||
return -1;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -34,5 +34,5 @@ export int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
|
||||
|
||||
export pid_t waitpid(pid_t pid, int *stat_loc, int options)
|
||||
{
|
||||
return __check_errno(call_waitpid(pid, stat_loc, options), -1);
|
||||
return __check_errno(sysdep(WaitProcessID)(pid, stat_loc, options), -1);
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <bits/libc.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
|
@@ -22,7 +22,7 @@
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fennix/syscalls.h>
|
||||
#include <bits/libc.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
export char *optarg;
|
||||
@@ -44,7 +44,7 @@ export int chown(const char *, uid_t, gid_t);
|
||||
|
||||
export int close(int fildes)
|
||||
{
|
||||
return __check_errno(call_close(fildes), -1);
|
||||
return __check_errno(sysdep(Close)(fildes), -1);
|
||||
}
|
||||
|
||||
export size_t confstr(int, char *, size_t);
|
||||
@@ -130,7 +130,7 @@ export int execv(const char *path, char *const argv[])
|
||||
|
||||
export int execve(const char *path, char *const argv[], char *const envp[])
|
||||
{
|
||||
return __check_errno(call_execve(path, argv, envp), -1);
|
||||
return __check_errno(sysdep(Execve)(path, argv, envp), -1);
|
||||
}
|
||||
|
||||
export int execvp(const char *file, char *const argv[])
|
||||
@@ -167,7 +167,7 @@ export int fdatasync(int);
|
||||
|
||||
export pid_t fork(void)
|
||||
{
|
||||
return __check_errno(call_fork(), -1);
|
||||
return __check_errno(sysdep(Fork)(), -1);
|
||||
}
|
||||
|
||||
export long int fpathconf(int, int);
|
||||
@@ -225,12 +225,12 @@ export pid_t getpgrp(void);
|
||||
|
||||
export pid_t getpid(void)
|
||||
{
|
||||
return call_getpid();
|
||||
return sysdep(GetProcessID)();
|
||||
}
|
||||
|
||||
export pid_t getppid(void)
|
||||
{
|
||||
return call_getppid();
|
||||
return sysdep(GetParentProcessID)();
|
||||
}
|
||||
|
||||
export pid_t getsid(pid_t);
|
||||
@@ -261,19 +261,19 @@ export int pipe(int[2]);
|
||||
|
||||
export ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return __check_errno(call_pread(fildes, buf, nbyte, offset), -1);
|
||||
return __check_errno(sysdep(PRead)(fildes, buf, nbyte, offset), -1);
|
||||
}
|
||||
|
||||
export int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
|
||||
|
||||
export ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
|
||||
{
|
||||
return __check_errno(call_pwrite(fildes, buf, nbyte, offset), -1);
|
||||
return __check_errno(sysdep(PWrite)(fildes, buf, nbyte, offset), -1);
|
||||
}
|
||||
|
||||
export ssize_t read(int fildes, void *buf, size_t nbyte)
|
||||
{
|
||||
return __check_errno(call_read(fildes, buf, nbyte), -1);
|
||||
return __check_errno(sysdep(Read)(fildes, buf, nbyte), -1);
|
||||
}
|
||||
|
||||
export int readlink(const char *, char *, size_t);
|
||||
@@ -324,5 +324,5 @@ export pid_t vfork(void);
|
||||
|
||||
export ssize_t write(int fildes, const void *buf, size_t nbyte)
|
||||
{
|
||||
return __check_errno(call_write(fildes, buf, nbyte), -1);
|
||||
return __check_errno(sysdep(Write)(fildes, buf, nbyte), -1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user