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
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9e9f268562
commit
3cc2e4b2a4
15
apps/app.c
15
apps/app.c
@ -15,23 +15,20 @@ int main()
|
||||
atexit(bye);
|
||||
printf("Welcome to %s from userspace (pid %d)!\n", "Luna", getpid());
|
||||
|
||||
mkdir("/home", 0755);
|
||||
mkdir("/home/user", 0755);
|
||||
|
||||
int fd = open("/home/user/notes.txt", O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0)
|
||||
FILE* f = fopen("/etc/motd", "r");
|
||||
if (!f)
|
||||
{
|
||||
perror("open");
|
||||
perror("fopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char buffer[512];
|
||||
ssize_t nread = read(fd, buffer, sizeof(buffer));
|
||||
size_t nread = fread(buffer, 1, sizeof(buffer), f);
|
||||
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);
|
||||
printf("date: %s", ctime(&now));
|
||||
|
Loading…
Reference in New Issue
Block a user