app: Use C FILE instead of POSIX fd, and switch back to /etc/motd
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-12 17:36:56 +01:00
parent 9e9f268562
commit 3cc2e4b2a4
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -15,23 +15,20 @@ int main()
atexit(bye); atexit(bye);
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid()); printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
mkdir("/home", 0755); FILE* f = fopen("/etc/motd", "r");
mkdir("/home/user", 0755); if (!f)
int fd = open("/home/user/notes.txt", O_RDWR | O_CREAT, 0644);
if (fd < 0)
{ {
perror("open"); perror("fopen");
return 1; return 1;
} }
char buffer[512]; char buffer[512];
ssize_t nread = read(fd, buffer, sizeof(buffer)); size_t nread = fread(buffer, 1, sizeof(buffer), f);
buffer[nread] = 0; buffer[nread] = 0;
printf("/home/user/notes.txt says: %s", buffer); printf("/etc/motd says: %s", buffer);
close(fd); fclose(f);
time_t now = time(NULL); time_t now = time(NULL);
printf("date: %s", ctime(&now)); printf("date: %s", ctime(&now));