#ifndef __string_h
#define __string_h
#pragma once

/* string.h */

#ifndef __sys_stdtypes_h
#include <sys/stdtypes.h>
#endif

#ifndef NULL
#define NULL 0
#endif

#ifndef _DF_SIZE_T
#define _DF_SIZE_T
typedef _TD_SIZE_T size_t;
#endif

/* String functions: */

void	*memchr(const void *, int, size_t);
int	 memcmp(const void *, const void *, size_t);
void	*memcpy(void *, const void *, size_t);
void	*memmove(void *, const void *, size_t);
void	*memset(void *, int, size_t);
char	*strcat(char *, const char *);
char	*strchr(const char *, int);
int	 strcmp(const char *, const char *);
char	*strcpy(char *, const char *);
size_t	 strcspn(const char *, const char *);
char	*strerror(int);
size_t	 strlen(const char *);
char	*strncat(char *, const char *, size_t);
int	 strncmp(const char *, const char *, size_t);
char	*strncpy(char *, const char *, size_t);
char	*strpbrk(const char *, const char *);
char	*strrchr(const char *, int);
size_t	 strspn(const char *, const char *);
char	*strstr(const char *, const char *);
char	*strtok(char *, const char *);

#ifndef __STRICT_ANSI__

/* Nonstandard */

int	 bcmp(const char *, const char *, size_t);
void	 bcopy(const char *, char *, size_t);
void	 bzero(void *, size_t);
int	 ffs(int);
char	*index(void *, int);
void	*memccpy(void *, void *, int, size_t);
char	*rindex(void *, int);
char	*strdup(const char *);
char	*strdcat(const char *, const char *);
char	*strndup(const char *, int);

#endif /* not __STRICT_ANSI__ */

/* Below are inline function definitions for small and frequently used
   functions in this header.  If GCC can't generate inline code it will
   use the version in the library.  Refer to the library for documented
   versions of these functions. */
   
#if defined __GNUC__ && !defined __NOINLINES__

extern __inline__ void *
memset (void *s, int c, size_t size)
{
  unsigned char *p = s;
  while (size-- > 0)
    *p++ = (unsigned char) c;
  return s;
}

extern __inline__ void *
memcpy (void *dst, const void *src, size_t size)
{
  const unsigned char *s = src;
  unsigned char *d = dst;
  if (size <= 0)
    return dst;
  while (size-- > 0)
    *d++ = *s++;
  return dst;
}

extern __inline__ size_t
strlen (const char *s)
{
  size_t count = 0;
  while (*s++)
    ++count;
  return count;
}

extern __inline__ char *
strcpy (char *dst, const char *src)
{
  char *d = dst;
  while ((*d++ = *src++) != '\0')
    ;
  return dst;
}

extern __inline__ int
memcmp (const void *s1, const void *s2, size_t size)
{
  const unsigned char *p1 = s1;
  const unsigned char *p2 = s2;
  while (size-- > 0)
    if (*p1 == *p2)
      {
	p1++;
	p2++;
      }
    else
      return *p1 - *p2;
  return 0;
}

extern __inline__ int
strcmp (const char *s1, const char *s2)
{
  const unsigned char *p1 = (const unsigned char *)s1;
  const unsigned char *p2 = (const unsigned char *)s2;
  while (*p1 != '\0' && *p1 == *p2)
    {
      p1++;
      p2++;
    }
  if (*p1 == '\0' && *p2 == '\0')
    return 0;
  else if (*p1 == '\0')
    return -1;
  else if (*p2 == '\0')
    return 1;
  else
    return *p1 - *p2;
}

#endif /* End of inline function definitions. */

#endif /* __string_h */
