xref: /freebsd/contrib/ncurses/include/nc_string.h (revision 73f0a83d68863a383fd8953972cd36eb6420ec7d)
1*73f0a83dSXin LI /****************************************************************************
2*73f0a83dSXin LI  * Copyright (c) 2012,2013 Free Software Foundation, Inc.                   *
3*73f0a83dSXin LI  *                                                                          *
4*73f0a83dSXin LI  * Permission is hereby granted, free of charge, to any person obtaining a  *
5*73f0a83dSXin LI  * copy of this software and associated documentation files (the            *
6*73f0a83dSXin LI  * "Software"), to deal in the Software without restriction, including      *
7*73f0a83dSXin LI  * without limitation the rights to use, copy, modify, merge, publish,      *
8*73f0a83dSXin LI  * distribute, distribute with modifications, sublicense, and/or sell       *
9*73f0a83dSXin LI  * copies of the Software, and to permit persons to whom the Software is    *
10*73f0a83dSXin LI  * furnished to do so, subject to the following conditions:                 *
11*73f0a83dSXin LI  *                                                                          *
12*73f0a83dSXin LI  * The above copyright notice and this permission notice shall be included  *
13*73f0a83dSXin LI  * in all copies or substantial portions of the Software.                   *
14*73f0a83dSXin LI  *                                                                          *
15*73f0a83dSXin LI  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16*73f0a83dSXin LI  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17*73f0a83dSXin LI  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18*73f0a83dSXin LI  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19*73f0a83dSXin LI  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20*73f0a83dSXin LI  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21*73f0a83dSXin LI  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22*73f0a83dSXin LI  *                                                                          *
23*73f0a83dSXin LI  * Except as contained in this notice, the name(s) of the above copyright   *
24*73f0a83dSXin LI  * holders shall not be used in advertising or otherwise to promote the     *
25*73f0a83dSXin LI  * sale, use or other dealings in this Software without prior written       *
26*73f0a83dSXin LI  * authorization.                                                           *
27*73f0a83dSXin LI  ****************************************************************************/
28*73f0a83dSXin LI 
29*73f0a83dSXin LI /****************************************************************************
30*73f0a83dSXin LI  *  Author: Thomas E. Dickey                        2012                    *
31*73f0a83dSXin LI  ****************************************************************************/
32*73f0a83dSXin LI 
33*73f0a83dSXin LI #ifndef STRING_HACKS_H
34*73f0a83dSXin LI #define STRING_HACKS_H 1
35*73f0a83dSXin LI 
36*73f0a83dSXin LI #include <ncurses_cfg.h>
37*73f0a83dSXin LI 
38*73f0a83dSXin LI /*
39*73f0a83dSXin LI  * $Id: nc_string.h,v 1.4 2013/12/15 01:09:19 tom Exp $
40*73f0a83dSXin LI  *
41*73f0a83dSXin LI  * String-hacks.  Use these macros to stifle warnings on (presumably) correct
42*73f0a83dSXin LI  * uses of strcat, strcpy and sprintf.
43*73f0a83dSXin LI  *
44*73f0a83dSXin LI  * By the way -
45*73f0a83dSXin LI  * A fundamental limitation of the interfaces (and frequent issue in bug
46*73f0a83dSXin LI  * reports using these functions) is that sizes are passed as unsigned values
47*73f0a83dSXin LI  * (with associated sign-extension problems), limiting their effectiveness
48*73f0a83dSXin LI  * when checking for buffer overflow.
49*73f0a83dSXin LI  */
50*73f0a83dSXin LI 
51*73f0a83dSXin LI #ifdef __cplusplus
52*73f0a83dSXin LI #define NCURSES_VOID		/* nothing */
53*73f0a83dSXin LI #else
54*73f0a83dSXin LI #define NCURSES_VOID (void)
55*73f0a83dSXin LI #endif
56*73f0a83dSXin LI 
57*73f0a83dSXin LI #if USE_STRING_HACKS && HAVE_STRLCAT
58*73f0a83dSXin LI #define _nc_STRCAT(d,s,n)	NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
59*73f0a83dSXin LI #else
60*73f0a83dSXin LI #define _nc_STRCAT(d,s,n)	NCURSES_VOID strcat((d),(s))
61*73f0a83dSXin LI #endif
62*73f0a83dSXin LI 
63*73f0a83dSXin LI #if USE_STRING_HACKS && HAVE_STRLCPY
64*73f0a83dSXin LI #define _nc_STRCPY(d,s,n)	NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
65*73f0a83dSXin LI #else
66*73f0a83dSXin LI #define _nc_STRCPY(d,s,n)	NCURSES_VOID strcpy((d),(s))
67*73f0a83dSXin LI #endif
68*73f0a83dSXin LI 
69*73f0a83dSXin LI #if USE_STRING_HACKS && HAVE_SNPRINTF
70*73f0a83dSXin LI #define _nc_SPRINTF             NCURSES_VOID snprintf
71*73f0a83dSXin LI #define _nc_SLIMIT(n)           NCURSES_CAST(size_t,n),
72*73f0a83dSXin LI #else
73*73f0a83dSXin LI #define _nc_SPRINTF             NCURSES_VOID sprintf
74*73f0a83dSXin LI #define _nc_SLIMIT(n)		/* nothing */
75*73f0a83dSXin LI #endif
76*73f0a83dSXin LI 
77*73f0a83dSXin LI #endif /* STRING_HACKS_H */
78