]> git.buserror.net Git - polintos/scott/priv.git/blob - include/c++/stl/stl/_tempbuf.c
minor doc updates
[polintos/scott/priv.git] / include / c++ / stl / stl / _tempbuf.c
1 /*
2  *
3  *
4  * Copyright (c) 1994
5  * Hewlett-Packard Company
6  *
7  * Copyright (c) 1996,1997
8  * Silicon Graphics Computer Systems, Inc.
9  *
10  * Copyright (c) 1997
11  * Moscow Center for SPARC Technology
12  *
13  * Copyright (c) 1999
14  * Boris Fomitchev
15  *
16  * This material is provided "as is", with absolutely no warranty expressed
17  * or implied. Any use is at your own risk.
18  *
19  * Permission to use or copy this software for any purpose is hereby granted
20  * without fee, provided the above notices are retained on all copies.
21  * Permission to modify the code and to distribute modified code is granted,
22  * provided the above notices are retained, and a notice that the code was
23  * modified is included with the above copyright notice.
24  *
25  */
26 #ifndef _STLP_TEMPBUF_C
27 #define _STLP_TEMPBUF_C
28
29 #ifndef _STLP_INTERNAL_TEMPBUF_H
30 # include <stl/_tempbuf.h>
31 #endif
32
33 _STLP_BEGIN_NAMESPACE
34
35 template <class _Tp>
36 pair<_Tp*, ptrdiff_t> _STLP_CALL
37 __get_temporary_buffer(ptrdiff_t __len, _Tp*)
38 {
39   if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
40     __len = INT_MAX / sizeof(_Tp);
41
42   while (__len > 0) {
43     _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
44     if (__tmp != 0)
45       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
46     __len /= 2;
47   }
48
49   return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
50 }
51 _STLP_END_NAMESPACE
52
53 #endif /*  _STLP_TEMPBUF_C */
54
55 // Local Variables:
56 // mode:C++
57 // End: