]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add casei versions of strcmpstart/strcmpend
authorNick Mathewson <nickm@torproject.org>
Tue, 30 Nov 2004 03:10:56 +0000 (03:10 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 30 Nov 2004 03:10:56 +0000 (03:10 +0000)
svn:r3026

src/common/util.c
src/common/util.h

index f007188e34042468f2e8d742b3ee63d8d1e487cb..efc320215d95818957fda83b025595018250f28d 100644 (file)
@@ -289,6 +289,15 @@ int strcmpstart(const char *s1, const char *s2)
   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 @@ int strcmpend(const char *s1, const char *s2)
     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 5b08fc855f147824a24e64713537d6a03194ba72..9fe7262aabdfbf7194e45fd19478de6619eacd7f 100644 (file)
@@ -56,7 +56,9 @@ char *tor_strndup(const char *s, size_t n);
 #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