diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-09-07 03:01:38 +0200 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-09-07 04:28:39 +0200 |
commit | 7c749893bfcf9f1a117ee6a2d35a6c8f0f05909d (patch) | |
tree | ae4fcbbf59833774221e6f6bf5fb5602b24da7c5 /src/vty/logging_vty.c | |
parent | 03e7553cba06145004748aba597636c5342ef89e (diff) |
add osmo_str_tolower() and _toupper() with test
We already have osmo_str2lower() and osmo_str2upper(), but these lack:
* proper destination buffer bounds checking,
* ability to call directly as printf() argument.
Deprecate osmo_str2upper() and osmo_str2lower() because of missing bounds
checking.
Introduce osmo_str_tolower_buf(), osmo_str_toupper_buf() to provide
bounds-safe conversion, also able to safely convert a buffer in-place.
Introduce osmo_str_tolower(), osmo_str_toupper() that call the above _buf()
equivalents using a static buffer[128] and returning the resulting string
directly, convenient for direct printing. Possibly truncated but always safe.
Add unit tests to utils_test.c.
Replace all libosmocore uses of now deprecated osmo_str2lower().
Naming: the ctype.h API is called tolower() and toupper(), so just prepend
'osmo_str_' and don't separate 'to_lower'.
Change-Id: Ib0ee1206b9f31d7ba25c31f8008119ac55440797
Diffstat (limited to 'src/vty/logging_vty.c')
-rw-r--r-- | src/vty/logging_vty.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index 8c8a3326..7d97bb1d 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -754,7 +754,6 @@ DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd, static int config_write_log_single(struct vty *vty, struct log_target *tgt) { int i; - char level_lower[32]; switch (tgt->type) { case LOG_TGT_TYPE_VTY: @@ -806,21 +805,19 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) VTY_NEWLINE); /* stupid old osmo logging API uses uppercase strings... */ - osmo_str2lower(level_lower, log_level_str(tgt->loglevel)); - vty_out(vty, " logging level all %s%s", level_lower, VTY_NEWLINE); + vty_out(vty, " logging level all %s%s", osmo_str_tolower(log_level_str(tgt->loglevel)), + VTY_NEWLINE); for (i = 0; i < osmo_log_info->num_cat; i++) { const struct log_category *cat = &tgt->categories[i]; - char cat_lower[32]; /* skip empty entries in the array */ if (!osmo_log_info->cat[i].name) continue; /* stupid old osmo logging API uses uppercase strings... */ - osmo_str2lower(cat_lower, osmo_log_info->cat[i].name+1); - osmo_str2lower(level_lower, log_level_str(cat->loglevel)); - vty_out(vty, " logging level %s %s%s", cat_lower, level_lower, VTY_NEWLINE); + vty_out(vty, " logging level %s", osmo_str_tolower(osmo_log_info->cat[i].name+1)); + vty_out(vty, " %s%s", osmo_str_tolower(log_level_str(cat->loglevel)), VTY_NEWLINE); } return 1; |