~/ learn/ comp-325/ cards/ System Programming I: The Kernel Boundary, Files, and Processes
1 of 62

The only acceptable shape for a system call

The only acceptable shape for a system call

Answer

int fd = open("data.txt", O_RDONLY); if (fd == -1) { perror("open"); return 1; }

Test for -1, name the call in the perror label so the message is findable, then decide. Skipping this is the single most common way a C program on UNIX fails silently.

S&K 3e ch18 §18.3–18.4, §18.7.4; system-call return convention and errno per POSIX.1-2024 §2.3

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e3e1afe9-7d76-4986-bf7e-cb2384665a70/flashcard utf-8 LF