xref: /dflybsd-src/contrib/ncurses/include/nc_string.h (revision 0cadad7e49c6219b0de0675ef6a6f44683d177d4)
13468e90cSJohn Marino /****************************************************************************
2*32bb5217SDaniel Fojt  * Copyright 2020 Thomas E. Dickey                                          *
3*32bb5217SDaniel Fojt  * Copyright 2012-2013,2016 Free Software Foundation, Inc.                  *
43468e90cSJohn Marino  *                                                                          *
53468e90cSJohn Marino  * Permission is hereby granted, free of charge, to any person obtaining a  *
63468e90cSJohn Marino  * copy of this software and associated documentation files (the            *
73468e90cSJohn Marino  * "Software"), to deal in the Software without restriction, including      *
83468e90cSJohn Marino  * without limitation the rights to use, copy, modify, merge, publish,      *
93468e90cSJohn Marino  * distribute, distribute with modifications, sublicense, and/or sell       *
103468e90cSJohn Marino  * copies of the Software, and to permit persons to whom the Software is    *
113468e90cSJohn Marino  * furnished to do so, subject to the following conditions:                 *
123468e90cSJohn Marino  *                                                                          *
133468e90cSJohn Marino  * The above copyright notice and this permission notice shall be included  *
143468e90cSJohn Marino  * in all copies or substantial portions of the Software.                   *
153468e90cSJohn Marino  *                                                                          *
163468e90cSJohn Marino  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
173468e90cSJohn Marino  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
183468e90cSJohn Marino  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
193468e90cSJohn Marino  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
203468e90cSJohn Marino  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
213468e90cSJohn Marino  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
223468e90cSJohn Marino  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
233468e90cSJohn Marino  *                                                                          *
243468e90cSJohn Marino  * Except as contained in this notice, the name(s) of the above copyright   *
253468e90cSJohn Marino  * holders shall not be used in advertising or otherwise to promote the     *
263468e90cSJohn Marino  * sale, use or other dealings in this Software without prior written       *
273468e90cSJohn Marino  * authorization.                                                           *
283468e90cSJohn Marino  ****************************************************************************/
293468e90cSJohn Marino 
303468e90cSJohn Marino /****************************************************************************
313468e90cSJohn Marino  *  Author: Thomas E. Dickey                        2012                    *
323468e90cSJohn Marino  ****************************************************************************/
333468e90cSJohn Marino 
343468e90cSJohn Marino #ifndef STRING_HACKS_H
353468e90cSJohn Marino #define STRING_HACKS_H 1
363468e90cSJohn Marino 
373468e90cSJohn Marino #include <ncurses_cfg.h>
383468e90cSJohn Marino 
39*32bb5217SDaniel Fojt #if HAVE_BSD_STRING_H
40*32bb5217SDaniel Fojt #include <bsd/string.h>
41*32bb5217SDaniel Fojt #endif
42*32bb5217SDaniel Fojt 
433468e90cSJohn Marino /*
44*32bb5217SDaniel Fojt  * $Id: nc_string.h,v 1.8 2020/02/02 23:34:34 tom Exp $
453468e90cSJohn Marino  *
463468e90cSJohn Marino  * String-hacks.  Use these macros to stifle warnings on (presumably) correct
473468e90cSJohn Marino  * uses of strcat, strcpy and sprintf.
483468e90cSJohn Marino  *
493468e90cSJohn Marino  * By the way -
503468e90cSJohn Marino  * A fundamental limitation of the interfaces (and frequent issue in bug
513468e90cSJohn Marino  * reports using these functions) is that sizes are passed as unsigned values
523468e90cSJohn Marino  * (with associated sign-extension problems), limiting their effectiveness
533468e90cSJohn Marino  * when checking for buffer overflow.
543468e90cSJohn Marino  */
553468e90cSJohn Marino 
563468e90cSJohn Marino #ifdef __cplusplus
573468e90cSJohn Marino #define NCURSES_VOID		/* nothing */
583468e90cSJohn Marino #else
593468e90cSJohn Marino #define NCURSES_VOID (void)
603468e90cSJohn Marino #endif
613468e90cSJohn Marino 
623468e90cSJohn Marino #if USE_STRING_HACKS && HAVE_STRLCAT
633468e90cSJohn Marino #define _nc_STRCAT(d,s,n)	NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
64*32bb5217SDaniel Fojt #define _nc_STRNCAT(d,s,m,n)	NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
653468e90cSJohn Marino #else
663468e90cSJohn Marino #define _nc_STRCAT(d,s,n)	NCURSES_VOID strcat((d),(s))
67*32bb5217SDaniel Fojt #define _nc_STRNCAT(d,s,m,n)	NCURSES_VOID strncat((d),(s),(n))
683468e90cSJohn Marino #endif
693468e90cSJohn Marino 
703468e90cSJohn Marino #if USE_STRING_HACKS && HAVE_STRLCPY
713468e90cSJohn Marino #define _nc_STRCPY(d,s,n)	NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
72*32bb5217SDaniel Fojt #define _nc_STRNCPY(d,s,n)	NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
733468e90cSJohn Marino #else
743468e90cSJohn Marino #define _nc_STRCPY(d,s,n)	NCURSES_VOID strcpy((d),(s))
75*32bb5217SDaniel Fojt #define _nc_STRNCPY(d,s,n)	NCURSES_VOID strncpy((d),(s),(n))
763468e90cSJohn Marino #endif
773468e90cSJohn Marino 
783468e90cSJohn Marino #if USE_STRING_HACKS && HAVE_SNPRINTF
793468e90cSJohn Marino #define _nc_SPRINTF             NCURSES_VOID snprintf
803468e90cSJohn Marino #define _nc_SLIMIT(n)           NCURSES_CAST(size_t,n),
813468e90cSJohn Marino #else
823468e90cSJohn Marino #define _nc_SPRINTF             NCURSES_VOID sprintf
833468e90cSJohn Marino #define _nc_SLIMIT(n)		/* nothing */
843468e90cSJohn Marino #endif
853468e90cSJohn Marino 
863468e90cSJohn Marino #endif /* STRING_HACKS_H */
87