source: trunk/libs/newlib/src/newlib/libc/stdio/getc.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.9 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<<getc>>---read a character (macro)
21
22INDEX
23        getc
24INDEX
25        _getc_r
26
27SYNOPSIS
28        #include <stdio.h>
29        int getc(FILE *<[fp]>);
30
31        #include <stdio.h>
32        int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
33
34DESCRIPTION
35<<getc>> is a macro, defined in <<stdio.h>>.  You can use <<getc>>
36to get the next single character from the file or stream
37identified by <[fp]>.  As a side effect, <<getc>> advances the file's
38current position indicator.
39
40For a subroutine version of this macro, see <<fgetc>>.
41
42The <<_getc_r>> function is simply the reentrant version of <<getc>>
43which passes an additional reentrancy structure pointer argument: <[ptr]>.
44
45RETURNS
46The next character (read as an <<unsigned char>>, and cast to
47<<int>>), unless there is no more data, or the host system reports a
48read error; in either of these situations, <<getc>> returns <<EOF>>.
49
50You can distinguish the two situations that cause an <<EOF>> result by
51using the <<ferror>> and <<feof>> functions.
52
53PORTABILITY
54ANSI C requires <<getc>>; it suggests, but does not require, that
55<<getc>> be implemented as a macro.  The standard explicitly permits
56macro implementations of <<getc>> to use the argument more than once;
57therefore, in a portable program, you should not use an expression
58with side effects as the <<getc>> argument.
59
60Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
61<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
62*/
63
64#if defined(LIBC_SCCS) && !defined(lint)
65static char sccsid[] = "%W% (Berkeley) %G%";
66#endif /* LIBC_SCCS and not lint */
67
68#include <_ansi.h>
69#include <stdio.h>
70#include "local.h"
71
72/*
73 * A subroutine version of the macro getc.
74 */
75
76#undef getc
77
78int
79_getc_r (struct _reent *ptr,
80       register FILE *fp)
81{
82  int result;
83  CHECK_INIT (ptr, fp);
84  _newlib_flockfile_start (fp);
85  result = __sgetc_r (ptr, fp);
86  _newlib_flockfile_end (fp);
87  return result;
88}
89
90#ifndef _REENT_ONLY
91
92int
93getc (register FILE *fp)
94{
95  int result;
96  struct _reent *reent = _REENT;
97
98  CHECK_INIT (reent, fp);
99  _newlib_flockfile_start (fp);
100  result = __sgetc_r (reent, fp);
101  _newlib_flockfile_end (fp);
102  return result;
103}
104
105#endif /* !_REENT_ONLY */
Note: See TracBrowser for help on using the repository browser.