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/] [fputws.c] - Blame information for rev 194

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
<<fputws>>---write a wide character string in a file or stream
30
 
31
INDEX
32
        fputws
33
INDEX
34
        _fputws_r
35
 
36
ANSI_SYNOPSIS
37
        #include <wchar.h>
38
        int fputws(const wchar_t *<[ws]>, FILE *<[fp]>);
39
 
40
        #include <wchar.h>
41
        int _fputws_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>, FILE *<[fp]>);
42
 
43
TRAD_SYNOPSIS
44
        #include <wchar.h>
45
        int fputws(<[ws]>, <[fp]>)
46
        wchar_t *<[ws]>;
47
        FILE *<[fp]>;
48
 
49
        #include <wchar.h>
50
        int _fputws_r(<[ptr]>, <[ws]>, <[fp]>)
51
        struct _reent *<[ptr]>;
52
        wchar_t *<[ws]>;
53
        FILE *<[fp]>;
54
 
55
DESCRIPTION
56
<<fputws>> writes the wide character string at <[ws]> (but without the
57
trailing null) to the file or stream identified by <[fp]>.
58
 
59
<<_fputws_r>> is simply the reentrant version of <<fputws>> that takes
60
an additional reentrant struct pointer argument: <[ptr]>.
61
 
62
RETURNS
63
If successful, the result is a non-negative integer; otherwise, the result
64
is <<-1>> to indicate an error.
65
 
66
PORTABILITY
67
C99, POSIX.1-2001
68
*/
69
 
70
#include <_ansi.h>
71
#include <reent.h>
72
#include <errno.h>
73
#include <limits.h>
74
#include <stdio.h>
75
#include <wchar.h>
76
#include "fvwrite.h"
77
#include "local.h"
78
 
79
int
80
_DEFUN(_fputws_r, (ptr, ws, fp),
81
        struct _reent *ptr _AND
82
        const wchar_t *ws _AND
83
        FILE *fp)
84
{
85
  size_t nbytes;
86
  char buf[BUFSIZ];
87
  struct __suio uio;
88
  struct __siov iov;
89
 
90
  _flockfile (fp);
91
  ORIENT (fp, 1);
92
  if (cantwrite (ptr, fp) != 0)
93
    goto error;
94
  uio.uio_iov = &iov;
95
  uio.uio_iovcnt = 1;
96
  iov.iov_base = buf;
97
  do
98
    {
99
      nbytes = _wcsrtombs_r(ptr, buf, &ws, sizeof (buf), &fp->_mbstate);
100
      if (nbytes == (size_t) -1)
101
        goto error;
102
      iov.iov_len = uio.uio_resid = nbytes;
103
      if (__sfvwrite_r(ptr, fp, &uio) != 0)
104
        goto error;
105
    }
106
  while (ws != NULL);
107
  _funlockfile (fp);
108
  return (0);
109
 
110
error:
111
  _funlockfile(fp);
112
  return (-1);
113
}
114
 
115
int
116
_DEFUN(fputws, (ws, fp),
117
        const wchar_t *ws _AND
118
        FILE *fp)
119
{
120
  CHECK_INIT (_REENT, fp);
121
  return _fputws_r (_REENT, ws, fp);
122
}

powered by: WebSVN 2.1.0

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