Luna/apps/app.c
apio 3cc2e4b2a4
All checks were successful
continuous-integration/drone/push Build is passing
app: Use C FILE instead of POSIX fd, and switch back to /etc/motd
2023-03-12 17:36:56 +01:00

36 lines
600 B
C

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.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));
}