/home/ntakagi/work/STLport-5.1.5/stlport/stl/_tempbuf.c

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Copyright (c) 1994
00005  * Hewlett-Packard Company
00006  *
00007  * Copyright (c) 1996,1997
00008  * Silicon Graphics Computer Systems, Inc.
00009  *
00010  * Copyright (c) 1997
00011  * Moscow Center for SPARC Technology
00012  *
00013  * Copyright (c) 1999
00014  * Boris Fomitchev
00015  *
00016  * This material is provided "as is", with absolutely no warranty expressed
00017  * or implied. Any use is at your own risk.
00018  *
00019  * Permission to use or copy this software for any purpose is hereby granted
00020  * without fee, provided the above notices are retained on all copies.
00021  * Permission to modify the code and to distribute modified code is granted,
00022  * provided the above notices are retained, and a notice that the code was
00023  * modified is included with the above copyright notice.
00024  *
00025  */
00026 #ifndef _STLP_TEMPBUF_C
00027 #define _STLP_TEMPBUF_C
00028 
00029 #ifndef _STLP_INTERNAL_TEMPBUF_H
00030 # include <stl/_tempbuf.h>
00031 #endif
00032 
00033 _STLP_BEGIN_NAMESPACE
00034 
00035 template <class _Tp>
00036 pair<_Tp*, ptrdiff_t> _STLP_CALL
00037 __get_temporary_buffer(ptrdiff_t __len, _Tp*)
00038 {
00039   if (__len > ptrdiff_t(INT_MAX / sizeof(_Tp)))
00040     __len = INT_MAX / sizeof(_Tp);
00041 
00042   while (__len > 0) {
00043     _Tp* __tmp = (_Tp*) malloc((size_t)__len * sizeof(_Tp));
00044     if (__tmp != 0)
00045       return pair<_Tp*, ptrdiff_t>(__tmp, __len);
00046     __len /= 2;
00047   }
00048 
00049   return pair<_Tp*, ptrdiff_t>((_Tp*)0, 0);
00050 }
00051 _STLP_END_NAMESPACE
00052 
00053 #endif /*  _STLP_TEMPBUF_C */
00054 
00055 // Local Variables:
00056 // mode:C++
00057 // End:



Generated on Mon Mar 10 15:32:41 2008 by  doxygen 1.5.1