2023-03-11 16:45:20 +00:00
|
|
|
#include <fcntl.h>
|
2023-01-06 12:31:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-01-06 23:21:08 +00:00
|
|
|
#include <time.h>
|
2023-03-11 16:45:20 +00:00
|
|
|
#include <unistd.h>
|
2023-01-06 12:31:14 +00:00
|
|
|
|
2023-01-06 18:40:25 +00:00
|
|
|
void bye()
|
|
|
|
{
|
2023-01-07 00:49:26 +00:00
|
|
|
printf("byeee!\n");
|
2023-01-06 18:40:25 +00:00
|
|
|
}
|
|
|
|
|
2023-01-06 12:31:14 +00:00
|
|
|
int main()
|
|
|
|
{
|
2023-01-06 18:40:25 +00:00
|
|
|
atexit(bye);
|
2023-02-27 15:23:51 +00:00
|
|
|
printf("Welcome to %s from userspace!\n", "Luna");
|
2023-01-06 19:15:43 +00:00
|
|
|
|
2023-03-11 16:45:20 +00:00
|
|
|
int fd = open("/etc/motd", 0);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
}
|
2023-01-11 22:01:47 +00:00
|
|
|
|
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);
|
|
|
|
|
2023-03-11 16:45:20 +00:00
|
|
|
close(fd);
|
2023-01-13 20:06:27 +00:00
|
|
|
|
|
|
|
time_t now = time(NULL);
|
|
|
|
printf("date: %s", ctime(&now));
|
2023-01-06 12:31:14 +00:00
|
|
|
}
|