Luna/apps/app.c
apio 8fa72f3cf0
All checks were successful
continuous-integration/drone/push Build is passing
kernel+libc: Implement read()
2023-03-11 18:02:50 +01:00

35 lines
556 B
C

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
void bye()
{
printf("byeee!\n");
}
int main()
{
atexit(bye);
printf("Welcome to %s from userspace!\n", "Luna");
int fd = open("/etc/motd", 0);
if (fd < 0)
{
perror("open");
return 1;
}
char buffer[512];
ssize_t nread = read(fd, buffer, sizeof(buffer));
buffer[nread] = 0;
printf("/etc/motd says: %s", buffer);
close(fd);
time_t now = time(NULL);
printf("date: %s", ctime(&now));
}