/*
 * Copyright (c) 2003 Linuxant inc.
 * Copyright (c) 2001-2003 Conexant Systems, Inc.
 *
 * NOTE: The use and distribution of this software is governed by the terms in
 * the file LICENSE, which is included in the package. You must read this and
 * agree to these terms before using or distributing this software.
 *
 */

/*************************************************************************

File Name: OsString.h

File Description: This file implements all the string/memory utilities.

************************************************************************/

#ifndef __OS_STRING_EX_H__
#define __OS_STRING_EX_H__

#if ( OS_TYPE == OS_LINUX )
#include "osdebug.h"
#endif

#if ( (OS_TYPE == OS_WIN_WDM) && (UK_MODE == UK_KERNEL) )
#define _INTSIZEOF(n)    ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )

#define va_start(ap,v) ap = (char *)&v + _INTSIZEOF(v)
#define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
#define va_end(ap) ap = (char *)0
typedef char * va_list;

#endif

#ifdef __cplusplus
extern "C"
{
#endif

#if !(( UK_MODE == UK_USER ) && (OS_TYPE == OS_LINUX))

#ifndef OS_NOREDEFS

#undef memset
#define memset          OsMemSet
#undef memcpy
#define memcpy          OsMemCpy
#undef memcmp
#define memcmp          OsMemCmp
#undef memmove
#define memmove         OsMemMove

#undef strcpy
#define strcpy          OsStrCpy
#undef strncpy
#define strncpy         OsStrnCpy
#undef strcat
#define strcat          OsStrCat
#undef strncat
#define strncat         OsStrnCat
#undef strcmp
#define strcmp          OsStrCmp
#undef strncmp
#define strncmp         OsStrnCmp
#undef toupper
#define toupper         OsToupper
#undef tolower
#define tolower         OsTolower
#undef isdigit
#define isdigit         OsIsDigit
#undef sprintf
#define sprintf         OsSprintf
#undef strlen
#define strlen          OsStrLen

#endif /* OS_NOREDEFS */

#if ( USE_PRAGMA_PACK == 1 )
#pragma pack(push,1)   /* Packing compatible with WinAC */
#endif


/********************************************************************************
	
Function Name: OsMemSet.

Function Description:The function initializes a buffer to a specified character.

Arguments: Buffer - Pointer to buffer to contain copied characters.
		   c - Character to copy into the buffer.
		   Count - Number of times to copy the character into the buffer.

Return Value: A pointer to Buffer.

********************************************************************************/
StdCall(PVOID, OsMemSet(PVOID Buffer, UINT32 c, UINT32 Count));

/********************************************************************************

Function Name: OsMemCpy.

Function Description:The function copies a specified number of characters from one 
					 buffer to another. This function may not work correctly if 
					 the buffers overlap. 

Arguments: BuffDest - Pointer to buffer to contain copied characters.
		   BuffSrc - Pointer to buffer with the characters to copy.
		   Count - Number of characters to copy.

Return Value: A pointer to BuffDest.

********************************************************************************/
StdCall(PVOID, OsMemCpy(PVOID BuffDest, const VOID *BuffSrc, UINT32 Count));

/********************************************************************************

Function Name: OsMemCmp.

Function Description:The function compares a specified number of characters from two buffers.

Arguments: Buff1 - Pointer to first buffer to compare.
		   Buff2 - Pointer to second buffer to compare.
		   Count - Number of characters to compare.

Return Value: Returns one of three values as follows:
													0 if buffers match.
													< 0 if buff1 is less than buff2.
													>0 if buff1 is greater than buff2.

********************************************************************************/
StdCall(int, OsMemCmp(PVOID Buff1, PVOID Buff2, UINT32 Count));
/********************************************************************************

Function Name: OsMemMove.

Function Description:The memmove function copies count bytes of characters from 
			src to dest. If some regions of the source area and the destination 
			overlap, memmove ensures that the original source bytes in the 
			overlapping region are copied before being overwritten.
Arguments: dest - Destination object.
		   src - Source object
		   count - NNumber of bytes of characters to copy.

Return Value: memmove returns the value of dest
 
********************************************************************************/
StdCall(void *, OsMemMove( void *dest, const void *src, int count ));


/********************************************************************************

Function Name: OsStrCpy.

Function Description:The function copies a specified a string from one 
					 buffer to another. This function may not work correctly if 
					 the buffers overlap. 

Arguments: BuffDest - Pointer to buffer to contain copied string.
		   BuffSrc - Pointer to buffer with the string to copy.

Return Value: A pointer to BuffDest.

********************************************************************************/
StdCall(PVOID, OsStrCpy(OUT PCHAR BuffDest, IN PCHAR BuffSrc));

/********************************************************************************

Function Name: OsStrnCpy.

Function Description:The function copies a specified a string from one 
					 buffer to another. The function does not copy more 
					 than MaxSize bytes.The behavior of strncpy is 
					 undefined if the source and destination strings overlap

Arguments: BuffDest - Pointer to buffer to contain copied string.
		   BuffSrc - Pointer to buffer with the string to copy.
		   MaxSize - Max chars to copy

Return Value: A pointer to BuffDest.

********************************************************************************/
StdCall(PVOID, OsStrnCpy(OUT PCHAR BuffDest, IN PCHAR BuffSrc, int MaxSize));

/********************************************************************************

Function Name: OsStrCat.

Function Description:The function copies a specified a string from one 
					 buffer to another, at its end. This function may not work correctly if 
					 the buffers overlap. 

Arguments: BuffDest - Pointer to buffer to contain copied string.
		   BuffSrc - Pointer to buffer with the string to copy.

Return Value: A pointer to BuffDest.

********************************************************************************/
StdCall(PVOID, OsStrCat(OUT PCHAR BuffDest, IN PCHAR BuffSrc));

/********************************************************************************

Function Name: OsStrnCat.

Function Description:The function copies a specified a string from one 
					 buffer to another, at its end. The function does not copy
					 more than MaxSize bytes.The behavior of strncpy is 
					 undefined if the source and destination strings overlap

Arguments: BuffDest - Pointer to buffer to contain copied string.
		   BuffSrc - Pointer to buffer with the string to copy.
		   MaxSize - Max chars to copy

Return Value: A pointer to BuffDest.

********************************************************************************/
StdCall(PVOID, OsStrnCat(OUT PCHAR BuffDest, IN PCHAR BuffSrc, int MaxSize));

/********************************************************************************

Function Name: OsStrCmp.

Function Description:The strcmp function compares string1 and string2 
		lexicographically and returns a value indicating their relationship

Arguments: string1 ,string2 - Null terminated strings to compare

Return Value: lexicographic relation of string1 to string2.

********************************************************************************/
StdCall(int, OsStrCmp(IN PCHAR string1, IN PCHAR string2));
/********************************************************************************

Function Name: OsStrnCpy.

Function Description:The strcmp function compares string1 and string2 
		lexicographically and returns a value indicating their relationship
Arguments: string1 ,string2 - Null terminated strings to compare
					MaxSize	- Number of characters to compare

Return Value: lexicographic relation of string1 to string2.

********************************************************************************/
StdCall(int, OsStrnCmp(IN PCHAR string1, IN PCHAR string2, int MaxSize));
/********************************************************************************

Function Name: OsToupper.

Function Description:converts a charecter c to upper case  

Arguments: c - charected to be converted to upper case.

Return Value: upper case charecter of c.

********************************************************************************/
StdCall(int, OsToupper(int c));
/********************************************************************************

Function Name: OsTolower.

Function Description:converts a charecter c to lower case  

Arguments: c - charected to be converted to lower case.

Return Value: lower case charecter of c.

********************************************************************************/
StdCall(int, OsTolower(int c));
/********************************************************************************

Function Name: OsIsDigit.

Function tests if a charecter is a decimal digit. 

Arguments: c - integer to test.

Return Value: non zero value if c is a decimal digit('0' - '9').

********************************************************************************/
StdCall(int, OsIsDigit(int c));

/********************************************************************************

Function Name: OsSprintf.

Function Description:The OsSprintf function formats and stores a series of 
						characters and values in buffer. 

Arguments: buffer - Pointer to buffer to contain copied string.
		   format - control string


Return Value: OsSprintf returns the number of bytes stored in buffer, 
				not counting the terminating null character. 

********************************************************************************/
int	__cdecl  OsSprintf(OUT PCHAR buffer, const CHAR *format_string, ...);

/********************************************************************************

Function Name: OSSprintfFixedArgs.

Function Description:The OSSprintfFixedArgs function formats and stores a series of 
						characters and values in buffer. The function recieves the 
						format parameters not on the stack, but using the va_list
						parameter

Arguments: buffer - Pointer to buffer to contain copied string.
		   format - control string.
		   StartedVaList - pointer to va_list that has been started to include the format arguments


Return Value: OsSprintf returns the number of bytes stored in buffer, 
				not counting the terminating null character. 

********************************************************************************/
StdCall(int, OSSprintfFixedArgs(PCHAR buffer, const CHAR *format, PCHAR StartedVaList));

/********************************************************************************

Function Name: OsStrLen.

Function Description:The function returns the length of a null-terminated string.

Arguments: String - Pointer to buffer to contain copied string.

Return Value: int - the length of a null-terminated string.

********************************************************************************/
StdCall(int, OsStrLen(IN PCHAR String));

 
int Osatoi(IN PCHAR String);
 
#if ( USE_PRAGMA_PACK == 1 )
#pragma pack(pop)   /* Packing compatible with our VXDs */
#endif

#endif /* UK_MODE == UK_KERNEL */

#ifdef __cplusplus
}
#endif

#endif /* __OS_STRING_EX_H__ */
