Luna/apps/app.c

39 lines
686 B
C
Raw Normal View History

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
2023-03-12 14:32:09 +00:00
#include <sys/stat.h>
2023-01-06 23:21:08 +00:00
#include <time.h>
#include <unistd.h>
void bye()
{
2023-01-07 00:49:26 +00:00
printf("byeee!\n");
}
int main()
{
atexit(bye);
2023-03-11 21:19:58 +00:00
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
2023-03-12 14:32:09 +00:00
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;
}
2023-03-11 17:02:50 +00:00
char buffer[512];
ssize_t nread = read(fd, buffer, sizeof(buffer));
buffer[nread] = 0;
2023-03-12 14:32:09 +00:00
printf("/home/user/notes.txt says: %s", buffer);
2023-03-11 17:02:50 +00:00
close(fd);
time_t now = time(NULL);
printf("date: %s", ctime(&now));
}