39 lines
686 B
C
39 lines
686 B
C
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/stat.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());
|
|
|
|
mkdir("/home", 0);
|
|
mkdir("/home/user", 0);
|
|
|
|
int fd = open("/home/user/notes.txt", O_RDWR | O_CREAT);
|
|
if (fd < 0)
|
|
{
|
|
perror("open");
|
|
return 1;
|
|
}
|
|
|
|
char buffer[512];
|
|
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
|
buffer[nread] = 0;
|
|
|
|
printf("/home/user/notes.txt says: %s", buffer);
|
|
|
|
close(fd);
|
|
|
|
time_t now = time(NULL);
|
|
printf("date: %s", ctime(&now));
|
|
}
|