#ifndef _NSRMEM_ //-*-c++-*-
#define _NSRMEM_

//----------------------------------------------------------------------
//  nsrMem.h
//   System-dependent memory function declarations.
//
//      Unpublished Confidential Information of Hewlett-Packard
//      Company. Do not disclose.  Copyright (c) Hewlett-Packard
//      Company 1995. All rights reserved
// 
// The contents of this software are proprietary and confidential to
// the Hewlett- Packard Company, and are limited in distribution to
// those with a direct need to know.  Individuals having access to
// this software are responsible for maintaining the confidentiality
// of the content and for keeping the software secure when not in use.
// Transfer to any party is strictly forbidden other than as expressly
// permitted in writing by Hewlett-Packard Company.  Unauthorized
// transfer to or possession by any unauthorized party may be a
// criminal offense.
//
//                  RESTRICTED RIGHTS LEGEND
//
//      Use,  duplication,  or disclosure by the U. S. Government is
//      subject to restrictions as set forth in subparagraph (c) (1)
//      (ii) in the Rights in Technical Data and Computer Software
//      clause in DFARS 252.227-7013 or any other successor clause.
//
//                      HEWLETT-PACKARD COMPANY
//                      3000 Hanover St.
//                      Palo Alto, CA  94304 U.S.A.
//
//      Rights for non-DOD U.S. Government Departments and Agencies
//      are as set forth in FAR 52.227-19 (c) (1,2) or any other
//      successor clause.
//
//----------------------------------------------------------------------
// $Source: /projects/HMS/nsr/udfCore/config/nsrMem.h,v $
// $Revision: 1.3 $     $Author: hmgr $
// $State: Exp $        $Locker:  $
// $Date: 96/05/20 14:56:47 $
//

inline static VOID_PTR
AllocateMemory(UINT32 nSize)
{
#ifdef WINDOWS_PLATFORM
    return ((VOID_PTR)farmalloc(nSize));
#else
    return ((VOID_PTR)malloc(nSize));
#endif
}

inline static void
FreeMemory(VOID_PTR pMem)
{
#ifdef WINDOWS_PLATFORM
    farfree(pMem);
#else
    free(pMem);
#endif
}

inline static VOID_PTR
MemCpy(VOID_PTR pDest, CONST_VOID_PTR pSource, UINT32 nLength)
{
#ifdef WINDOWS_PLATFORM
    VOID_PTR pReturn = pDest;
    while (nLength--)
        *((BYTE_PTR)pDest)++ = *((BYTE_PTR)pSource)++;

    return (pReturn);
#else
    return (memcpy(pDest, pSource, nLength));
#endif
}

inline static VOID_PTR
MemMove(VOID_PTR pDest, CONST_VOID_PTR pSource, UINT32 nLength)
{
#ifdef WINDOWS_PLATFORM
    if (pSource == pDest)
        return pDest;

    VOID_PTR pReturn = pDest;

    if (pDest < pSource)
        while (nLength--)
            *((BYTE_PTR)pDest)++ = *((BYTE_PTR)pSource)++;
    else {
        ((BYTE_PTR)pDest) += nLength - 1;
        ((BYTE_PTR)pSource) += nLength - 1;
        while (nLength --)
            *((BYTE_PTR)pDest)-- = *((BYTE_PTR)pSource)--;
    }

    return (pReturn);
#else
    return (memmove(pDest, pSource, nLength));
#endif
}

inline static int
MemCmp(CONST_VOID_PTR pMem1, CONST_VOID_PTR pMem2, UINT32 nLength)
{
#ifdef WINDOWS_PLATFORM
    int nReturn = 0;
    while (nLength --) {
        nReturn = *((BYTE_PTR)pMem1)++ - *((BYTE_PTR)pMem2)++;
        if (nReturn)
            break;
    }

    return (nReturn);
#else
    return (memcmp(pMem1, pMem2, nLength));
#endif
}

inline static VOID_PTR
MemSet(VOID_PTR pDest, char pVal, UINT32 nLength)
{
#ifdef WINDOWS_PLATFORM
    VOID_PTR pReturn = pDest;
    while (nLength--)
        *((BYTE_PTR)pDest)++ = pVal;

    return (pReturn);
#else
    return (memset(pDest, pVal, nLength));
#endif
}

inline static UINT32
StrLen(CONST_CHAR_PTR pStr)
{
#ifdef WINDOWS_PLATFORM
    UINT32 nReturn = 0;
    while (*pStr++)
        nReturn++;

    return (nReturn);
#else
    return (strlen(pStr));
#endif
}

inline static CHAR_PTR
StrCpy(CHAR_PTR pDest, CONST_CHAR_PTR pSource)
{
#ifdef WINDOWS_PLATFORM
    CHAR_PTR pReturn = pDest;
    while (*pSource)
        *pDest++ = *pSource++;

    *pDest = 0;
    return (pReturn);
#else
    return (strcpy(pDest, pSource));
#endif
}

inline static CHAR_PTR
StrNCpy(CHAR_PTR pDest, CONST_CHAR_PTR pSource, UINT32 nLength)
{
#ifdef WINDOWS_PLATFORM
    UINT32 nPos = 0;
    CHAR_PTR pReturn = pDest;
    while (*pSource && nPos < nLength) {
        *pDest++ = *pSource++;
        nPos++;
    }

    if (nPos < nLength)
        *pDest = 0;

    return pDest;

#else
    return (strncpy(pDest, pSource, nLength));
#endif
}

inline static int
StrCmp(CONST_CHAR_PTR pStr1, CONST_CHAR_PTR pStr2)
{
#ifdef WINDOWS_PLATFORM
    int nReturn = 0;
    do {
    } while ((nReturn = *pStr1 - *pStr2) == 0 && *pStr1++ && *pStr2++);

    return (nReturn);
#else
    return (strcmp(pStr1, pStr2));
#endif
}

#endif // _NSRMEM_
