[TUHS] Happy birthday, Dennis Ritchie! [ really sun vs dec/apollo --> X and NeWS ]

Random832 random832 at fastmail.com
Wed Sep 20 04:09:06 AEST 2017

On Tue, Sep 19, 2017, at 08:24, Norman Wilson wrote:
> I guess the problem with perror is that it isn't sufficiently
> UNIX-like: it bundles three jobs that are really separate
> (convert errno to string message, format an error message,
> output the message) into one function, inseparably and
> inflexibly.

Yeah, but you have to do all of that (plus exit, if the error isn't
recoverable) after every single function that might fail.  If the
function didn't exist, you'd have to write your own, so you're not
really any worse off if it doesn't do quite what you want.

if(open one thing < 0) { perror...; exit...; }
if(open another thing < 0) { perror...; exit...; }
if(!malloc...) {perror... exit... }
etc, I'd be half tempted to write a function just for *that*.

BSD's err/warn family is a further refinement on this - it allows
format/arguments, as I complained about in another post, and lets you
specify what file to send output to, and the existence of err vs warn
lets you avoid having exit as a separate step.

More information about the TUHS mailing list