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