Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-04-05 17:44:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-04-05 17:44:48 +0300
commitf0f6c96a9204419c429c38915d9340d092b570c4 (patch)
treeb11634e1f006d8a4c3e23bcb5dc0687dbab309ce /source/blender/blenlib
parentad1ea9a427e3543a43ca2589f87f0c94b9be03ca (diff)
BLI_string: macros that de-duplicate sizeof arg
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_string.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index d137806c575..48be9d1842f 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -103,6 +103,20 @@ int BLI_string_find_split_words(
const char delim, int r_words[][2], int words_max)
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+/** \name String Copy/Format Macros
+ * Avoid repeating destination with `sizeof(..)`.
+ * \note `ARRAY_SIZE` allows pointers on some platforms.
+ * \{ */
+#define STRNCPY(dst, src) \
+ BLI_strncpy(dst, src, ARRAY_SIZE(dst))
+#define STRNCPY_RLEN(dst, src) \
+ BLI_strncpy_rlen(dst, src, ARRAY_SIZE(dst))
+#define SNPRINTF(dst, format, ...) \
+ BLI_snprintf(dst, ARRAY_SIZE(dst), format, __VA_ARGS__)
+#define SNPRINTF_RLEN(dst, format, ...) \
+ BLI_snprintf_rlen(dst, ARRAY_SIZE(dst), format, __VA_ARGS__)
+/** \} */
+
#ifdef __cplusplus
}
#endif