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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [snprintf.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/* doc in sprintf.c */
2
 
3
/* This code created by modifying sprintf.c so copyright inherited. */
4
 
5
/*
6
 * Copyright (c) 1990 The Regents of the University of California.
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms are permitted
10
 * provided that the above copyright notice and this paragraph are
11
 * duplicated in all such forms and that any documentation,
12
 * advertising materials, and other materials related to such
13
 * distribution and use acknowledge that the software was developed
14
 * by the University of California, Berkeley.  The name of the
15
 * University may not be used to endorse or promote products derived
16
 * from this software without specific prior written permission.
17
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20
 */
21
 
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 <_ansi.h>
30
#include "local.h"
31
 
32
int
33
#ifdef _HAVE_STDC
34
_DEFUN (_snprintf_r, (ptr, str, size, fmt), struct _reent *ptr _AND char *str _AND size_t size _AND _CONST char *fmt _DOTS)
35
#else
36
_snprintf_r (ptr, str, size, fmt, va_alist)
37
     struct _reent *ptr;
38
     char *str;
39
     size_t size;
40
     _CONST char *fmt;
41
     va_dcl
42
#endif
43
{
44
  int ret;
45
  va_list ap;
46
  FILE f;
47
 
48
  f._flags = __SWR | __SSTR;
49
  f._bf._base = f._p = (unsigned char *) str;
50
  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
51
  f._data = ptr;
52
#ifdef _HAVE_STDC
53
  va_start (ap, fmt);
54
#else
55
  va_start (ap);
56
#endif
57
  ret = vfprintf (&f, fmt, ap);
58
  va_end (ap);
59
  if (size > 0)
60
    *f._p = 0;
61
  return (ret);
62
}
63
 
64
#ifndef _REENT_ONLY
65
 
66
int
67
#ifdef _HAVE_STDC
68
_DEFUN (snprintf, (str, size, fmt), char *str _AND size_t size _AND _CONST char *fmt _DOTS)
69
#else
70
snprintf (str, size, fmt, va_alist)
71
     char *str;
72
     size_t size;
73
     _CONST char *fmt;
74
     va_dcl
75
#endif
76
{
77
  int ret;
78
  va_list ap;
79
  FILE f;
80
 
81
  f._flags = __SWR | __SSTR;
82
  f._bf._base = f._p = (unsigned char *) str;
83
  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
84
  f._data = _REENT;
85
#ifdef _HAVE_STDC
86
  va_start (ap, fmt);
87
#else
88
  va_start (ap);
89
#endif
90
  ret = vfprintf (&f, fmt, ap);
91
  va_end (ap);
92
  if (size > 0)
93
    *f._p = 0;
94
  return (ret);
95
}
96
 
97
#endif

powered by: WebSVN 2.1.0

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