projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
092982d
)
Add second wrapper ssnprintf2 to allow introduction of error handling on truncation...
author
Zebity Spring
<zebity@yahoo.com>
Wed, 18 Sep 2019 11:49:34 +0000
(21:49 +1000)
committer
Zebity Spring
<zebity@yahoo.com>
Wed, 18 Sep 2019 11:49:34 +0000
(21:49 +1000)
src/utils/common/common.c
patch
|
blob
|
history
diff --git
a/src/utils/common/common.c
b/src/utils/common/common.c
index
6a0ac28
..
2711c9d
100644
(file)
--- a/
src/utils/common/common.c
+++ b/
src/utils/common/common.c
@@
-89,8
+89,7
@@
char *sstrncpy(char *dest, const char *src, size_t n) {
return dest;
} /* char *sstrncpy */
return dest;
} /* char *sstrncpy */
-/* ssnprintf returns zero on success, one if truncation occurred
- and a negative integer onerror. */
+/* ssnprintf returns result from vsnprintf conistent with snprintf */
int ssnprintf(char *str, size_t sz, const char *format, ...) {
va_list ap;
va_start(ap, format);
int ssnprintf(char *str, size_t sz, const char *format, ...) {
va_list ap;
va_start(ap, format);
@@
-102,6
+101,22
@@
int ssnprintf(char *str, size_t sz, const char *format, ...) {
return ret;
} /* int ssnprintf */
return ret;
} /* int ssnprintf */
+/* ssnprintf2 returns zero on success, one if truncation occurred
+ and a negative integer on error. */
+int ssnprintf2(char *str, size_t sz, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+
+ int ret = vsnprintf(str, sz, format, ap);
+
+ va_end(ap);
+
+ if (ret < 0) {
+ return ret;
+ }
+ return (size_t)ret >= sz;
+} /* int ssnprintf2 */
+
char *ssnprintf_alloc(char const *format, ...) /* {{{ */
{
char static_buffer[1024] = "";
char *ssnprintf_alloc(char const *format, ...) /* {{{ */
{
char static_buffer[1024] = "";