a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Permission is hereby granted, free of charge, to any person obtaining a
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * copy of this software and associated documentation files (the "Software"),
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * to deal in the Software without restriction, including without limitation
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the rights to use, copy, modify, merge, publish, distribute, sublicense,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * and/or sell copies of the Software, and to permit persons to whom the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Software is furnished to do so, subject to the following conditions:
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * The above copyright notice and this permission notice (including the next
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * paragraph) shall be included in all copies or substantial portions of the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Software.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * DEALINGS IN THE SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef XPRINTF_H
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define XPRINTF_H
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stdio.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <stdarg.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <X11/Xfuncproto.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef _X_RESTRICT_KYWD
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if defined(restrict) /* assume autoconf set it correctly */ || \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync (defined(__STDC__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _X_RESTRICT_KYWD restrict
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _X_RESTRICT_KYWD __restrict__
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#else
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define _X_RESTRICT_KYWD
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * These functions provide a portable implementation of the common (but not
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * yet universal) asprintf & vasprintf routines to allocate a buffer big
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * enough to sprintf the arguments to. The XNF variants terminate the server
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * if the allocation fails.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * The buffer allocated is returned in the pointer provided in the first
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * argument. The return value is the size of the allocated buffer, or -1
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * on failure.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, ...)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(2, 3);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXvasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, va_list va)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(2, 0);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXNFasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, ...)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(2, 3);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXNFvasprintf(char **ret, const char *_X_RESTRICT_KYWD fmt, va_list va)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(2, 0);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#if !defined(HAVE_ASPRINTF) && !defined(HAVE_VASPRINTF)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define asprintf Xasprintf
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define vasprintf Xvasprintf
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * These functions provide a portable implementation of the linux kernel
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * scnprintf & vscnprintf routines that return the number of bytes actually
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * copied during a snprintf, (excluding the final '\0').
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXscnprintf(char *s, int n, const char * _X_RESTRICT_KYWD fmt, ...)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(3,4);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncextern _X_EXPORT int
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncXvscnprintf(char *s, int n, const char * _X_RESTRICT_KYWD fmt, va_list va)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync_X_ATTRIBUTE_PRINTF(3,0);
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif /* XPRINTF_H */