source: trunk/libs/newlib/src/newlib/libc/stdio/getchar.c @ 567

Last change on this file since 567 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.5 KB
Line 
1/*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley.  The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16 */
17
18/*
19FUNCTION
20<<getchar>>---read a character (macro)
21
22INDEX
23        getchar
24INDEX
25        _getchar_r
26
27SYNOPSIS
28        #include <stdio.h>
29        int getchar(void);
30
31        int _getchar_r(struct _reent *<[reent]>);
32
33DESCRIPTION
34<<getchar>> is a macro, defined in <<stdio.h>>.  You can use <<getchar>>
35to get the next single character from the standard input stream.
36As a side effect, <<getchar>> advances the standard input's
37current position indicator.
38
39The alternate function <<_getchar_r>> is a reentrant version.  The
40extra argument <[reent]> is a pointer to a reentrancy structure.
41
42
43RETURNS
44The next character (read as an <<unsigned char>>, and cast to
45<<int>>), unless there is no more data, or the host system reports a
46read error; in either of these situations, <<getchar>> returns <<EOF>>.
47
48You can distinguish the two situations that cause an <<EOF>> result by
49using `<<ferror(stdin)>>' and `<<feof(stdin)>>'.
50
51PORTABILITY
52ANSI C requires <<getchar>>; it suggests, but does not require, that
53<<getchar>> be implemented as a macro.
54
55Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
56<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
57*/
58
59#if defined(LIBC_SCCS) && !defined(lint)
60static char sccsid[] = "%W% (Berkeley) %G%";
61#endif /* LIBC_SCCS and not lint */
62
63/*
64 * A subroutine version of the macro getchar.
65 */
66
67#include <_ansi.h>
68#include <reent.h>
69#include <stdio.h>
70#include "local.h"
71
72#undef getchar
73
74int
75_getchar_r (struct _reent *reent)
76{
77  _REENT_SMALL_CHECK_INIT (reent);
78  return _getc_r (reent, _stdin_r (reent));
79}
80
81#ifndef _REENT_ONLY
82
83int
84getchar (void)
85{
86  struct _reent *reent = _REENT;
87
88  /* CHECK_INIT is called (eventually) by __srefill_r.  */
89  _REENT_SMALL_CHECK_INIT (reent);
90  return _getc_r (reent, _stdin_r (reent));
91}
92
93#endif
Note: See TracBrowser for help on using the repository browser.