summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2011-03-28 19:24:22 +0200
committerHarald Welte <laforge@gnumonks.org>2011-03-28 20:00:45 +0200
commit3abad6a6f9ae4cfa65c9f6d5f15208790449eefe (patch)
tree32b141a3bf38a3b89589d767c795bd2d7837b59e /src
parent70004fcc6dcd5dd979c10143872b2a136371e371 (diff)
utils: move OSMO_SNPRINT_RET() macro definition to osmocom/core/utils.h
This is used by the logging to vty conversion functions by now, but it may be of help for other functions that plan to use snprintf().
Diffstat (limited to 'src')
-rw-r--r--src/logging.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/src/logging.c b/src/logging.c
index 653c80db..2c24f2fb 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -434,16 +434,6 @@ int log_target_file_reopen(struct log_target *target)
return 0;
}
-/* This can go into some header file so others can benefit from it. */
-#define SNPRINTF_FAILURE(ret, rem, offset, len) \
-do { \
- len += ret; \
- if (ret > rem) \
- ret = rem; \
- offset += ret; \
- rem -= ret; \
-} while (0)
-
/* This generates the logging command string for VTY. */
const char *log_vty_command_string(const struct log_info *info)
{
@@ -465,7 +455,7 @@ const char *log_vty_command_string(const struct log_info *info)
ret = snprintf(str + offset, rem, "logging level (");
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
for (i = 0; i < info->num_cat; i++) {
int j, name_len = strlen(info->cat[i].name)+1;
@@ -478,7 +468,7 @@ const char *log_vty_command_string(const struct log_info *info)
ret = snprintf(str + offset, rem, "%s|", name+1);
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
offset--; /* to remove the trailing | */
rem++;
@@ -486,7 +476,7 @@ const char *log_vty_command_string(const struct log_info *info)
ret = snprintf(str + offset, rem, ") (");
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
for (i = 0; i < LOGLEVEL_DEFS; i++) {
int j, loglevel_str_len = strlen(loglevel_strs[i].str)+1;
@@ -499,7 +489,7 @@ const char *log_vty_command_string(const struct log_info *info)
ret = snprintf(str + offset, rem, "%s|", loglevel_str);
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
offset--; /* to remove the trailing | */
rem++;
@@ -507,7 +497,7 @@ const char *log_vty_command_string(const struct log_info *info)
ret = snprintf(str + offset, rem, ")");
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
err:
return str;
}
@@ -536,21 +526,21 @@ const char *log_vty_command_description(const struct log_info *info)
"Set the log level for a specified category\n");
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
for (i = 0; i < info->num_cat; i++) {
ret = snprintf(str + offset, rem, "%s\n",
info->cat[i].description);
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
for (i = 0; i < LOGLEVEL_DEFS; i++) {
ret = snprintf(str + offset, rem, "%s\n",
loglevel_descriptions[i]);
if (ret < 0)
goto err;
- SNPRINTF_FAILURE(ret, rem, offset, len);
+ OSMO_SNPRINTF_RET(ret, rem, offset, len);
}
err:
return str;