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

powered by: WebSVN 2.1.0

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