From: Pablo Neira Ayuso pablo@gnumonks.org
This patch adds bitvec_find_bit_pos() to bitvec.c where it really belongs to. Before this patch used to be part of gsm/rxlev_stat.c --- include/osmocom/core/bitvec.h | 2 ++ src/bitvec.c | 14 ++++++++++++++ src/gsm/rxlev_stat.c | 12 ------------ 3 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/include/osmocom/core/bitvec.h b/include/osmocom/core/bitvec.h index 42977fb..bbe1641 100644 --- a/include/osmocom/core/bitvec.h +++ b/include/osmocom/core/bitvec.h @@ -68,6 +68,8 @@ int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count); /* get multiple bits (based on numeric value) from current pos */ int bitvec_get_uint(struct bitvec *bv, int num_bits);
+/* find the first bit set in bit vector */ +int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
/* Pad the bit vector up to a certain bit position */ int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit); diff --git a/src/bitvec.c b/src/bitvec.c index 4984af2..4fd3834 100644 --- a/src/bitvec.c +++ b/src/bitvec.c @@ -217,3 +217,17 @@ int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit)
return 0; } + +/* find first bit set in bit vector */ +int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, + enum bit_value val) +{ + unsigned int i; + + for (i = n; i < bv->data_len*8; i++) { + if (bitvec_get_bit_pos(bv, i) == val) + return i; + } + + return -1; +} diff --git a/src/gsm/rxlev_stat.c b/src/gsm/rxlev_stat.c index 626aaff..d226861 100644 --- a/src/gsm/rxlev_stat.c +++ b/src/gsm/rxlev_stat.c @@ -30,18 +30,6 @@ #include <osmocom/core/bitvec.h> #include <osmocom/gsm/rxlev_stat.h>
-int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val) -{ - unsigned int i; - - for (i = n; i < bv->data_len*8; i++) { - if (bitvec_get_bit_pos(bv, i) == val) - return i; - } - - return -1; -} - void rxlev_stat_input(struct rxlev_stats *st, uint16_t arfcn, uint8_t rxlev) { struct bitvec bv;
From: Pablo Neira Ayuso pablo@gnumonks.org
--- include/osmocom/core/write_queue.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/osmocom/core/write_queue.h b/include/osmocom/core/write_queue.h index ef244c3..3b730c7 100644 --- a/include/osmocom/core/write_queue.h +++ b/include/osmocom/core/write_queue.h @@ -23,8 +23,8 @@ #ifndef write_queue_h #define write_queue_h
-#include "select.h" -#include "msgb.h" +#include <osmocom/core/select.h> +#include <osmocom/core/msgb.h>
struct write_queue { struct bsc_fd bfd;
From: Pablo Neira Ayuso pablo@gnumonks.org
Before this patch, it was in osmocom/core/rate_ctr.h --- include/osmocom/core/rate_ctr.h | 3 --- include/osmocom/vty/Makefile.am | 2 +- include/osmocom/vty/misc.h | 10 ++++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 include/osmocom/vty/misc.h
diff --git a/include/osmocom/core/rate_ctr.h b/include/osmocom/core/rate_ctr.h index dba573d..9efc23d 100644 --- a/include/osmocom/core/rate_ctr.h +++ b/include/osmocom/core/rate_ctr.h @@ -75,7 +75,4 @@ static inline void rate_ctr_inc(struct rate_ctr *ctr) /* Initialize the counter module */ int rate_ctr_init(void *tall_ctx);
-struct vty; -void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, - struct rate_ctr_group *ctrg); #endif /* RATE_CTR_H */ diff --git a/include/osmocom/vty/Makefile.am b/include/osmocom/vty/Makefile.am index d2f0616..83d0010 100644 --- a/include/osmocom/vty/Makefile.am +++ b/include/osmocom/vty/Makefile.am @@ -1,4 +1,4 @@ osmovty_HEADERS = buffer.h command.h vector.h vty.h \ - telnet_interface.h logging.h + telnet_interface.h logging.h misc.h
osmovtydir = $(includedir)/osmocom/vty diff --git a/include/osmocom/vty/misc.h b/include/osmocom/vty/misc.h new file mode 100644 index 0000000..707f82f --- /dev/null +++ b/include/osmocom/vty/misc.h @@ -0,0 +1,10 @@ +#ifndef OSMO_VTY_MISC_H +#define OSMO_VTY_MISC_H + +#include <osmocom/vty/vty.h> +#include <osmocom/core/rate_ctr.h> + +void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, + struct rate_ctr_group *ctrg); + +#endif
From: Pablo Neira Ayuso pablo@gnumonks.org
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(). --- include/osmocom/core/utils.h | 9 +++++++++ src/logging.c | 26 ++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 0cdf03b..252228d 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -27,4 +27,13 @@ char *ubit_dump(const uint8_t *bits, unsigned int len); void osmo_str2lower(char *out, const char *in); void osmo_str2upper(char *out, const char *in);
+#define OSMO_SNPRINTF_RET(ret, rem, offset, len) \ +do { \ + len += ret; \ + if (ret > rem) \ + ret = rem; \ + offset += ret; \ + rem -= ret; \ +} while (0) + #endif diff --git a/src/logging.c b/src/logging.c index 653c80d..2c24f2f 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;