Module: kamailio
Branch: master
Commit: c2ded549b235db9ce5e90b9cc71bf8e4a86b27b3
URL: 
https://github.com/kamailio/kamailio/commit/c2ded549b235db9ce5e90b9cc71bf8e4a86b27b3

Author: Victor Seva <[email protected]>
Committer: Victor Seva <[email protected]>
Date: 2025-09-24T11:39:58+02:00

core: [str] STR_FMT_VAL macro

same as STR_FMT macro but will use a default value if str is empty

---

Modified: src/core/str.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/c2ded549b235db9ce5e90b9cc71bf8e4a86b27b3.diff
Patch: 
https://github.com/kamailio/kamailio/commit/c2ded549b235db9ce5e90b9cc71bf8e4a86b27b3.patch

---

diff --git a/src/core/str.h b/src/core/str.h
index f02dc4e32e4..adc60c129eb 100644
--- a/src/core/str.h
+++ b/src/core/str.h
@@ -83,10 +83,7 @@ typedef struct _str str;
  * @param v is a string literal
  * @sa STR_NULL
  */
-#define STR_STATIC_INIT(v) \
-       {                      \
-               (v), sizeof(v) - 1 \
-       }
+#define STR_STATIC_INIT(v) {(v), sizeof(v) - 1}
 
 /* kamailio compatibility macro (same thing as above) */
 #define str_init(v) STR_STATIC_INIT(v)
@@ -97,10 +94,7 @@ typedef struct _str str;
  * \code str var = STR_NULL; \endcode
  * @sa STR_STATIC_INIT
  */
-#define STR_NULL \
-       {            \
-               0, 0     \
-       }
+#define STR_NULL {0, 0}
 
 /** Formats ::str string for use in printf-like functions.
  * This is a macro that prepares a ::str string for use in functions which
@@ -116,6 +110,13 @@ typedef struct _str str;
        ((_pstr_ != (str *)0) ? (_pstr_)->len : 0), \
                        ((_pstr_ != (str *)0) ? (_pstr_)->s : "")
 
+/** Formats ::str string for use in printf-like functions with default value.
+ * Same as STR_FMT but will use v if str is empty
+ */
+#define STR_FMT_VAL(_pstr_, v)                  \
+       ((_pstr_ != (str *)0) ? (_pstr_)->len : 0), \
+                       ((_pstr_ != (str *)0) ? (_pstr_)->s : v)
+
 
 /** Compares two ::str strings.
  * This macro implements comparison of two strings represented using ::str

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to