2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Andrew Tridgell 1992-2001
6 Copyright (C) Simo Sorce 2001-2002
7 Copyright (C) Martin Pool 2003
8 Copyright (C) James Peach 2005
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "system/locale.h"
26 #include "lib/util/samba_util.h"
29 Do a case-insensitive, whitespace-ignoring ASCII string compare.
31 _PUBLIC_
int strwicmp(const char *psz1
, const char *psz2
)
33 /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
34 /* appropriate value. */
37 else if (psz1
== NULL
)
39 else if (psz2
== NULL
)
42 /* sync the strings on first non-whitespace */
44 while (isspace((int)*psz1
))
46 while (isspace((int)*psz2
))
50 * This does not do a genuine multi-byte comparison,
51 * instead it just uses the fast-path for ASCII in
52 * these common routines
54 if (toupper_m((unsigned char)*psz1
) != toupper_m((unsigned char)*psz2
)
61 return (*psz1
- *psz2
);
66 NOTE: oldc and newc must be 7 bit characters
68 void string_replace( char *s
, char oldc
, char newc
)
72 next_codepoint(s
, &c_size
);
85 Paranoid strcpy into a buffer of given length (includes terminating
86 zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars
87 and replaces with '_'. Deliberately does *NOT* check for multibyte
88 characters. Treats src as an array of bytes, not as a multibyte
89 string. Any byte >0x7f is automatically converted to '_'.
90 other_safe_chars must also contain an ascii string (bytes<0x7f).
93 char *alpha_strcpy(char *dest
,
95 const char *other_safe_chars
,
101 smb_panic("ERROR: NULL dest in alpha_strcpy");
110 if (len
>= maxlength
)
113 if (!other_safe_chars
)
114 other_safe_chars
= "";
116 for(i
= 0; i
< len
; i
++) {
117 int val
= (src
[i
] & 0xff);
122 if (isupper(val
) || islower(val
) ||
123 isdigit(val
) || strchr(other_safe_chars
, val
))
134 char *talloc_alpha_strcpy(TALLOC_CTX
*mem_ctx
,
136 const char *other_safe_chars
)
147 dest
= talloc_zero_size(mem_ctx
, slen
+ 1);
152 alpha_strcpy(dest
, src
, other_safe_chars
, slen
+ 1);