williamr@4: /*
williamr@4:  *
williamr@4:  *
williamr@4:  * Copyright (c) 1994
williamr@4:  * Hewlett-Packard Company
williamr@4:  *
williamr@4:  * Copyright (c) 1996,1997
williamr@4:  * Silicon Graphics Computer Systems, Inc.
williamr@4:  *
williamr@4:  * Copyright (c) 1997
williamr@4:  * Moscow Center for SPARC Technology
williamr@4:  *
williamr@4:  * Copyright (c) 1999
williamr@4:  * Boris Fomitchev
williamr@4:  *
williamr@4:  * This material is provided "as is", with absolutely no warranty expressed
williamr@4:  * or implied. Any use is at your own risk.
williamr@4:  *
williamr@4:  * Permission to use or copy this software for any purpose is hereby granted
williamr@4:  * without fee, provided the above notices are retained on all copies.
williamr@4:  * Permission to modify the code and to distribute modified code is granted,
williamr@4:  * provided the above notices are retained, and a notice that the code was
williamr@4:  * modified is included with the above copyright notice.
williamr@4:  *
williamr@4:  */
williamr@4: #ifndef _STLP_TEMPBUF_C
williamr@4: #define _STLP_TEMPBUF_C
williamr@4: 
williamr@4: #ifndef _STLP_INTERNAL_TEMPBUF_H
williamr@4: # include <stl/_tempbuf.h>
williamr@4: #endif
williamr@4: 
williamr@4: _STLP_BEGIN_NAMESPACE
williamr@4: 
williamr@4: template <class _Tp>
williamr@4: pair<_Tp*, ptrdiff_t> _STLP_CALL
williamr@4: __get_temporary_buffer(ptrdiff_t __len, _Tp*)
williamr@4: {
williamr@4:   if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
williamr@4:     __len = INT_MAX / sizeof(_Tp);
williamr@4: 
williamr@4:   while (__len > 0) {
williamr@4:     _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
williamr@4:     if (__tmp != 0)
williamr@4:       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
williamr@4:     __len /= 2;
williamr@4:   }
williamr@4: 
williamr@4:   return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
williamr@4: }
williamr@4: _STLP_END_NAMESPACE
williamr@4: 
williamr@4: #endif /*  _STLP_TEMPBUF_C */
williamr@4: 
williamr@4: // Local Variables:
williamr@4: // mode:C++
williamr@4: // End: