Luna/apps/app.c

36 lines
600 B
C
Raw Normal View History

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
2023-03-12 14:32:09 +00:00
#include <sys/stat.h>
2023-01-06 23:21:08 +00:00
#include <time.h>
#include <unistd.h>
void bye()
{
2023-01-07 00:49:26 +00:00
printf("byeee!\n");
}
int main()
{
atexit(bye);
2023-03-11 21:19:58 +00:00
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
FILE* f = fopen("/etc/motd", "r");
if (!f)
{
perror("fopen");
return 1;
}
2023-03-11 17:02:50 +00:00
char buffer[512];
size_t nread = fread(buffer, 1, sizeof(buffer), f);
2023-03-11 17:02:50 +00:00
buffer[nread] = 0;
printf("/etc/motd says: %s", buffer);
2023-03-11 17:02:50 +00:00
fclose(f);
time_t now = time(NULL);
printf("date: %s", ctime(&now));
}