diff options
author | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-08 19:51:10 +0100 |
---|---|---|
committer | Chris Hall <GMCH@hestia.halldom.com> | 2010-04-08 19:51:10 +0100 |
commit | 83447a051fbcc88b33fcea6670520687668d3ba1 (patch) | |
tree | f3be10368d9fc6c605c1ec351bc7c1f2c0c61ff0 /lib/qfstring.c | |
parent | 17b711e6e4a4d5ce3728a07890434d890ebb76b4 (diff) | |
download | quagga-83447a051fbcc88b33fcea6670520687668d3ba1.tar.bz2 quagga-83447a051fbcc88b33fcea6670520687668d3ba1.tar.xz |
New functions for error numbers and addresses in messages.
Implemented less onerous ways of including descriptions of errors
and IP addresses in logging and other messages.
Implemented mapping of error numbers to error names, which is
generally more meaningful.
Diffstat (limited to 'lib/qfstring.c')
-rw-r--r-- | lib/qfstring.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/qfstring.c b/lib/qfstring.c index 30ee441c..583d729f 100644 --- a/lib/qfstring.c +++ b/lib/qfstring.c @@ -40,10 +40,33 @@ qfs_init(qf_str qfs, char* str, size_t size) { assert(size > 0) ; - qfs->str = qfs->ptr = str ; - qfs->end = qfs->str + size - 1 ; + qfs->str = str ; + qfs->end = str + size - 1 ; *str = '\0' ; + qfs->ptr = str ; +} ; + +/*------------------------------------------------------------------------------ + * Initialise qf_str which already contains string -- to given size (which + * includes the '\n') + * + * This may be used to prepare for appending to a buffer which already contains + * something. + * + * Sets pointers, setting the write pointer to the existing terminating '\n'. + * + * This operation is async-signal-safe. + */ +extern void +qfs_init_as_is(qf_str qfs, char* str, size_t size) +{ + assert(size > 0) ; + + qfs->str = str ; + qfs->end = str + size - 1 ; + + qfs->ptr = strchr(str, '\0') ; } ; /*------------------------------------------------------------------------------ @@ -205,7 +228,7 @@ qfs_append_justified(qf_str qfs, const char* src, int width) extern void qfs_append_justified_n(qf_str qfs, const char* src, size_t n, int width) { - if (n >= abs(width)) + if ((int)n >= abs(width)) width = 0 ; if (width > 0) @@ -861,7 +884,7 @@ qfs_vprintf(qf_str qfs, const char *format, va_list args) } ; /*------------------------------------------------------------------------------ - * %s handler + * %s handler -- tolerates NULL pointer * * Accepts: width * precision @@ -892,7 +915,7 @@ qfs_arg_string(qf_str qfs, va_list args, enum pf_flags flags, if (flags != (flags & pf_precision)) return pfp_failed ; - len = strlen(src) ; + len = (src != NULL) ? strlen(src) : 0 ; if (((precision > 0) || (flags & pf_precision)) && (len > precision)) len = precision ; |