ReactOS  0.4.14-dev-323-g6fe6a88
_tempbuf.c
Go to the documentation of this file.
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 
34 
35 template <class _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 }
52 
53 #endif /* _STLP_TEMPBUF_C */
54 
55 // Local Variables:
56 // mode:C++
57 // End:
#define INT_MAX
Definition: limits.h:40
#define _STLP_END_NAMESPACE
Definition: features.h:503
Definition: _pair.h:47
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
#define malloc
Definition: debug_ros.c:4
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_CALL
Definition: _bc.h:131
_STLP_BEGIN_NAMESPACE pair< _Tp *, ptrdiff_t > _STLP_CALL __get_temporary_buffer(ptrdiff_t __len, _Tp *)
Definition: _tempbuf.c:37