[or-cvs] Add casei versions of strcmpstart/strcmpend
Nick Mathewson
nickm at seul.org
Tue Nov 30 03:10:58 UTC 2004
Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv22660/src/common
Modified Files:
util.c util.h
Log Message:
Add casei versions of strcmpstart/strcmpend
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- util.c 29 Nov 2004 22:25:29 -0000 1.189
+++ util.c 30 Nov 2004 03:10:56 -0000 1.190
@@ -289,6 +289,15 @@
return strncmp(s1, s2, n);
}
+/* Compares the first strlen(s2) characters of s1 with s2. Returns as for
+ * strcasecmp.
+ */
+int strcasecmpstart(const char *s1, const char *s2)
+{
+ size_t n = strlen(s2);
+ return strncasecmp(s1, s2, n);
+}
+
/* Compares the last strlen(s2) characters of s1 with s2. Returns as for
* strcmp.
*/
@@ -301,6 +310,18 @@
return strncmp(s1+(n1-n2), s2, n2);
}
+/* Compares the last strlen(s2) characters of s1 with s2. Returns as for
+ * strcasecmp.
+ */
+int strcasecmpend(const char *s1, const char *s2)
+{
+ size_t n1 = strlen(s1), n2 = strlen(s2);
+ if (n2>n1)
+ return strcasecmp(s1,s2);
+ else
+ return strncasecmp(s1+(n1-n2), s2, n2);
+}
+
/** Return a pointer to the first char of s that is not whitespace and
* not a comment, or to the terminating NUL if no such character exists.
*/
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- util.h 29 Nov 2004 22:25:29 -0000 1.123
+++ util.h 30 Nov 2004 03:10:56 -0000 1.124
@@ -56,7 +56,9 @@
#define HEX_CHARACTERS "0123456789ABCDEFabcdef"
void tor_strlower(char *s);
int strcmpstart(const char *s1, const char *s2);
+int strcasecmpstart(const char *s1, const char *s2);
int strcmpend(const char *s1, const char *s2);
+int strcasecmpend(const char *s1, const char *s2);
int tor_strstrip(char *s, const char *strip);
typedef enum {
ALWAYS_TERMINATE, NEVER_TERMINATE, TERMINATE_IF_EVEN
More information about the tor-commits
mailing list