~/ learn/ comp-325/ cards/ The five calls the whole file API is built from
1 of 10

Opening the two ends of a copy

Opening the two ends of a copy

Answer

int src = open(argv[1], O_RDONLY); int dst = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666); if (src == -1 || dst == -1) { perror("open"); return 1; }

The destination needs O_CREAT (so the third argument is mandatory) and O_TRUNC (so a shorter copy does not leave the old tail behind). The stored mode is 0666 & ~umask.

S&K 3e ch18 §18.8; signatures and return values per POSIX.1-2024 (open, read, write, close, lseek)

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/5a7833c8-fff8-4ef9-b42d-acbcad733ef6/flashcard utf-8 LF