1121982Sjhb/**************************************************************************** 2121982Sjhb * Copyright 2020,2021 Thomas E. Dickey * 3121982Sjhb * Copyright 2012-2013,2016 Free Software Foundation, Inc. * 4121982Sjhb * * 5121982Sjhb * Permission is hereby granted, free of charge, to any person obtaining a * 6121982Sjhb * copy of this software and associated documentation files (the * 7121982Sjhb * "Software"), to deal in the Software without restriction, including * 8121982Sjhb * without limitation the rights to use, copy, modify, merge, publish, * 9121982Sjhb * distribute, distribute with modifications, sublicense, and/or sell * 10121982Sjhb * copies of the Software, and to permit persons to whom the Software is * 11121982Sjhb * furnished to do so, subject to the following conditions: * 12121982Sjhb * * 13121982Sjhb * The above copyright notice and this permission notice shall be included * 14121982Sjhb * in all copies or substantial portions of the Software. * 15121982Sjhb * * 16121982Sjhb * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 17121982Sjhb * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 18121982Sjhb * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 19121982Sjhb * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 20121982Sjhb * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 21121982Sjhb * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 22121982Sjhb * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 23121982Sjhb * * 24121982Sjhb * Except as contained in this notice, the name(s) of the above copyright * 25121982Sjhb * holders shall not be used in advertising or otherwise to promote the * 26121982Sjhb * sale, use or other dealings in this Software without prior written * 27121982Sjhb * authorization. * 28121982Sjhb ****************************************************************************/ 29121982Sjhb 30121982Sjhb/**************************************************************************** 31121982Sjhb * Author: Thomas E. Dickey 2012 * 32121982Sjhb ****************************************************************************/ 33121982Sjhb 34151979Sjhb#ifndef STRING_HACKS_H 35151979Sjhb#define STRING_HACKS_H 1 36151979Sjhb 37151979Sjhb#include <ncurses_cfg.h> 38151979Sjhb 39151979Sjhb#if HAVE_BSD_STRING_H 40151979Sjhb#include <bsd/string.h> 41151979Sjhb#endif 42151979Sjhb 43151979Sjhb/* 44151979Sjhb * $Id: nc_string.h,v 1.1 2023/10/17 09:52:08 nicm Exp $ 45151979Sjhb * 46164265Sjhb * String-hacks. Use these macros to stifle warnings on (presumably) correct 47164265Sjhb * uses of strcat, strcpy and sprintf. 48164265Sjhb * 49151979Sjhb * By the way - 50164265Sjhb * A fundamental limitation of the interfaces (and frequent issue in bug 51164265Sjhb * reports using these functions) is that sizes are passed as unsigned values 52164265Sjhb * (with associated sign-extension problems), limiting their effectiveness 53121982Sjhb * when checking for buffer overflow. 54151979Sjhb */ 55164265Sjhb 56164265Sjhb#ifdef __cplusplus 57164265Sjhb#define NCURSES_VOID /* nothing */ 58164265Sjhb#else 59164265Sjhb#define NCURSES_VOID (void) 60151979Sjhb#endif 61151979Sjhb 62151979Sjhb#if USE_STRING_HACKS && HAVE_STRLCAT 63151979Sjhb#define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n)) 64151979Sjhb#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m)) 65151979Sjhb#else 66163212Sjhb#define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s)) 67163212Sjhb#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n)) 68151979Sjhb#endif 69151979Sjhb 70151979Sjhb#if USE_STRING_HACKS && HAVE_STRLCPY 71121982Sjhb#define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n)) 72121982Sjhb#define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n)) 73121982Sjhb#else 74121982Sjhb#define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s)) 75121982Sjhb#define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n)) 76121982Sjhb#endif 77121982Sjhb 78121982Sjhb#if USE_STRING_HACKS && HAVE_SNPRINTF 79121982Sjhb#ifdef __cplusplus 80121982Sjhb#define _nc_SPRINTF NCURSES_VOID snprintf 81121982Sjhb#else 82121982Sjhb#define _nc_SPRINTF NCURSES_VOID (snprintf) 83121982Sjhb#endif 84121982Sjhb#define _nc_SLIMIT(n) NCURSES_CAST(size_t,n), 85121982Sjhb#else 86133907Speter#define _nc_SPRINTF NCURSES_VOID sprintf 87121982Sjhb#define _nc_SLIMIT(n) /* nothing */ 88121982Sjhb#endif 89121982Sjhb 90121982Sjhb#endif /* STRING_HACKS_H */ 91163219Sjhb