summaryrefslogtreecommitdiff
path: root/lib/util/util_str.c
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-09-19 13:42:32 +1000
committerVolker Lendecke <vl@samba.org>2014-09-19 20:34:05 +0200
commit6d450b3b48bd51b7e244711e7c6f832e0e27d8ee (patch)
tree476ef73c6fd17806ef308b857d075042206b7b68 /lib/util/util_str.c
parentf3d50e5ff5382868f8e39ab9af07f43bfefd8303 (diff)
downloadsamba-6d450b3b48bd51b7e244711e7c6f832e0e27d8ee.tar.gz
lib/util: Return some functions to util_str.c
These were moved in commit 8e704e4107b284bfc1e43f4c698ac0e6c5ae1800 when util_str.c was not shared. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Sep 19 20:34:05 CEST 2014 on sn-devel-104
Diffstat (limited to 'lib/util/util_str.c')
-rw-r--r--lib/util/util_str.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/util/util_str.c b/lib/util/util_str.c
index 58c9f7860d8..673fbc7c6b5 100644
--- a/lib/util/util_str.c
+++ b/lib/util/util_str.c
@@ -278,3 +278,58 @@ _PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bu
return true;
}
+
+/**
+ Set a boolean variable from the text value stored in the passed string.
+ Returns true in success, false if the passed string does not correctly
+ represent a boolean.
+**/
+
+_PUBLIC_ bool set_boolean(const char *boolean_string, bool *boolean)
+{
+ if (strwicmp(boolean_string, "yes") == 0 ||
+ strwicmp(boolean_string, "true") == 0 ||
+ strwicmp(boolean_string, "on") == 0 ||
+ strwicmp(boolean_string, "1") == 0) {
+ *boolean = true;
+ return true;
+ } else if (strwicmp(boolean_string, "no") == 0 ||
+ strwicmp(boolean_string, "false") == 0 ||
+ strwicmp(boolean_string, "off") == 0 ||
+ strwicmp(boolean_string, "0") == 0) {
+ *boolean = false;
+ return true;
+ }
+ return false;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+**/
+_PUBLIC_ size_t utf16_len(const void *buf)
+{
+ size_t len;
+
+ for (len = 0; SVAL(buf,len); len += 2) ;
+
+ return len + 2;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+limited by 'n' bytes
+**/
+_PUBLIC_ size_t utf16_len_n(const void *src, size_t n)
+{
+ size_t len;
+
+ for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ;
+
+ if (len+2 <= n) {
+ len += 2;
+ }
+
+ return len;
+}