apio
b54a7f3a80
All checks were successful
continuous-integration/drone/push Build is passing
O_RDONLY, O_WRONLY, O_RDWR, O_TRUNC, O_CREAT and O_EXCL are fully implemented. O_APPEND is partially implemented. Other flags are not here yet.
35 lines
582 B
C
35 lines
582 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", O_RDONLY);
|
|
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));
|
|
}
|