/****************************************************************************
 * 
 *  $Id: os.h,v 1.7 2000/08/10 18:43:22 uboddeti Exp $
 *
 *  Copyright (C) 1995,1996,1997 RealNetworks, Inc.
 *  All rights reserved.
 *
 *  http://www.real.com/devzone
 *
 *  This program contains proprietary information of RealNetworks, Inc.,
 *  and is licensed subject to restrictions on use and distribution.
 *
 *  Operating System Dependant defines, functions, and includes
 *
 */

#ifndef _OS_
#define _OS_

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>

#if defined(_UNIX)
#if defined(__hpux)
#include <dl.h>
#elif defined(_AIX)
#include "dlfcn.h"
#else
#include <dlfcn.h>
#endif
#endif

#ifndef _HPUX
typedef void* HINSTANCE;
#else
typedef shl_t HINSTANCE;
#endif

#if defined (_FREEBSD2)
#define RTLD_LAZY 1
#endif

inline HINSTANCE
LoadLibrary(char* pFileName)
{
#if defined(__hpux)
    return shl_load(pFileName, BIND_DEFERRED, 0L);
#else
    return dlopen(pFileName, RTLD_LAZY);
#endif
}

inline void*
GetProcAddress(HINSTANCE pDLL, char* pSymbol)
{
#if defined(_FREEBSD2)
    char pNewSymbol[2048];
    sprintf(pNewSymbol, "_%s", pSymbol);
    return dlsym(pDLL, pNewSymbol);
#elif defined(__hpux)
    void* symAddr = 0;
    int rc = shl_findsym((shl_t *)pDLL, pSymbol, TYPE_UNDEFINED, &symAddr);
    if (rc < 0)
	return 0;
    else
	return symAddr;
#else
    return dlsym(pDLL, pSymbol);
#endif
}

inline void
FreeLibrary(HINSTANCE pDLL)
{
#if defined(__hpux)
    shl_unload(pDLL);
#else
    dlclose(pDLL);
#endif
}


inline void
GetCurrentDirectory( int nBufferLength, char* lpBuffer )
{
    getcwd( lpBuffer, nBufferLength );
}

#endif
