26
33
* holders shall not be used in advertising or otherwise to promote the sale,
27
34
* use or other dealings in this Software without prior written authorization.
37
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
39
* Permission is hereby granted, free of charge, to any person obtaining a
40
* copy of this software and associated documentation files (the "Software"),
41
* to deal in the Software without restriction, including without limitation
42
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
43
* and/or sell copies of the Software, and to permit persons to whom the
44
* Software is furnished to do so, subject to the following conditions:
46
* The above copyright notice and this permission notice (including the next
47
* paragraph) shall be included in all copies or substantial portions of the
50
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
53
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
55
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
56
* DEALINGS IN THE SOFTWARE.
29
59
#ifdef HAVE_DIX_CONFIG_H
30
60
#include <dix-config.h>
42
79
# error "no working va_copy was found"
84
* Varargs sprintf that allocates a string buffer the right size for
85
* the pattern & data provided and prints the requested data to it.
87
* @param ret Pointer to which the newly allocated buffer is written
88
* (contents undefined on error)
89
* @param format printf style format string
90
* @param va variable argument list
91
* @return size of allocated buffer, or -1 on error.
94
Xvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va)
97
return vasprintf(ret, format, va);
103
size = vsnprintf(NULL, 0, format, va2);
106
*ret = malloc(size + 1);
110
vsnprintf(*ret, size + 1, format, va);
116
#ifndef HAVE_VASPRINTF
117
# define vasprintf Xvasprintf
121
* sprintf that allocates a string buffer the right size for
122
* the pattern & data provided and prints the requested data to it.
124
* @param ret Pointer to which the newly allocated buffer is written
125
* (contents undefined on error)
126
* @param format printf style format string
127
* @param ... arguments for specified format
128
* @return size of allocated buffer, or -1 on error.
131
Xasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...)
135
va_start(va, format);
136
size = vasprintf(ret, format, va);
142
* Varargs sprintf that allocates a string buffer the right size for
143
* the pattern & data provided and prints the requested data to it.
144
* On failure, issues a FatalError message and aborts the server.
146
* @param ret Pointer to which the newly allocated buffer is written
147
* (contents undefined on error)
148
* @param format printf style format string
149
* @param va variable argument list
150
* @return size of allocated buffer
153
XNFvasprintf(char **ret, const char * _X_RESTRICT_KYWD format, va_list va)
155
int size = vasprintf(ret, format, va);
156
if ((size == -1) || (*ret == NULL)) {
157
Error("XNFvasprintf");
158
FatalError("XNFvasprintf failed");
164
* sprintf that allocates a string buffer the right size for
165
* the pattern & data provided and prints the requested data to it.
166
* On failure, issues a FatalError message and aborts the server.
168
* @param ret Pointer to which the newly allocated buffer is written
169
* (contents undefined on error)
170
* @param format printf style format string
171
* @param ... arguments for specified format
172
* @return size of allocated buffer
175
XNFasprintf(char ** ret, const char * _X_RESTRICT_KYWD format, ...)
179
va_start(va, format);
180
size = XNFvasprintf(ret, format, va);
185
/* Old api, now deprecated, may be removed in the future */
47
187
Xvprintf(const char *format, va_list va)
54
size = vsnprintf(NULL, 0, format, va2);
57
ret = (char *)malloc(size + 1);
61
vsnprintf(ret, size + 1, format, va);
191
if (vasprintf(&ret, format, va) == -1)