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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [sniprintf.c] - Blame information for rev 862

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

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * Copyright (c) 1990, 2007 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
/* This code created by modifying snprintf.c so copyright inherited. */
19
/* doc in siprintf.c */
20
 
21
#include <_ansi.h>
22
#include <reent.h>
23
#include <stdio.h>
24
#ifdef _HAVE_STDC
25
#include <stdarg.h>
26
#else
27
#include <varargs.h>
28
#endif
29
#include <limits.h>
30
#include <errno.h>
31
#include "local.h"
32
 
33
int
34
#ifdef _HAVE_STDC
35
_DEFUN (_sniprintf_r, (ptr, str, size, fmt),
36
        struct _reent *ptr _AND
37
        char *str _AND
38
        size_t size _AND
39
        _CONST char *fmt _DOTS)
40
#else
41
_sniprintf_r (ptr, str, size, fmt, va_alist)
42
     struct _reent *ptr;
43
     char *str;
44
     size_t size;
45
     _CONST char *fmt;
46
     va_dcl
47
#endif
48
{
49
  int ret;
50
  va_list ap;
51
  FILE f;
52
 
53
  if (size > INT_MAX)
54
    {
55
      ptr->_errno = EOVERFLOW;
56
      return EOF;
57
    }
58
  f._flags = __SWR | __SSTR;
59
  f._bf._base = f._p = (unsigned char *) str;
60
  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
61
  f._file = -1;  /* No file. */
62
#ifdef _HAVE_STDC
63
  va_start (ap, fmt);
64
#else
65
  va_start (ap);
66
#endif
67
  ret = _svfiprintf_r (ptr, &f, fmt, ap);
68
  va_end (ap);
69
  if (ret < EOF)
70
    ptr->_errno = EOVERFLOW;
71
  if (size > 0)
72
    *f._p = 0;
73
  return (ret);
74
}
75
 
76
#ifndef _REENT_ONLY
77
 
78
int
79
#ifdef _HAVE_STDC
80
_DEFUN (sniprintf, (str, size, fmt),
81
        char *str _AND
82
        size_t size _AND
83
        _CONST char *fmt _DOTS)
84
#else
85
sniprintf (str, size, fmt, va_alist)
86
     char *str;
87
     size_t size;
88
     _CONST char *fmt;
89
     va_dcl
90
#endif
91
{
92
  int ret;
93
  va_list ap;
94
  FILE f;
95
  struct _reent *ptr = _REENT;
96
 
97
  if (size > INT_MAX)
98
    {
99
      ptr->_errno = EOVERFLOW;
100
      return EOF;
101
    }
102
  f._flags = __SWR | __SSTR;
103
  f._bf._base = f._p = (unsigned char *) str;
104
  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
105
  f._file = -1;  /* No file. */
106
#ifdef _HAVE_STDC
107
  va_start (ap, fmt);
108
#else
109
  va_start (ap);
110
#endif
111
  ret = _svfiprintf_r (ptr, &f, fmt, ap);
112
  va_end (ap);
113
  if (ret < EOF)
114
    ptr->_errno = EOVERFLOW;
115
  if (size > 0)
116
    *f._p = 0;
117
  return (ret);
118
}
119
 
120
#endif

powered by: WebSVN 2.1.0

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