1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/PUTCHAR.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,111 @@
1.4 +/* PUTCHAR.C
1.5 + *
1.6 + * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
1.7 + * All rights reserved.
1.8 + */
1.9 +
1.10 +/*
1.11 + * Copyright (c) 1990 The Regents of the University of California.
1.12 + * All rights reserved.
1.13 + *
1.14 + * Redistribution and use in source and binary forms are permitted
1.15 + * provided that the above copyright notice and this paragraph are
1.16 + * duplicated in all such forms and that any documentation,
1.17 + * advertising materials, and other materials related to such
1.18 + * distribution and use acknowledge that the software was developed
1.19 + * by the University of California, Berkeley. The name of the
1.20 + * University may not be used to endorse or promote products derived
1.21 + * from this software without specific prior written permission.
1.22 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1.23 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1.24 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1.25 + */
1.26 +
1.27 +/*
1.28 +FUNCTION
1.29 +<<putchar>>---write a character (macro)
1.30 +
1.31 +INDEX
1.32 + putchar
1.33 +INDEX
1.34 + _putchar_r
1.35 +
1.36 +ANSI_SYNOPSIS
1.37 + #include <stdio.h>
1.38 + int putchar(int <[ch]>);
1.39 +
1.40 + int _putchar_r(void *<[reent]>, int <[ch]>);
1.41 +
1.42 +TRAD_SYNOPSIS
1.43 + #include <stdio.h>
1.44 + int putchar(<[ch]>)
1.45 + int <[ch]>;
1.46 +
1.47 + int _putchar_r(<[reent]>, <[ch]>)
1.48 + char *<[reent]>;
1.49 + int <[ch]>;
1.50 +
1.51 +DESCRIPTION
1.52 +<<putchar>> is a macro, defined in <<stdio.h>>. <<putchar>>
1.53 +writes its argument to the standard output stream,
1.54 +after converting it from an <<int>> to an <<unsigned char>>.
1.55 +
1.56 +The alternate function <<_putchar_r>> is a reentrant version. The
1.57 +extra argument <[reent]> is a pointer to a reentrancy structure.
1.58 +
1.59 +RETURNS
1.60 +If successful, <<putchar>> returns its argument <[ch]>. If an error
1.61 +intervenes, the result is <<EOF>>. You can use `<<ferror(stdin)>>' to
1.62 +query for errors.
1.63 +
1.64 +PORTABILITY
1.65 +ANSI C requires <<putchar>>; it suggests, but does not require, that
1.66 +<<putchar>> be implemented as a macro.
1.67 +
1.68 +Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
1.69 +<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
1.70 +*/
1.71 +
1.72 +/*
1.73 + * A subroutine version of the macro putchar
1.74 + */
1.75 +
1.76 +#include <stdio_r.h>
1.77 +#include "LOCAL.H"
1.78 +
1.79 +#undef putchar
1.80 +
1.81 +/**
1.82 +A reentrant version of putchar().
1.83 +*/
1.84 +EXPORT_C int
1.85 +_putchar_r (struct _reent *ptr,int c)
1.86 +{
1.87 + return __sputc ((unsigned char)c, _stdout_r (ptr));
1.88 +}
1.89 +
1.90 +#ifndef _REENT_ONLY
1.91 +
1.92 +#undef putchar
1.93 +/**
1.94 +Write character to standard output.
1.95 +Writes character to the current position in the standard output
1.96 +and increases the file pointer to point to next character.
1.97 +This routine cooresponds to: putc(character,stdout).
1.98 +
1.99 +@param c Character to be written.
1.100 +
1.101 +@return On Success, returns the written character.
1.102 + On Failure, EOF is returned and errno may be set.
1.103 +*/
1.104 +EXPORT_C int
1.105 +putchar (int c)
1.106 +{
1.107 + /* CHECK_INIT is (eventually) called by __swbuf. */
1.108 + struct _reent *r = _REENT2;
1.109 + if (!r)
1.110 + return EOF; // Memory for library globals is not allocated (errno not set).
1.111 + return(_putchar_r (r, c));
1.112 +}
1.113 +
1.114 +#endif