Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!ima!haddock!karl
From: karl@haddock.UUCP
Newsgroups: comp.lang.forth
Subject: Re: Unix system calls from Forth
Message-ID: <195@haddock.UUCP>
Date: Fri, 12-Dec-86 19:13:54 EST
Article-I.D.: haddock.195
Posted: Fri Dec 12 19:13:54 1986
Date-Received: Mon, 15-Dec-86 06:44:30 EST
References: <12234@watnot.UUCP> <182@haddock.UUCP> <12261@watnot.UUCP>
Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer)
Distribution: net
Organization: Interactive Systems, Boston
Lines: 34

In article <12261@watnot.UUCP> ccplumb@watnot.UUCP (Colin Plumb) writes:
>I'd like to ask people with more Unix experience than my 4 months
>whether it's desirable to put the error in "errno", or leave it on the
>stack.  My perception is that, while in most cases you simply bomb out
>(via some sort of ABORT word), which clears the stack, and thus never
>use the error number, if you try to handle it more gracefully, you
>almost always use the error number in some sort of case statement.
>(That is, you use it right away, and just in this one place.)  So why
>stash it away somewhere?

Okay.  First, if you're going to abort, it doesn't matter whether or not the
errno is on the stack; so we can assume a more graceful error handler.  It's
been my experience in C that most such calls do *not* look at errno.  In fact,
the usual situation that if the system call fails, the function will return an
error condition to its caller.  (E.g. if fopen() fails to open(), it returns
NULL.)  If the system calls return the pair (FAILURE,errno), then any utility
routines that use them will likewise have to leave errno on the stack.  This
can get a bit messy if you have other stack cleanup to do before returning.
That's why I think stashing it is better.  (Also, it means one less arg to the
perror() routine, which again means less stack rearrangement.)

>I was thinking of using a leading "_" for the system call naming
>convention, since that's the convention used by the innards C library,

If you mean the mapping "printf" -> "_printf", that's a convention used by
some C *compilers*, and it applies to all external names.  The other use of
underscore (e.g. "exit" and "_exit") is what I was emulating with my notation
of "$" and "$_"; in fact I did use "$_exit" for the "real" system call vs.
"$exit" for the cleanup version (I was going to implement multiple cleanup
routines, too).  I don't think there's any reason to support the C library
syntax for functions like wait(), unless you expect to mechanically translate
code from C!

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint