Rev 4921 | 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 | |||
6099 | serge | 75 | #ifdef _NANO_FORMATTED_IO |
76 | int |
||
77 | _EXFUN(_sniprintf_r, (struct _reent *, char *, size_t, const char *, ...) |
||
78 | _ATTRIBUTE ((__alias__("_snprintf_r")))); |
||
79 | #endif |
||
80 | |||
4349 | Serge | 81 | #ifndef _REENT_ONLY |
82 | |||
83 | int |
||
84 | #ifdef _HAVE_STDC |
||
85 | _DEFUN(snprintf, (str, size, fmt), |
||
4921 | Serge | 86 | char *__restrict str _AND |
4349 | Serge | 87 | size_t size _AND |
4921 | Serge | 88 | _CONST char *__restrict fmt _DOTS) |
4349 | Serge | 89 | #else |
90 | snprintf(str, size, fmt, va_alist) |
||
91 | char *str; |
||
92 | size_t size; |
||
93 | _CONST char *fmt; |
||
94 | va_dcl |
||
95 | #endif |
||
96 | { |
||
97 | int ret; |
||
98 | va_list ap; |
||
99 | FILE f; |
||
100 | struct _reent *ptr = _REENT; |
||
101 | |||
102 | if (size > INT_MAX) |
||
103 | { |
||
104 | ptr->_errno = EOVERFLOW; |
||
105 | return EOF; |
||
106 | } |
||
107 | f._flags = __SWR | __SSTR; |
||
108 | f._bf._base = f._p = (unsigned char *) str; |
||
109 | f._bf._size = f._w = (size > 0 ? size - 1 : 0); |
||
110 | f._file = -1; /* No file. */ |
||
111 | #ifdef _HAVE_STDC |
||
112 | va_start (ap, fmt); |
||
113 | #else |
||
114 | va_start (ap); |
||
115 | #endif |
||
116 | ret = _svfprintf_r (ptr, &f, fmt, ap); |
||
117 | va_end (ap); |
||
118 | if (ret < EOF) |
||
119 | ptr->_errno = EOVERFLOW; |
||
120 | if (size > 0) |
||
121 | *f._p = 0; |
||
122 | return (ret); |
||
123 | } |
||
124 | |||
6099 | serge | 125 | #ifdef _NANO_FORMATTED_IO |
126 | int |
||
127 | _EXFUN(sniprintf, (char *, size_t, const char *, ...) |
||
128 | _ATTRIBUTE ((__alias__("snprintf")))); |
||
4349 | Serge | 129 | #endif |
6099 | serge | 130 | #endif>> |