35 lines
575 B
C
35 lines
575 B
C
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.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());
|
|
|
|
int fd = open("/etc/motd", 0);
|
|
if (fd < 0)
|
|
{
|
|
perror("open");
|
|
return 1;
|
|
}
|
|
|
|
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));
|
|
}
|