summaryrefslogtreecommitdiff
path: root/lib/util/util_str_common.c
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2011-04-08 12:02:40 +1000
committerAndrew Tridgell <tridge@samba.org>2011-04-13 14:47:07 +1000
commit2eea91957c90d6a5960b5350d2c4664812260a7b (patch)
tree792b34f76b72f3b7e0ade24b5f0b03bae30bb4f9 /lib/util/util_str_common.c
parent9941dfe9f6532ecbc317685046d74e6f90c41695 (diff)
downloadsamba-2eea91957c90d6a5960b5350d2c4664812260a7b.tar.gz
samba-2eea91957c90d6a5960b5350d2c4664812260a7b.tar.bz2
samba-2eea91957c90d6a5960b5350d2c4664812260a7b.zip
lib/util Move simple string routines into common code.
Signed-off-by: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'lib/util/util_str_common.c')
-rw-r--r--lib/util/util_str_common.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/util/util_str_common.c b/lib/util/util_str_common.c
new file mode 100644
index 0000000000..e003d73d74
--- /dev/null
+++ b/lib/util/util_str_common.c
@@ -0,0 +1,54 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+
+ Copyright (C) Andrew Tridgell 1992-2001
+ Copyright (C) Simo Sorce 2001-2002
+ Copyright (C) Martin Pool 2003
+ Copyright (C) James Peach 2005
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/**
+Do a case-insensitive, whitespace-ignoring string compare.
+**/
+_PUBLIC_ int strwicmp(const char *psz1, const char *psz2)
+{
+ /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
+ /* appropriate value. */
+ if (psz1 == psz2)
+ return (0);
+ else if (psz1 == NULL)
+ return (-1);
+ else if (psz2 == NULL)
+ return (1);
+
+ /* sync the strings on first non-whitespace */
+ while (1) {
+ while (isspace((int)*psz1))
+ psz1++;
+ while (isspace((int)*psz2))
+ psz2++;
+ if (toupper_ascii((unsigned char)*psz1) != toupper_ascii((unsigned char)*psz2)
+ || *psz1 == '\0'
+ || *psz2 == '\0')
+ break;
+ psz1++;
+ psz2++;
+ }
+ return (*psz1 - *psz2);
+}