replace.h revision 60da515c
1c7b4381aSmrg/* 2c7b4381aSmrg * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3c7b4381aSmrg * 4c7b4381aSmrg * Permission is hereby granted, free of charge, to any person obtaining a 5c7b4381aSmrg * copy of this software and associated documentation files (the "Software"), 6c7b4381aSmrg * to deal in the Software without restriction, including without limitation 7c7b4381aSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c7b4381aSmrg * and/or sell copies of the Software, and to permit persons to whom the 9c7b4381aSmrg * Software is furnished to do so, subject to the following conditions: 10c7b4381aSmrg * 11c7b4381aSmrg * The above copyright notice and this permission notice (including the next 12c7b4381aSmrg * paragraph) shall be included in all copies or substantial portions of the 13c7b4381aSmrg * Software. 14c7b4381aSmrg * 15c7b4381aSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16c7b4381aSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17c7b4381aSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18c7b4381aSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19c7b4381aSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20c7b4381aSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21c7b4381aSmrg * DEALINGS IN THE SOFTWARE. 22c7b4381aSmrg */ 23c7b4381aSmrg 24c7b4381aSmrg/* Local replacements for functions found in some, but not all, libc's */ 25c7b4381aSmrg#ifndef XFONT_REPLACE_H 26c7b4381aSmrg#define XFONT_REPLACE_H 27c7b4381aSmrg 28c7b4381aSmrg#ifdef HAVE_CONFIG_H 29c7b4381aSmrg#include <config.h> 30c7b4381aSmrg#endif 31c7b4381aSmrg 32c7b4381aSmrg#include <X11/Xfuncproto.h> 33c7b4381aSmrg 34c7b4381aSmrg#include <stdlib.h> 35c7b4381aSmrg#if defined(HAVE_LIBBSD) && defined(HAVE_REALLOCARRAY) 36c7b4381aSmrg#include <bsd/stdlib.h> /* for reallocarray */ 37c7b4381aSmrg#endif 38c7b4381aSmrg 39c7b4381aSmrg#ifndef HAVE_REALLOCARRAY 40c7b4381aSmrgextern _X_HIDDEN void * 41c7b4381aSmrgreallocarray(void *optr, size_t nmemb, size_t size); 42c7b4381aSmrg#endif 43c7b4381aSmrg 44c7b4381aSmrg#ifndef mallocarray 45c7b4381aSmrg#define mallocarray(n, s) reallocarray(NULL, n, s) 46c7b4381aSmrg#endif 47c7b4381aSmrg 48c7b4381aSmrg#include <string.h> 49c7b4381aSmrg#if defined(HAVE_LIBBSD) && defined(HAVE_STRLCPY) 50c7b4381aSmrg#include <bsd/string.h> /* for strlcpy, strlcat */ 51c7b4381aSmrg#endif 52c7b4381aSmrg 53c7b4381aSmrg#ifndef HAVE_STRLCPY 54c7b4381aSmrgextern _X_HIDDEN size_t 55c7b4381aSmrgstrlcpy(char *dst, const char *src, size_t siz); 56c7b4381aSmrgextern _X_HIDDEN size_t 57c7b4381aSmrgstrlcat(char *dst, const char *src, size_t siz); 58c7b4381aSmrg#endif 59c7b4381aSmrg 6060da515cSmrg#ifndef HAVE_ERR_H 6160da515cSmrg#define err(eval, ...) do { \ 6260da515cSmrg fprintf(stderr, __VA_ARGS__); \ 6360da515cSmrg fprintf(stderr, "\n"); \ 6460da515cSmrg exit(eval); \ 6560da515cSmrg } while (0) 6660da515cSmrg#define vwarn(...) do { \ 6760da515cSmrg fprintf(stderr, __VA_ARGS__); \ 6860da515cSmrg fprintf(stderr, "\n"); \ 6960da515cSmrg } while (0) 7060da515cSmrg#endif 7160da515cSmrg 7260da515cSmrg#ifndef HAVE_REALPATH 7360da515cSmrgextern _X_HIDDEN char * 7460da515cSmrgrealpath(const char *path, char *resolved_path); 7560da515cSmrg#endif 76c7b4381aSmrg 77c7b4381aSmrg#endif /* XFONT_REPLACE_H */ 78