epoc32/include/stdapis/stlport/stl/_tempbuf.c
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
 *
williamr@2
     3
 *
williamr@2
     4
 * Copyright (c) 1994
williamr@2
     5
 * Hewlett-Packard Company
williamr@2
     6
 *
williamr@2
     7
 * Copyright (c) 1996,1997
williamr@2
     8
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     9
 *
williamr@2
    10
 * Copyright (c) 1997
williamr@2
    11
 * Moscow Center for SPARC Technology
williamr@2
    12
 *
williamr@2
    13
 * Copyright (c) 1999 
williamr@2
    14
 * Boris Fomitchev
williamr@2
    15
 *
williamr@2
    16
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
    17
 * or implied. Any use is at your own risk.
williamr@2
    18
 *
williamr@2
    19
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@2
    20
 * without fee, provided the above notices are retained on all copies.
williamr@2
    21
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    22
 * provided the above notices are retained, and a notice that the code was
williamr@2
    23
 * modified is included with the above copyright notice.
williamr@2
    24
 *
williamr@2
    25
 */
williamr@2
    26
#ifndef _STLP_TEMPBUF_C
williamr@2
    27
#define _STLP_TEMPBUF_C
williamr@2
    28
williamr@2
    29
#ifndef _STLP_INTERNAL_TEMPBUF_H
williamr@2
    30
# include <stl/_tempbuf.h>
williamr@2
    31
#endif
williamr@2
    32
williamr@2
    33
_STLP_BEGIN_NAMESPACE
williamr@2
    34
williamr@2
    35
template <class _Tp>
williamr@2
    36
pair<_Tp*, ptrdiff_t> _STLP_CALL 
williamr@2
    37
__get_temporary_buffer(ptrdiff_t __len, _Tp*)
williamr@2
    38
{
williamr@2
    39
  if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
williamr@2
    40
    __len = INT_MAX / sizeof(_Tp);
williamr@2
    41
williamr@2
    42
  while (__len > 0) {
williamr@2
    43
    _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
williamr@2
    44
    if (__tmp != 0)
williamr@2
    45
      return pair<_Tp*, ptrdiff_t>(__tmp, __len);
williamr@2
    46
    __len /= 2;
williamr@2
    47
  }
williamr@2
    48
williamr@2
    49
  return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
williamr@2
    50
}
williamr@2
    51
_STLP_END_NAMESPACE
williamr@2
    52
williamr@2
    53
#endif /*  _STLP_TEMPBUF_C */
williamr@2
    54
williamr@2
    55
// Local Variables:
williamr@2
    56
// mode:C++
williamr@2
    57
// End: