/*
 * String functions.
 */
#ifndef _STRING_H
#define _STRING_H

#ifndef _COMPILER_H
#include <compiler.h>
#endif

#ifndef _SIZE_T
#define _SIZE_T __SIZE_TYPEDEF__
typedef _SIZE_T size_t;
#endif

#ifndef NULL
#define NULL __NULL
#endif

__EXTERN void *	memcpy	__PROTO((void * dst, const void * src, size_t size));
__EXTERN char *	strcpy	__PROTO((char *dst, const char *src));
__EXTERN char *	strncpy	__PROTO((char *dst, const char *src, size_t size));
__EXTERN char *	strcat	__PROTO((char *dst, const char *src));
__EXTERN char *	strncat	__PROTO((char *dst, const char *src, size_t size));
__EXTERN int 	memcmp	__PROTO((const void * s1, const void * s2, size_t size));
__EXTERN int 	strcmp	__PROTO((const char *s1, const char *s2));
__EXTERN int 	strncmp	__PROTO((const char *s1, const char *s2, size_t size));
 	/* strcoll not implemented for now */
__EXTERN size_t	strcoll	__PROTO((char *to, size_t maxsize, const char *from));
__EXTERN void *	memchr	__PROTO((const void * s, int ucharwanted, size_t size));
__EXTERN char *	strchr	__PROTO((const char *s, int charwanted));
__EXTERN size_t strcspn	__PROTO((const char *s, const char *reject));
__EXTERN char *	strpbrk	__PROTO((const char *s, const char *breakat));
__EXTERN char *	strrchr	__PROTO((const char *s, int charwanted));
__EXTERN size_t strspn	__PROTO((const char *s, const char *accept));
__EXTERN char *	strstr	__PROTO((const char *s, const char *wanted));
__EXTERN char *	strtok	__PROTO((char *s, const char *delim));
__EXTERN void *	memset	__PROTO((void *s, int ucharfill, size_t size));
__EXTERN size_t	strlen	__PROTO((const char *s));
__EXTERN char *	strerror __PROTO((int errnum));

#ifndef __STRICT_ANSI__
/* 
 * from henry spencers string lib
 *  these dont appear in ansi draft sec 4.11
 */
__EXTERN void *	memccpy	__PROTO((void * dst, const void * src, int ucharstop, size_t size));
__EXTERN char *	strlwr	__PROTO((char *));
__EXTERN char *	strrev	__PROTO((char *));
__EXTERN char *  strdup	__PROTO((const char *s));

/*
 * V7 and BSD compatibility.
 */
__EXTERN char *	index	__PROTO((const char *s, int charwanted));
__EXTERN char *	rindex	__PROTO((const char *s, int charwanted));
__EXTERN void   bcopy	__PROTO((const void *src, void *dst, size_t length));
__EXTERN int	bcmp	__PROTO((const void *s1, const void *s2, size_t length));
__EXTERN void	bzero	__PROTO((void *dst, size_t length));
#endif /* __STRICT_ANSI__ */

/* some macro versions of functions. these are faster, but less
   forgiving of NULLs and similar nasties. to use the library functions,
   just #undef the appropriate things.
*/

#ifdef __GNUC_INLINE__

static __inline__
char *
__strcat(char *dst, const char *src)
{
	register char *_dscan;

	for (_dscan = dst; *_dscan; _dscan++) ;
	while (*_dscan++ = *src++) ;
	return dst;
}

static __inline__
char *
__strcpy(char *dst, const char *src)
{
	register char *_dscan = dst;
	while (*_dscan++ = *src++) ;
	return dst;
}

static __inline__
size_t
__strlen(const char *scan)
{
	register const char *_start = scan+1;
	while (*scan++) ;
	return (size_t)((long)scan - (long)_start);
}

#define strcat 	__strcat
#define strcpy 	__strcpy
#define strlen 	__strlen

#endif /* __GNUC_INLINE__ */

#endif /* _STRING_H */
