
/*
  File: include/basic/win32/libport.h
  Description: Provides missing platform-specific library functions
  Part of the Mantis project
  (c) 2002 Lycos Inc.

  This file is distributed for the sole purpose of allowing you to write
  software to interface with Sonique 2 and other Mantis programs. It is
  not to be modified or used for any other purpose without written
  authorization.

  If you redistribute this file, it must be in the original package
  complete with all other files provided, including the usage agreement.

  Do not remove this notice.
*/

#ifndef	_WIN32_LIB_H__
#define _WIN32_LIB_H__

#ifdef DEBUG_INCLUDE_ORDER
#pragma message("Including " __FILE__ "\n" )
#endif

#if _MSC_VER > 1000
#pragma once
#endif


//These seem to be missing?? - NV

inline int lstrcmpn(const char* first, const char* second, size_t count)
{
	while (count)
	{
		if (first[0] != second[0]) return first[0]-second[0];
		first++;
		second++;
		count--;
	}
	return 0;
}

#define tolower(c) ( ((c)>='A' && (c)<='Z') ? ((c)-'A'+'a') : (c) )
inline int lstrcmpni(const char* first, const char* second, size_t count)
{
	while (count)
	{
		if (tolower(first[0]) != tolower(second[0])) return tolower(first[0])-tolower(second[0]);
		first++;
		second++;
		count--;
	}
	return 0;
}





// jmc110802 GetEnvironmentVariable is WString
//inline bool GetEnvironmentVariable( const char* szName, AString& toHere )
inline bool GetEnvironmentVariable( WString wsName, WString& toHere )
{
	if( wsName )
	{
		uint32 nCount;
		if ( IsUnicodeFileSystem() )
			nCount = GetEnvironmentVariableW( wsName, NULL, 0 );
		else
			nCount = GetEnvironmentVariableA( AString(wsName), NULL, 0 );

		if( nCount )
		{
			toHere.Allocate(nCount-1);
			if ( IsUnicodeFileSystem() )
			{
				if( GetEnvironmentVariableW( wsName, toHere.GetAt(), nCount ) )
					return true;
			}
			else
			{
				AString asTemp;
				asTemp.Allocate(nCount-1);
				if( GetEnvironmentVariableA( AString(wsName), asTemp.GetAt(), nCount ) )
				{
					toHere = asTemp;
					return true;
				}
			}
		}
	}
	return false;
}

/* -- Win32 has this function Exactly..  so don't have to reimplement
   -- other OS's will have to provide this
bool SetEnvironmentVariable( const char* szName, const char* this ); 
*/



#endif
