Thanks, Richard, I've bookmarked that link. Not only does it have the
current version of putchar, it has the whole history of it, including
rationalizations for the changes. It starts out, 14 years ago, looking
like standard C to me:
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#undef putchar
/*
* A subroutine version of the macro putchar
*/
putchar(c)
int c;
{
register FILE *so = stdout;
return (__sputc(c, so));
}
#if defined(LIBC_SCCS) && !defined(lint)
#if 0
static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* LIBC_SCCS and not lint */
Somewhere along the line, clc's Chris Torek became the "guy who writes
putchar for openbsd," and it adds on a couple non-standard headers that
apparently deal with threading:
#include <stdio.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
#include "pthread_private.h"
#endif
#undef putchar
/*
* A subroutine version of the macro putchar
*/
int
putchar(c)
int c;
{
int retval;
register FILE *so = stdout;
#ifdef _THREAD_SAFE
_thread_flockfile(so,__FILE__,__LINE__);
#endif
retval = __sputc(c, so);
#ifdef _THREAD_SAFE
_thread_funlockfile(so);
#endif
return (retval);
}
The current version isn't shy about the non-standard headers:
#include "namespace.h"
#include <stdio.h>
#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
, but does the same thing: it undefines putchar and worries about something
being f locked. I was mildly surprised not to see a test against EOF.
I don't understand much of unix programming, but I find that the time I
spend on it bears dividends down the road. What a quirky thing to have a
header called un-namespace.h.