Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020,2021 Thomas E. Dickey * |
| 3 | * Copyright 2012-2013,2016 Free Software Foundation, Inc. * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 39 | #if HAVE_BSD_STRING_H |
| 40 | #include <bsd/string.h> |
| 41 | #endif |
| 42 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 43 | /* |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 44 | * $Id: nc_string.h,v 1.9 2021/04/25 00:10:43 tom Exp $ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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)) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 64 | #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 65 | #else |
| 66 | #define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s)) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 67 | #define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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)) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 72 | #define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 73 | #else |
| 74 | #define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s)) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 75 | #define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 76 | #endif |
| 77 | |
| 78 | #if USE_STRING_HACKS && HAVE_SNPRINTF |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 79 | #ifdef __cplusplus |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 80 | #define _nc_SPRINTF NCURSES_VOID snprintf |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 81 | #else |
| 82 | #define _nc_SPRINTF NCURSES_VOID (snprintf) |
| 83 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 84 | #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 */ |