karl@haddock.UUCP (12/03/87)
I wrote: > errno = 0; > unlink(fname); > if (errno != 0) abort(); and was informed that this is unportable usage because the POSIX spec doesn't guarantee that functions will preserve errno on success. Tell me then, o POSIX gurus, whether there are still functions that can return -1 on success (e.g. ptrace() and possibly nice())? If so, does POSIX specify what these functions are allowed to do with errno in such a case?
peter@sugar.UUCP (Peter da Silva) (12/07/87)
To throw a spanner into the works: On the Amiga, when a system call fails you call IoErr() to find out what went wrong. However, IoErr() takes no arguments. For a general error handling system, you would want to find out the last IoErr on a given stream. If you don't have a stream (say for malloc, or for fopen) you have to fall back to the existing setup. So: #include <ioerr.h> if(!(fp = fopen("illegal file name", "r"))) { switch(ioerr(0)) { ... } } if(!fread(...)) { switch(ioerr(fp)) { ... } } But stdio has enough problems (like... why don't read() and fread() have the same arguments?), so let's not & say we did. -- -- Peter da Silva `-_-' ...!hoptoad!academ!uhnix1!sugar!peter -- Disclaimer: These U aren't mere opinions... these are *values*.