From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 7/8] shared/util: Add strdelimit and strsuffix
Date: Wed, 21 Feb 2018 16:14:55 +0200 [thread overview]
Message-ID: <20180221141456.6656-7-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20180221141456.6656-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
src/shared/util.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/shared/util.h | 3 +++
2 files changed, 48 insertions(+)
diff --git a/src/shared/util.c b/src/shared/util.c
index f6f265e56..986e2b22d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -980,3 +980,48 @@ const char *bt_appear_to_str(uint16_t appearance)
return str;
}
+
+char *strdelimit(char *str, char *del, char c)
+{
+ char *dup;
+
+ if (!str)
+ return NULL;
+
+ dup = strdup(str);
+ if (dup[0] == '\0')
+ return dup;
+
+ while (del[0] != '\0') {
+ char *rep = dup;
+
+ while ((rep = strchr(rep, del[0])))
+ rep[0] = c;
+
+ del++;
+ }
+
+ return dup;
+}
+
+int strsuffix(const char *str, const char *suffix)
+{
+ int len;
+ int suffix_len;
+
+ if (!str || !suffix)
+ return false;
+
+ if (str[0] == '\0' && suffix[0] != '\0')
+ return false;
+
+ if (suffix[0] == '\0' && str[0] != '\0')
+ return false;
+
+ len = strlen(str);
+ suffix_len = strlen(suffix);
+ if (len < suffix_len)
+ return false;
+
+ return strncmp(str + len - suffix_len, suffix, suffix_len);
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 3f5f6dfb5..604dc3be4 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -92,6 +92,9 @@ do { \
#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
#define malloc0(n) (calloc((n), 1))
+char *strdelimit(char *str, char *del, char c);
+int strsuffix(const char *str, const char *suffix);
+
void *btd_malloc(size_t size);
typedef void (*util_debug_func_t)(const char *str, void *user_data);
--
2.14.3
next prev parent reply other threads:[~2018-02-21 14:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 14:14 [PATCH BlueZ 1/8] shared/shell: Add non-interactive mode Luiz Augusto von Dentz
2018-02-21 14:14 ` [PATCH BlueZ 2/8] tools/bluetooth-player: Only enable attach input when connected Luiz Augusto von Dentz
2018-02-21 14:14 ` [PATCH BlueZ 3/8] tools/obexctl: " Luiz Augusto von Dentz
2018-02-21 14:14 ` [PATCH BlueZ 4/8] shared/shell: Set NON_INTERACTIVE env Luiz Augusto von Dentz
2018-02-21 14:14 ` [PATCH BlueZ 5/8] client: Don't auto register agent on non-interactive mode Luiz Augusto von Dentz
2018-02-21 14:14 ` [PATCH BlueZ 6/8] shared/mainloop: Add GLIB wrapper Luiz Augusto von Dentz
2018-02-21 14:14 ` Luiz Augusto von Dentz [this message]
2018-02-21 14:14 ` [PATCH BlueZ 8/8] shared/shell: Use mainloop wrappers instead of GLIB directly Luiz Augusto von Dentz
2018-02-22 9:56 ` [PATCH BlueZ 1/8] shared/shell: Add non-interactive mode Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221141456.6656-7-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).