#ifndef __STD_NEW
#define __STD_NEW

#ifndef  __STDDEF_H__
#include <stddef.h>
#endif

#include <malloc.h>
#include <exception>

namespace __dls {
   extern const char _RTL_DATA *__dls_bad_alloc ;
} ;

namespace std {

    typedef void ( *new_handler) ();
    extern new_handler set_new_handler( new_handler new_p );

   class _RTL_CLASS bad_alloc : public exception     
   { 
      public:
         bad_alloc () throw () : exception( )
            { ; }
         bad_alloc(const bad_alloc&) __NOTHROW
            { ; }
         bad_alloc& operator=(const bad_alloc&) __NOTHROW
            { return *this; }
         virtual ~bad_alloc ()  __NOTHROW;

         virtual const char * what () const  __NOTHROW
         { 
            return __dls::__dls_bad_alloc ;
         }
   };

   struct nothrow_t {};

   extern nothrow_t _RTL_DATA nothrow;
} ;

typedef void ( *new_handler) ();

extern new_handler set_new_handler( new_handler __p );

void *  operator new (size_t);
void *  operator new [] (size_t) ;

void    operator delete (void *) noexcept;
void    operator delete[] (void *) noexcept ;

inline void *  operator new(size_t, void *ptr)
 { return ptr; }
inline void*  operator new[] ( size_t, void* ptr)
 { return ptr; }

inline void * operator new (size_t size, const std::nothrow_t &nt) noexcept
{
    size = size ? size : 1;
    return malloc(size);
}
inline void * operator new[] (size_t size, const std::nothrow_t &nt) noexcept
{
    void *rv = ::operator new (size + sizeof(size_t), nt);
	if (rv)
		rv = (void *)((char *)rv + sizeof(size_t));
	return rv;
}
inline void operator delete (void *v, const std::nothrow_t &nt) noexcept
{
   free(v) ;
}
inline void operator delete[] (void *v, const std::nothrow_t &nt) noexcept
{
   ::operator delete ((void *)((char *)v - sizeof(size_t)),nt);  
}

#endif
