* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*
- * $Id: tools.c 26170 2008-10-26 20:59:07Z androsyn $
*
* Here is the original header:
*
* defined, tools.h will build inlined versions of the functions
* on supported compilers
*/
+
#define _GNU_SOURCE 1
#include <librb_config.h>
#include <rb_lib.h>
return x;
}
+#ifndef HAVE_STRCASECMP
+#ifndef _WIN32
+/* Fallback taken from FreeBSD. --Elizafox */
+int
+rb_strcasecmp(const char *s1, const char *s2)
+{
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ while (tolower(*us1) == tolower(*us2++))
+ {
+ if (*us1++ == '\0')
+ return 0;
+ }
+
+ return (tolower(*us1) - tolower(*--us2));
+}
+#else /* _WIN32 */
+int
+rb_strcasecmp(const char *s1, const char *s2)
+{
+ return stricmp(s1, s2);
+}
+#endif /* _WIN32 */
+#else /* HAVE_STRCASECMP */
+int
+rb_strcasecmp(const char *s1, const char *s2)
+{
+ return strcasecmp(s1, s2);
+}
+#endif
+
+#ifndef HAVE_STRNCASECMP
+#ifndef _WIN32
+/* Fallback taken from FreeBSD. --Elizafox */
+int
+rb_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ if (n != 0)
+ {
+ const unsigned char *us1 = (const unsigned char *)s1;
+ const unsigned char *us2 = (const unsigned char *)s2;
+
+ do
+ {
+ if (tolower(*us1) != tolower(*us2++))
+ return (tolower(*us1) - tolower(*--us2));
+ if (*us1++ == '\0')
+ break;
+ } while (--n != 0);
+ }
+ return 0;
+}
+#else /* _WIN32 */
+int
+rb_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ return strnicmp(s1, s2, n);
+}
+#endif /* _WIN32 */
+#else /* HAVE_STRNCASECMP */
+int
+rb_strncasecmp(const char *s1, const char *s2, size_t n)
+{
+ return strncasecmp(s1, s2, n);
+}
+#endif
+
+#ifndef HAVE_STRCASESTR
+/* Fallback taken from FreeBSD. --Elizafox */
+char *
+rb_strcasestr(const char *s, const char *find)
+{
+ char c, sc;
+ size_t len;
+
+ if ((c = *find++) != 0) {
+ c = tolower((unsigned char)c);
+ len = strlen(find);
+ do {
+ do {
+ if ((sc = *s++) == 0)
+ return (NULL);
+ } while ((char)tolower((unsigned char)sc) != c);
+ } while (rb_strncasecmp(s, find, len) != 0);
+ s--;
+ }
+ return ((char *)s);
+}
+#else
+char *
+rb_strcasestr(const char *s, const char *find)
+{
+ return strcasestr(s, find);
+}
+#endif
+
#ifndef HAVE_STRLCAT
size_t
rb_strlcat(char *dest, const char *src, size_t count)