OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [fgetwc.c] - Blame information for rev 171

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*-
2
 * Copyright (c) 2002-2004 Tim J. Robbins.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
 
27
/*
28
FUNCTION
29
<<fgetwc>>, <<getwc>>---get a wide character from a file or stream
30
 
31
INDEX
32
        fgetwc
33
INDEX
34
        _fgetwc_r
35
INDEX
36
        getwc
37
INDEX
38
        _getwc_r
39
 
40
ANSI_SYNOPSIS
41
        #include <stdio.h>
42
        #include <wchar.h>
43
        wint_t fgetwc(FILE *<[fp]>);
44
 
45
        #include <stdio.h>
46
        #include <wchar.h>
47
        wint_t _fgetwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
48
 
49
        #include <stdio.h>
50
        #include <wchar.h>
51
        wint_t getwc(FILE *<[fp]>);
52
 
53
        #include <stdio.h>
54
        #include <wchar.h>
55
        wint_t _getwc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
56
 
57
TRAD_SYNOPSIS
58
        #include <stdio.h>
59
        #include <wchar.h>
60
        wint_t fgetwc(<[fp]>)
61
        FILE *<[fp]>;
62
 
63
        #include <stdio.h>
64
        #include <wchar.h>
65
        wint_t _fgetwc_r(<[ptr]>, <[fp]>)
66
        struct _reent *<[ptr]>;
67
        FILE *<[fp]>;
68
 
69
        #include <stdio.h>
70
        #include <wchar.h>
71
        wint_t getwc(<[fp]>)
72
        FILE *<[fp]>;
73
 
74
        #include <stdio.h>
75
        #include <wchar.h>
76
        wint_t _getwc_r(<[ptr]>, <[fp]>)
77
        struct _reent *<[ptr]>;
78
        FILE *<[fp]>;
79
 
80
DESCRIPTION
81
Use <<fgetwc>> to get the next wide character from the file or stream
82
identified by <[fp]>.  As a side effect, <<fgetwc>> advances the file's
83
current position indicator.
84
 
85
The  <<getwc>>  function  or macro functions identically to <<fgetwc>>.  It
86
may be implemented as a macro, and may evaluate its argument more  than
87
once. There is no reason ever to use it.
88
 
89
<<_fgetwc_r>> and <<_getwc_r>> are simply reentrant versions of
90
<<fgetwc>> and <<getwc>> that are passed the additional reentrant
91
structure pointer argument: <[ptr]>.
92
 
93
RETURNS
94
The next wide character cast to <<wint_t>>), unless there is no more data,
95
or the host system reports a read error; in either of these situations,
96
<<fgetwc>> and <<getwc>> return <<WEOF>>.
97
 
98
You can distinguish the two situations that cause an <<EOF>> result by
99
using the <<ferror>> and <<feof>> functions.
100
 
101
PORTABILITY
102
C99, POSIX.1-2001
103
*/
104
 
105
#include <_ansi.h>
106
#include <reent.h>
107
#include <errno.h>
108
#include <stdio.h>
109
#include <stdlib.h>
110
#include <wchar.h>
111
#include "local.h"
112
 
113
static wint_t
114
_DEFUN(__fgetwc, (ptr, fp),
115
        struct _reent *ptr _AND
116
        register FILE *fp)
117
{
118
  wchar_t wc;
119
  size_t nconv;
120
 
121
  if (fp->_r <= 0 && __srefill_r (ptr, fp))
122
    return (WEOF);
123
  if (MB_CUR_MAX == 1)
124
    {
125
      /* Fast path for single-byte encodings. */
126
      wc = *fp->_p++;
127
      fp->_r--;
128
      return (wc);
129
    }
130
  do
131
    {
132
      nconv = _mbrtowc_r (ptr, &wc, fp->_p, fp->_r, &fp->_mbstate);
133
      if (nconv == (size_t)-1)
134
        break;
135
      else if (nconv == (size_t)-2)
136
        continue;
137
      else if (nconv == 0)
138
        {
139
          /*
140
           * Assume that the only valid representation of
141
           * the null wide character is a single null byte.
142
           */
143
          fp->_p++;
144
          fp->_r--;
145
          return (L'\0');
146
        }
147
      else
148
        {
149
          fp->_p += nconv;
150
          fp->_r -= nconv;
151
          return (wc);
152
        }
153
    }
154
  while (__srefill_r(ptr, fp) == 0);
155
  fp->_flags |= __SERR;
156
  errno = EILSEQ;
157
  return (WEOF);
158
}
159
 
160
wint_t
161
_DEFUN(_fgetwc_r, (ptr, fp),
162
        struct _reent *ptr _AND
163
        register FILE *fp)
164
{
165
  wint_t r;
166
 
167
  _flockfile (fp);
168
  ORIENT(fp, 1);
169
  r = __fgetwc (ptr, fp);
170
  _funlockfile (fp);
171
  return r;
172
}
173
 
174
wint_t
175
_DEFUN(fgetwc, (fp),
176
        FILE *fp)
177
{
178
  CHECK_INIT(_REENT, fp);
179
  return _fgetwc_r (_REENT, fp);
180
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.