summaryrefslogtreecommitdiffstats
path: root/src/utils.c
Commit message (Collapse)AuthorAgeFilesLines
* doc: fix doxygen 'utils' group closing braceNeels Hofmeyr2017-01-181-1/+2
| | | | | | | osmo_strlcpy() was excluded from the group because the closing brace was above it. Change-Id: I6701261f5854342ac4cd4f2da62e49eb40362938
* doc: clarify osmo_strlcpy() docNeels Hofmeyr2017-01-151-5/+5
| | | | | | | Stating that it 'truncates src' is misleading. Also clarify whether siz includes the space needed for the terminating NUL. Change-Id: I01c1a94408b471f7f54576178a60938bf9ee3261
* doc: fix typo for osmo_hexparseNeels Hofmeyr2016-12-211-1/+1
| | | | Change-Id: Ifc2b499792fda378c807c678b8e06630cb64d273
* Introduce osmo_strlcpy() function so we can stop using strncpy()Harald Welte2016-11-261-0/+22
| | | | | | | | | | | | | | | | I'm aware of the existing criticism on stlrcpy(), but I think it is still better than what we have now: stnrcpy(), sometimes with Coverity warnings and sometimes with a manual setting of the termination byte. The implementation follows the linux kernel strlcpy() which is claimed to be BSD compatible. We could of course link against libbsd on Linux instead, but I think it's reasonably small and simple to provide our own implementation. Future versions of libosmocore could use some autoconf magic and preprocessor macros to use the system-provided strlcpy() if it exists. Change-Id: Ifdc99b0e3b8631f1e771e58acaf9efb00a9cd493
* add get_value_string_or_null() to handle unknown itemsNeels Hofmeyr2016-06-131-3/+18
| | | | | | | | | | | | | | | | | Add get_value_string_or_null() to return NULL in case the given value is not found in the list of strings, to be able to cleanly fall back to another list of strings. Absorb the lookup loop from get_value_string(). Context: in osmo-bts, I want to look up an RSL message name in rsl_msgt_names and fall back to rsl_ipac_msgt_names if not found, because the IPAC PDCH ACT and DEACT messages are sent in a standard ABIS_RSL_MDISC_DED_CHAN. In a subsequent commit, get_value_string_or_null() will be used by new rsl_or_ipac_msg_name(). Change-Id: I1fa3907e28d528d2758bc3eae9d19e6c1168f5e5 Reviewed-on: https://gerrit.osmocom.org/230 Reviewed-by: Harald Welte <laforge@gnumonks.org> Tested-by: Jenkins Builder
* api doc: get_value_string(): mention composition in static bufferNeels Hofmeyr2016-06-131-0/+4
| | | | | | | Change-Id: I93dad98711ef69f8a1e196efa029a842a1ff5bd6 Reviewed-on: https://gerrit.osmocom.org/229 Reviewed-by: Harald Welte <laforge@gnumonks.org> Tested-by: Jenkins Builder
* Import osmo_{encode,decode}_big_endian() from openbscHarald Welte2016-05-051-0/+62
|
* utils: add 'returns' doc to osmo_hexparse().Neels Hofmeyr2015-09-231-0/+1
|
* utils: Disable the weak symbol for darwinHolger Hans Peter Freyther2015-04-111-1/+5
| | | | | | | | We should consider simply removing the alias as we have had several ABI changes since introducint the alias utils.c:223:23: error: only weak aliases are supported on darwin __attribute__((weak, alias("osmo_hexdump_nospc")));
* add missing copyright statements to source code filesHarald Welte2014-09-111-0/+23
| | | | | | Some source code files didn't have the usual copyright and licence statement at their top. I'm adding them baesed on information in the commitlog.
* utils: Greatly improve performance of osmo_hexdump routinesNils O. SelÄsdal2014-01-021-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | In the osmo-bts and libosmo-abis code the hexdump routine is used for every incoming/outgoing packet (including voice frames) and the usage of snprintf showed up inside profiles. There is a semantic change when more than 4096 characters are used. The code will now truncate at byte boundaries (and not nibbles). Code: static const int lengths[] = { 23, 1000, 52 }; char buf[4096]; int i; for (i = 0; i < 30000; ++i) char *res = osmo_hexdump(buf, lengths[i & 3]); Results: before: after: real 0m3.233s real 0m0.085s user 0m3.212s user 0m0.084s sys 0m0.000s sys 0m0.000s
* get_value_string: Null terminate after the call to snprintfHolger Hans Peter Freyther2013-07-041-0/+1
| | | | | | | It is impossible that the snprintf will fill the entire namebuf but just follow the idiom to make sure it is null terminated. Related: Coverity CID 1040676
* add some missing doxygen annotation for libosmocore functionsHarald Welte2013-01-111-1/+9
|
* doc: Fix the Doxygen section endingsSylvain Munaut2012-04-181-1/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* utils: Fix alias to weak alias to allow OSX compilationSylvain Munaut2011-11-191-1/+1
| | | | | | Using a weak alias works just as good AFAICT. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* core/utils: Add a symbol alias for a previous typo for compatibilitySylvain Munaut2011-11-111-0/+4
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* utils: Fix a bad double osmo_ prefix for osmo_hexdump_nospcSylvain Munaut2011-11-101-1/+1
| | | | | | Hopefully no project where using them it seems Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* doxygen: add doxygen module 'utils'Harald Welte2011-08-171-0/+51
|
* osmo_hexdump: Fix segfault when input is too long.Holger Hans Peter Freyther2011-07-151-0/+2
| | | | | | | | | | In snprinftf the size is a size_t (unsigned) in case we want to write more than we have available, len_remain will be < 0. This was spotted while removing hexdump from simtrace and comparing it to our implementation. int snprintf(char *str, size_t size, const char *format, ...);
* utils: use namespace prefix osmo_*Pablo Neira Ayuso2011-05-071-9/+9
| | | | | | | | | | | | Summary of changes: s/bcd2char/osmo_bcd2char/g s/char2bcd/osmo_char2bcd/g s/hexparse/osmo_hexparse/g s/hexdump/osmo_hexdump/g s/hexdump_nospc/osmo_hexdump_nospc/g s/ubit_dump/osmo_ubit_dump/g s/static_assert/osmo_static_assert/g
* include: reorganize headers file to include/osmocom/[gsm|core]Pablo Neira Ayuso2011-03-231-1/+1
| | | | | | | | | | | | This patch moves all GSM-specific definitions to include/osmocom/gsm. Moreover, the headers in include/osmocore/ have been moved to include/osmocom/core. This has been proposed by Harald Welte and Sylvain Munaunt. Tested with `make distcheck'. Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
* LOGGING: configure logging from the vtyHarald Welte2011-02-181-0/+22
| | | | | We can now configure logging to (multiple) files, stderr and syslog from the vty command line in a persistent way (config file)
* [utils] introduce ubit_dump to dump buffers of unpacked bitsHarald Welte2011-02-081-1/+1
|
* [utils] add 'bitdump' function for bitfieldsHarald Welte2011-02-081-0/+30
|
* utils: Fix typo. It is ascii.Holger Hans Peter Freyther2010-11-191-1/+1
|
* add new hexdump_nospc() functionHarald Welte2010-07-301-2/+12
|
* move hexdump() from logging.c to utils.cHarald Welte2010-07-301-0/+19
|
* Import 'hexparse' function from OpenBSCHarald Welte2010-07-301-0/+27
|
* get_value_string(): return "unknown 0x..." instead of "unknown"Harald Welte2010-03-251-1/+5
|
* import bcd2char() and char2bcd() from OpenBSCHarald Welte2010-03-041-0/+14
|
* Import value_string utilities and some RSL stuff from OpenBSCHarald Welte2010-03-011-0/+32