Luna/apps/app.c
apio 8c72e9a49a
All checks were successful
continuous-integration/drone/push Build is passing
kernel: Add an exec() system call
Doesn't support arguments or environment for now.
2023-03-16 22:44:58 +01:00

40 lines
695 B
C

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
void bye()
{
printf("byeee!\n");
}
int main()
{
atexit(bye);
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
FILE* f = fopen("/etc/motd", "r");
if (!f)
{
perror("fopen");
return 1;
}
char buffer[512];
size_t nread = fread(buffer, 1, sizeof(buffer), f);
buffer[nread] = 0;
printf("/etc/motd says: %s", buffer);
fclose(f);
time_t now = time(NULL);
printf("date: %s", ctime(&now));
// FIXME: Add libc wrapper.
syscall(SYS_exec, "/bin/hello");
}