10 if ((rfd
= open("/newmotd", O_RDONLY
)) < 0)
11 panic("open /newmotd: %e", rfd
);
12 if ((wfd
= open("/motd", O_RDWR
)) < 0)
13 panic("open /motd: %e", wfd
);
14 cprintf("file descriptors %d %d\n", rfd
, wfd
);
16 panic("open /newmotd and /motd give same file descriptor");
18 cprintf("OLD MOTD\n===\n");
19 while ((n
= read(wfd
, buf
, sizeof buf
-1)) > 0)
24 if ((r
= ftruncate(wfd
, 0)) < 0)
25 panic("truncate /motd: %e", r
);
27 cprintf("NEW MOTD\n===\n");
28 while ((n
= read(rfd
, buf
, sizeof buf
-1)) > 0) {
30 if ((r
= write(wfd
, buf
, n
)) != n
)
31 panic("write /motd: %e", r
);
36 panic("read /newmotd: %e", n
);