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