Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!ames!amdcad!rpw3 From: rpw3@amdcad.AMD.COM (Rob Warnock) Newsgroups: comp.lang.c Subject: Re: Perror complication Message-ID: <18005@amdcad.AMD.COM> Date: Fri, 21-Aug-87 22:27:55 EDT Article-I.D.: amdcad.18005 Posted: Fri Aug 21 22:27:55 1987 Date-Received: Sun, 23-Aug-87 06:47:40 EDT References: <8913@brl-adm.ARPA> <8048@mimsy.UUCP> Reply-To: rpw3@amdcad.UUCP (Rob Warnock) Organization: [Consultant] San Mateo, CA Lines: 33 Sometimes when I get really frustrated by the fact that a successful system call does *not* clear errno, I use the following macro: #define ERRED(x) ((errno = 0), (x), errno != 0) So you can say things like: while (ERRED(pid = fork())) { /* handle fork() failure */ ...decide how many times to sleep + loop, or whether to exit() or longjmp() or what... } if (pid) { ...parent... } else { ...child... } This bypasses problems with syscalls that can return "-1" as a valid successful result, such as "nice()", and also avoids the "Not a typewriter" syndrome. The problem is I don't use it consistently (nor does anyone else) and therefore it can sometimes be a hindrance to maintenance rather than a help (the old "Bourne Shell ALGOL" problem). ;-} ;-} Rob Warnock Systems Architecture Consultant UUCP: {amdcad,fortune,sun,attmail}!redwood!rpw3 ATTmail: !rpw3 DDD: (415)572-2607 USPS: 627 26th Ave, San Mateo, CA 94403