Skip to content

Commit d4d2bda

Browse files
committed
better error handling in the code example
1 parent cdd9faa commit d4d2bda

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

file-api.tex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,16 @@
745745

746746
\begin{verbatim}
747747
flags = fcntl(fd, F_GETFL);
748-
if (fcntl(fd, F_SETFL, flags | O_APPEND) == -1)
749-
...
748+
fcntl(fd, F_SETFL, flags | O_APPEND);
749+
\end{verbatim}
750+
751+
or better with proper error checks:
752+
753+
\begin{verbatim}
754+
if (((flags = fcntl(fd, F_GETFL)) == -1) ||
755+
(fcntl(fd, F_SETFL, flags | O_APPEND) == -1)) {
756+
err(...);
757+
}
750758
\end{verbatim}
751759

752760
\dots similarly when removing a flag.

0 commit comments

Comments
 (0)