2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
29 #include <X11/Xfuncproto.h>
31 #ifndef _X_RESTRICT_KYWD
32 #if defined(restrict) /* assume autoconf set it correctly */ || \
33 (defined(__STDC__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */
34 #define _X_RESTRICT_KYWD restrict
35 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
36 #define _X_RESTRICT_KYWD __restrict__
38 #define _X_RESTRICT_KYWD
43 * These functions provide a portable implementation of the common (but not
44 * yet universal) asprintf & vasprintf routines to allocate a buffer big
45 * enough to sprintf the arguments to. The XNF variants terminate the server
46 * if the allocation fails.
47 * The buffer allocated is returned in the pointer provided in the first
48 * argument. The return value is the size of the allocated buffer, or -1
52 Xasprintf(char **ret
, const char *_X_RESTRICT_KYWD fmt
, ...)
53 _X_ATTRIBUTE_PRINTF(2, 3);
55 Xvasprintf(char **ret
, const char *_X_RESTRICT_KYWD fmt
, va_list va
)
56 _X_ATTRIBUTE_PRINTF(2, 0);
58 XNFasprintf(char **ret
, const char *_X_RESTRICT_KYWD fmt
, ...)
59 _X_ATTRIBUTE_PRINTF(2, 3);
61 XNFvasprintf(char **ret
, const char *_X_RESTRICT_KYWD fmt
, va_list va
)
62 _X_ATTRIBUTE_PRINTF(2, 0);
64 #if !defined(HAVE_ASPRINTF) && !defined(HAVE_VASPRINTF)
65 #define asprintf Xasprintf
66 #define vasprintf Xvasprintf
70 * These functions provide a portable implementation of the linux kernel
71 * scnprintf & vscnprintf routines that return the number of bytes actually
72 * copied during a snprintf, (excluding the final '\0').
75 Xscnprintf(char *s
, int n
, const char * _X_RESTRICT_KYWD fmt
, ...)
76 _X_ATTRIBUTE_PRINTF(3,4);
78 Xvscnprintf(char *s
, int n
, const char * _X_RESTRICT_KYWD fmt
, va_list va
)
79 _X_ATTRIBUTE_PRINTF(3,0);
81 #endif /* XPRINTF_H */