Browse code

kamailio compatibility, add str_strcmp and str_casecmp functions

Henning Westerholt authored on 08/12/2008 17:13:57
Showing 2 changed files
... ...
@@ -28,7 +28,7 @@
28 28
  *
29 29
  */
30 30
 
31
-#include <string.h>
31
+
32 32
 #include <sys/types.h>
33 33
 #include <pwd.h>
34 34
 #include <grp.h>
... ...
@@ -56,6 +56,8 @@
56 56
 #include <time.h>
57 57
 #include <unistd.h>
58 58
 #include <ctype.h>
59
+#include <string.h>
60
+#include <strings.h>
59 61
 
60 62
 #include "compiler_opt.h"
61 63
 #include "config.h"
... ...
@@ -633,6 +635,49 @@ static inline int pkg_str_dup(str* dst, const str* src)
633 633
 	return 0;
634 634
 }
635 635
 
636
+/**
637
+ * \brief Compare two str's case sensitive
638
+ * \param str1 first str
639
+ * \param str2 second str
640
+ * \return 0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors
641
+ */
642
+static inline int str_strcmp(const str *str1, const str *str2)
643
+{
644
+	if(str1==NULL || str2==NULL || str1->s ==NULL || str2->s==NULL || str1->len<0 || str2->len<0)
645
+	{
646
+		LM_ERR("bad parameters\n");
647
+		return -2;
648
+	}
649
+
650
+	if (str1->len < str2->len)
651
+		return -1;
652
+	else if (str1->len > str2->len)
653
+		return 1;
654
+	else
655
+		return strncmp(str1->s, str2->s, str1->len);
656
+}
657
+
658
+/**
659
+ * \brief Compare two str's case insensitive
660
+ * \param str1 first str
661
+ * \param str2 second str
662
+ * \return 0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors
663
+ */
664
+static inline int str_strcasecmp(const str *str1, const str *str2)
665
+{
666
+	if(str1==NULL || str2==NULL || str1->s ==NULL || str2->s==NULL || str1->len<0 || str2->len<0)
667
+	{
668
+		LM_ERR("bad parameters\n");
669
+		return -2;
670
+	}
671
+	if (str1->len < str2->len)
672
+		return -1;
673
+	else if (str1->len > str2->len)
674
+		return 1;
675
+	else
676
+		return strncasecmp(str1->s, str2->s, str1->len);
677
+}
678
+
636 679
 /* converts a username into uid:gid,
637 680
  * returns -1 on error & 0 on success */
638 681
 int user2uid(int* uid, int* gid, char* user);