_tempbuf.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #ifndef _STLP_INTERNAL_TEMPBUF_H
  29. # include <stl/_tempbuf.h>
  30. #endif
  31. _STLP_BEGIN_NAMESPACE
  32. template <class _Tp>
  33. pair<_Tp*, ptrdiff_t> _STLP_CALL
  34. __get_temporary_buffer(ptrdiff_t __len, _Tp*)
  35. {
  36. if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
  37. __len = INT_MAX / sizeof(_Tp);
  38. while (__len > 0) {
  39. _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
  40. if (__tmp != 0)
  41. return pair<_Tp*, ptrdiff_t>(__tmp, __len);
  42. __len /= 2;
  43. }
  44. return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
  45. }
  46. _STLP_END_NAMESPACE
  47. #endif /* _STLP_TEMPBUF_C */
  48. // Local Variables:
  49. // mode:C++
  50. // End: