From 06356fd9c3234574bd26d2f123acd334b4275f3c Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Tue, 19 Nov 2019 01:38:10 +0100 Subject: utils: add osmo_strnchr() When finding a char in a string, I want to be able to limit the search area by size, not only by nul terminator. Change-Id: I48f8ace9f51f8a06796648883afcabe3b4e8b537 --- tests/utils/utils_test.ok | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/utils/utils_test.ok') diff --git a/tests/utils/utils_test.ok b/tests/utils/utils_test.ok index d5cf4910..89e0fed4 100644 --- a/tests/utils/utils_test.ok +++ b/tests/utils/utils_test.ok @@ -403,3 +403,11 @@ NULL token_len=10 buf_size=1 -> token="" rc=0 NULL token_len=10 buf_size=0 -> token="unchanged" rc=0 "" token_len=10 buf_size=0 -> token="unchanged" rc=0 "foo=bar" token_len=0 buf_size=0 -> token="unchanged" rc=0 + +osmo_strnchr_test() +osmo_strnchr("foo=bar", 8, '=') -> 3 +osmo_strnchr("foo=bar", 4, '=') -> 3 +osmo_strnchr("foo=bar", 3, '=') -> -1 +osmo_strnchr("foo=bar", 0, '=') -> -1 +osmo_strnchr("foo", 9, '=') -> -1 +osmo_strnchr("foo", 9, '\0') -> 3 -- cgit v1.2.3