
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#ifdef __cplusplus
extern "C"
{
#endif

  int strnicmp (char *s, char *d, int n)
  {
    unsigned char c;

    if (n == 0)
        return (0);

    while (tolower (c = *s) == tolower (*(unsigned char *) d))
      {
	if (c == 0 || --n == 0)
	  return (0);
	++s;
	++d;
      }
    if (tolower (c) < tolower (*(unsigned char *) d))
        return (-1);
      return (1);
  }

  char *stristr (char *s1, char *s2)
  {
    short len2 = strlen (s2);

    if (len2 == 0)
        return (s1);

    while (*s1)
      {
	if (tolower (*s1) == tolower (*s2))
	  if (strnicmp (s1, s2, len2) == 0)
	    return (s1);
	++s1;
      }
    return (NULL);
  }

#ifdef __cplusplus
}
#endif
