Luna/apps/app.c

35 lines
556 B
C
Raw Normal View History

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.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);
printf("Welcome to %s from userspace!\n", "Luna");
int fd = open("/etc/motd", 0);
if (fd < 0)
{
perror("open");
return 1;
}
2023-03-11 17:02:50 +00:00
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));
}