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