Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*-
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
<>, <>---write a wide character on a stream or file
30
 
31
INDEX
32
	fputwc
33
INDEX
34
	_fputwc_r
35
INDEX
36
	putwc
37
INDEX
38
	_putwc_r
39
 
40
ANSI_SYNOPSIS
41
	#include 
42
	#include 
43
	wint_t fputwc(wchar_t <[wc]>, FILE *<[fp]>);
44
 
45
	#include 
46
	#include 
47
	wint_t _fputwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
48
 
49
	#include 
50
	#include 
51
	wint_t putwc(wchar_t <[wc]>, FILE *<[fp]>);
52
 
53
	#include 
54
	#include 
55
	wint_t _putwc_r(struct _reent *<[ptr]>, wchar_t <[wc]>, FILE *<[fp]>);
56
 
57
TRAD_SYNOPSIS
58
	#include 
59
	#include 
60
	wint_t fputwc(<[wc]>, <[fp]>)
61
	wchar_t <[wc]>;
62
	FILE *<[fp]>;
63
 
64
	#include 
65
	#include 
66
	wint_t _fputwc_r(<[ptr]>, <[wc]>, <[fp]>)
67
	struct _reent *<[ptr]>;
68
	wchar_t <[wc]>;
69
	FILE *<[fp]>;
70
 
71
	#include 
72
	#include 
73
	wint_t putwc(<[wc]>, <[fp]>)
74
	wchar_t <[wc]>;
75
	FILE *<[fp]>;
76
 
77
	#include 
78
	#include 
79
	wint_t _putwc_r(<[ptr]>, <[wc]>, <[fp]>)
80
	struct _reent *<[ptr]>;
81
	wchar_t <[wc]>;
82
	FILE *<[fp]>;
83
 
84
DESCRIPTION
85
<> writes the wide character argument <[wc]> to the file or
86
stream identified by <[fp]>.
87
 
88
If the file was opened with append mode (or if the stream cannot
89
support positioning), then the new wide character goes at the end of the
90
file or stream.  Otherwise, the new wide character is written at the
91
current value of the position indicator, and the position indicator
92
oadvances by one.
93
 
94
The <> function or macro functions identically to <>.  It
95
may be implemented as a macro, and may evaluate its argument more than
96
once. There is no reason ever to use it.
97
 
98
The <<_fputwc_r>> and <<_putwc_r>> functions are simply reentrant versions
99
of <> and <> that take an additional reentrant structure
100
argument: <[ptr]>.
101
 
102
RETURNS
103
If successful, <> and <> return their argument <[wc]>.
104
If an error intervenes, the result is <>.  You can use
105
`<)>>' to query for errors.
106
 
107
PORTABILITY
108
C99, POSIX.1-2001
109
*/
110
 
111
#include <_ansi.h>
112
#include 
113
#include 
114
#include 
115
#include 
116
#include 
117
#include 
118
#include "local.h"
119
 
120
static wint_t
121
_DEFUN(__fputwc, (ptr, wc, fp),
122
	struct _reent *ptr _AND
123
	wchar_t wc _AND
124
	FILE *fp)
125
{
126
  char buf[MB_LEN_MAX];
127
  size_t i, len;
128
 
129
  if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX)
130
    {
131
      /*
132
       * Assume single-byte locale with no special encoding.
133
       * A more careful test would be to check
134
       * _CurrentRuneLocale->encoding.
135
       */
136
      *buf = (unsigned char)wc;
137
      len = 1;
138
    }
139
  else
140
    {
141
      if ((len = _wcrtomb_r (ptr, buf, wc, &fp->_mbstate)) == (size_t) -1)
142
	{
143
	  fp->_flags |= __SERR;
144
	  return WEOF;
145
	}
146
    }
147
 
148
  for (i = 0; i < len; i++)
149
    if (__sputc_r (ptr, (unsigned char) buf[i], fp) == EOF)
150
      return WEOF;
151
 
152
  return (wint_t) wc;
153
}
154
 
155
wint_t
156
_DEFUN(_fputwc_r, (ptr, wc, fp),
157
	struct _reent *ptr _AND
158
	wchar_t wc _AND
159
	FILE *fp)
160
{
161
  wint_t r;
162
 
4921 Serge 163
  _newlib_flockfile_start (fp);
4349 Serge 164
  ORIENT(fp, 1);
165
  r = __fputwc(ptr, wc, fp);
4921 Serge 166
  _newlib_flockfile_end (fp);
4349 Serge 167
  return r;
168
}
169
 
170
wint_t
171
_DEFUN(fputwc, (wc, fp),
172
	wchar_t wc _AND
173
	FILE *fp)
174
{
4921 Serge 175
  struct _reent *reent = _REENT;
176
 
177
  CHECK_INIT(reent, fp);
178
  return _fputwc_r (reent, wc, fp);
4349 Serge 179
}