summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-04-14 15:48:00 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-04-14 09:21:59 +0200
commite1078b87ded65bd7af8401597ae017b90bdf3ce0 (patch)
tree3d06711f5ae0514b40b9398b6c84db9fcd6ecbe4 /lib
parentbbeba18b1ce2cae4a7fcdf040c168f89ce118861 (diff)
downloadsamba-e1078b87ded65bd7af8401597ae017b90bdf3ce0.tar.gz
samba-e1078b87ded65bd7af8401597ae017b90bdf3ce0.tar.xz
samba-e1078b87ded65bd7af8401597ae017b90bdf3ce0.zip
lib/util Move alpha_strcpy() from s3 into common code
Autobuild-User: Andrew Bartlett <abartlet@samba.org> Autobuild-Date: Thu Apr 14 09:21:59 CEST 2011 on sn-devel-104
Diffstat (limited to 'lib')
-rw-r--r--lib/util/charset/util_unistr.c46
-rw-r--r--lib/util/util_str_common.c51
2 files changed, 51 insertions, 46 deletions
diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c
index ddb15f88f93..a1be501c7ce 100644
--- a/lib/util/charset/util_unistr.c
+++ b/lib/util/charset/util_unistr.c
@@ -39,52 +39,6 @@ _PUBLIC_ void string_replace_m(char *s, char oldc, char newc)
}
/**
- Paranoid strcpy into a buffer of given length (includes terminating
- zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
- and replaces with '_'. Deliberately does *NOT* check for multibyte
- characters. Don't change it !
-**/
-
-_PUBLIC_ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
-{
- size_t len, i;
-
- if (maxlength == 0) {
- /* can't fit any bytes at all! */
- return NULL;
- }
-
- if (!dest) {
- DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
- return NULL;
- }
-
- if (!src) {
- *dest = 0;
- return dest;
- }
-
- len = strlen(src);
- if (len >= maxlength)
- len = maxlength - 1;
-
- if (!other_safe_chars)
- other_safe_chars = "";
-
- for(i = 0; i < len; i++) {
- int val = (src[i] & 0xff);
- if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val))
- dest[i] = src[i];
- else
- dest[i] = '_';
- }
-
- dest[i] = '\0';
-
- return dest;
-}
-
-/**
Convert a string to lower case, allocated with talloc
**/
_PUBLIC_ char *strlower_talloc_handle(struct smb_iconv_handle *iconv_handle,
diff --git a/lib/util/util_str_common.c b/lib/util/util_str_common.c
index e6671be8ad4..fe78d65020b 100644
--- a/lib/util/util_str_common.c
+++ b/lib/util/util_str_common.c
@@ -102,3 +102,54 @@ void string_replace( char *s, char oldc, char newc )
p += c_size;
}
}
+
+
+/**
+ Paranoid strcpy into a buffer of given length (includes terminating
+ zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
+ and replaces with '_'. Deliberately does *NOT* check for multibyte
+ characters. Treats src as an array of bytes, not as a multibyte
+ string. Any byte >0x7f is automatically converted to '_'.
+ other_safe_chars must also contain an ascii string (bytes<0x7f).
+**/
+
+char *alpha_strcpy(char *dest,
+ const char *src,
+ const char *other_safe_chars,
+ size_t maxlength)
+{
+ size_t len, i;
+
+ if (!dest) {
+ smb_panic("ERROR: NULL dest in alpha_strcpy");
+ }
+
+ if (!src) {
+ *dest = 0;
+ return dest;
+ }
+
+ len = strlen(src);
+ if (len >= maxlength)
+ len = maxlength - 1;
+
+ if (!other_safe_chars)
+ other_safe_chars = "";
+
+ for(i = 0; i < len; i++) {
+ int val = (src[i] & 0xff);
+ if (val > 0x7f) {
+ dest[i] = '_';
+ continue;
+ }
+ if (isupper(val) || islower(val) ||
+ isdigit(val) || strchr(other_safe_chars, val))
+ dest[i] = src[i];
+ else
+ dest[i] = '_';
+ }
+
+ dest[i] = '\0';
+
+ return dest;
+}