3 ms·
I was shocked (and impressed) when I looked at some of djb's code and saw that he put his "the return value of every syscall must be checked" view into practice
by schoen 12y ago
I was shocked (and impressed) when I looked at some of djb's code and saw that he put his "the return value of every syscall must be checked" view into practice so consistently that every single printf() (not only fprintf()!) was inside an if block that checked whether it succeeded in writing to stdout or not.
Of course, printf() does have a return value ("Upon successful return, these functions return the number of characters printed"), and it can fail... but it takes a considerable consistency of purpose to decide to deal with that possibility explicitly every single time.
- riffraff 12y agoout of curiosity, what do you (does he) do if printf fails?
- svckr 12y agoFrom qmail/qmail-pw2u.c (linked somewhere above): void die_write() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: unable to write output\n"); _exit(111); } /* ... */ if (substdio_puts(subfdout,uugh) == -1) die_write(); if (substdio_puts(subfdout,dashcolon) == -1) die_write(); if (substdio_put(subfdout,x,i) == -1) die_write(); /* ... */
- mercurial 12y agoI think this says as much about djb's abilities as about C's limitations.