lib/util/charset Add wrapper to allow testing of strlen_m_ext()
authorAndrew Bartlett <abartlet@samba.org>
Wed, 30 Mar 2011 23:27:41 +0000 (10:27 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 30 Mar 2011 23:53:24 +0000 (10:53 +1100)
This allows test routines to force in particular character sets, and
not rely on the smb.conf.

Andrew Bartlett

lib/util/charset/charset.h
lib/util/charset/util_str.c

index 7374d6e2ec440d163cabf1c7f03fed2b344f9e22..82396e149857045af919b69e88811709fb8122f3 100644 (file)
@@ -111,6 +111,14 @@ struct smb_iconv_handle;
 #define strupper(s) strupper_m(s)
 
 char *strchr_m(const char *s, char c);
+/**
+ * Calculate the number of units (8 or 16-bit, depending on the
+ * destination charset), that would be needed to convert the input
+ * string which is expected to be in in src_charset encoding to the
+ * destination charset (which should be a unicode charset).
+ */
+size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
+                          const char *s, charset_t src_charset, charset_t dst_charset);
 size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset);
 size_t strlen_m_ext_term(const char *s, charset_t src_charset,
                         charset_t dst_charset);
index ff53b1875ea0022f42875a52483a4c8c73f5b35b..9aaf651589b7971dec7f3ca29658192ab0e31b7f 100644 (file)
@@ -140,10 +140,10 @@ _PUBLIC_ bool strcsequal(const char *s1,const char *s2)
  * string which is expected to be in in src_charset encoding to the
  * destination charset (which should be a unicode charset).
  */
-_PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset)
+_PUBLIC_ size_t strlen_m_ext_handle(struct smb_iconv_handle *ic,
+                                   const char *s, charset_t src_charset, charset_t dst_charset)
 {
        size_t count = 0;
-       struct smb_iconv_handle *ic = get_iconv_handle();
 
        if (!s) {
                return 0;
@@ -203,6 +203,18 @@ _PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst
        return count;
 }
 
+/**
+ * Calculate the number of units (8 or 16-bit, depending on the
+ * destination charset), that would be needed to convert the input
+ * string which is expected to be in in src_charset encoding to the
+ * destination charset (which should be a unicode charset).
+ */
+_PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset)
+{
+       struct smb_iconv_handle *ic = get_iconv_handle();
+       return strlen_m_ext_handle(ic, s, src_charset, dst_charset);
+}
+
 _PUBLIC_ size_t strlen_m_ext_term(const char *s, const charset_t src_charset,
                                  const charset_t dst_charset)
 {