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