Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
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 
22
#include 
23
#ifdef _HAVE_STDC
24
#include 
25
#else
26
#include 
27
#endif
28
#include 
29
#include 
30
#include "local.h"
31
 
32
int
33
#ifdef _HAVE_STDC
34
_DEFUN(_snprintf_r, (ptr, str, size, fmt),
35
       struct _reent *ptr _AND
4921 Serge 36
       char *__restrict str          _AND
4349 Serge 37
       size_t size        _AND
4921 Serge 38
       _CONST char *__restrict fmt _DOTS)
4349 Serge 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),
4921 Serge 80
       char *__restrict str _AND
4349 Serge 81
       size_t size _AND
4921 Serge 82
       _CONST char *__restrict fmt _DOTS)
4349 Serge 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