os/ossrv/genericopenlibs/cstdlib/LSTDIO/PUTCHAR.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* PUTCHAR.C
     2  * 
     3  * Portions Copyright (c) 1990-2006 Nokia Corporation and/or its subsidiary(-ies).
     4  * All rights reserved.
     5  */
     6 
     7 /*
     8  * Copyright (c) 1990 The Regents of the University of California.
     9  * All rights reserved.
    10  *
    11  * Redistribution and use in source and binary forms are permitted
    12  * provided that the above copyright notice and this paragraph are
    13  * duplicated in all such forms and that any documentation,
    14  * advertising materials, and other materials related to such
    15  * distribution and use acknowledge that the software was developed
    16  * by the University of California, Berkeley.  The name of the
    17  * University may not be used to endorse or promote products derived
    18  * from this software without specific prior written permission.
    19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
    20  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
    21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    22  */
    23 
    24 /*
    25 FUNCTION
    26 <<putchar>>---write a character (macro)
    27 
    28 INDEX
    29 	putchar
    30 INDEX
    31 	_putchar_r
    32 
    33 ANSI_SYNOPSIS
    34 	#include <stdio.h>
    35 	int putchar(int <[ch]>);
    36 
    37 	int _putchar_r(void *<[reent]>, int <[ch]>);
    38 
    39 TRAD_SYNOPSIS
    40 	#include <stdio.h>
    41 	int putchar(<[ch]>)
    42 	int <[ch]>;
    43 
    44 	int _putchar_r(<[reent]>, <[ch]>)
    45 	char *<[reent]>;
    46 	int <[ch]>;
    47 
    48 DESCRIPTION
    49 <<putchar>> is a macro, defined in <<stdio.h>>.  <<putchar>>
    50 writes its argument to the standard output stream,
    51 after converting it from an <<int>> to an <<unsigned char>>.
    52 
    53 The alternate function <<_putchar_r>> is a reentrant version.  The
    54 extra argument <[reent]> is a pointer to a reentrancy structure.
    55 
    56 RETURNS
    57 If successful, <<putchar>> returns its argument <[ch]>.  If an error
    58 intervenes, the result is <<EOF>>.  You can use `<<ferror(stdin)>>' to
    59 query for errors.
    60 
    61 PORTABILITY
    62 ANSI C requires <<putchar>>; it suggests, but does not require, that
    63 <<putchar>> be implemented as a macro.
    64 
    65 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
    66 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
    67 */
    68 
    69 /*
    70  * A subroutine version of the macro putchar
    71  */
    72 
    73 #include <stdio_r.h>
    74 #include "LOCAL.H"
    75 
    76 #undef putchar
    77 
    78 /**
    79 A reentrant version of putchar().
    80 */
    81 EXPORT_C int
    82 _putchar_r (struct _reent *ptr,int c)
    83 {
    84   return __sputc ((unsigned char)c, _stdout_r (ptr));
    85 }
    86 
    87 #ifndef _REENT_ONLY
    88 
    89 #undef putchar
    90 /**
    91 Write character to standard output.
    92 Writes character to the current position in the standard output
    93 and increases the file pointer to point to next character.
    94 This routine cooresponds to: putc(character,stdout).
    95 
    96 @param c Character to be written. 
    97 
    98 @return On Success, returns the written character.
    99 		On Failure, EOF is returned and errno may be set.
   100 */
   101 EXPORT_C int
   102 putchar (int c)
   103 {
   104   /* CHECK_INIT is (eventually) called by __swbuf.  */
   105   struct _reent *r = _REENT2;
   106   if (!r)
   107 	return EOF; // Memory for library globals is not allocated (errno not set).
   108   return(_putchar_r (r, c));
   109 }
   110 
   111 #endif