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

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
/* This code was copied from sprintf.c */
18
/* doc in sprintf.c */
19
 
20
#include <_ansi.h>
21
#include <reent.h>
22
#include <stdio.h>
23
#include <stdarg.h>
24
#include <limits.h>
25
#include "local.h"
26
 
27
int
28
_DEFUN(_asprintf_r, (ptr, strp, fmt),
29
       struct _reent *ptr _AND
30
       char **strp        _AND
31
       const char *fmt _DOTS)
32
{
33
  int ret;
34
  va_list ap;
35
  FILE f;
36
 
37
  /* mark a zero-length reallocatable buffer */
38
  f._flags = __SWR | __SSTR | __SMBF;
39
  f._bf._base = f._p = NULL;
40
  f._bf._size = f._w = 0;
41
  f._file = -1;  /* No file. */
42
  va_start (ap, fmt);
43
  ret = _svfprintf_r (ptr, &f, fmt, ap);
44
  va_end (ap);
45
  if (ret >= 0)
46
    {
47
      *f._p = 0;
48
      *strp = f._bf._base;
49
    }
50
  return (ret);
51
}
52
 
53
#ifndef _REENT_ONLY
54
 
55
int
56
_DEFUN(asprintf, (strp, fmt),
57
       char **strp _AND
58
       const char *fmt _DOTS)
59
{
60
  int ret;
61
  va_list ap;
62
  FILE f;
63
 
64
  /* mark a zero-length reallocatable buffer */
65
  f._flags = __SWR | __SSTR | __SMBF;
66
  f._bf._base = f._p = NULL;
67
  f._bf._size = f._w = 0;
68
  f._file = -1;  /* No file. */
69
  va_start (ap, fmt);
70
  ret = _svfprintf_r (_REENT, &f, fmt, ap);
71
  va_end (ap);
72
  if (ret >= 0)
73
    {
74
      *f._p = 0;
75
      *strp = f._bf._base;
76
    }
77
  return (ret);
78
}
79
 
80
#endif /* ! _REENT_ONLY */

powered by: WebSVN 2.1.0

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