blob: 546aa0695ba0279c80dc57270a0905389cfa8526 [file] [log] [blame]
Steve Kondikae271bc2015-11-15 02:50:53 +01001/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 2012-2013,2016 Free Software Foundation, Inc. *
Steve Kondikae271bc2015-11-15 02:50:53 +01004 * *
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
micky3879b9f5e72025-07-08 18:04:53 -040039#if HAVE_BSD_STRING_H
40#include <bsd/string.h>
41#endif
42
Steve Kondikae271bc2015-11-15 02:50:53 +010043/*
micky3879b9f5e72025-07-08 18:04:53 -040044 * $Id: nc_string.h,v 1.9 2021/04/25 00:10:43 tom Exp $
Steve Kondikae271bc2015-11-15 02:50:53 +010045 *
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))
micky3879b9f5e72025-07-08 18:04:53 -040064#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
Steve Kondikae271bc2015-11-15 02:50:53 +010065#else
66#define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
micky3879b9f5e72025-07-08 18:04:53 -040067#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
Steve Kondikae271bc2015-11-15 02:50:53 +010068#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))
micky3879b9f5e72025-07-08 18:04:53 -040072#define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
Steve Kondikae271bc2015-11-15 02:50:53 +010073#else
74#define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
micky3879b9f5e72025-07-08 18:04:53 -040075#define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
Steve Kondikae271bc2015-11-15 02:50:53 +010076#endif
77
78#if USE_STRING_HACKS && HAVE_SNPRINTF
micky3879b9f5e72025-07-08 18:04:53 -040079#ifdef __cplusplus
Steve Kondikae271bc2015-11-15 02:50:53 +010080#define _nc_SPRINTF NCURSES_VOID snprintf
micky3879b9f5e72025-07-08 18:04:53 -040081#else
82#define _nc_SPRINTF NCURSES_VOID (snprintf)
83#endif
Steve Kondikae271bc2015-11-15 02:50:53 +010084#define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
85#else
86#define _nc_SPRINTF NCURSES_VOID sprintf
87#define _nc_SLIMIT(n) /* nothing */
88#endif
89
90#endif /* STRING_HACKS_H */