2 * Copyright (c) 1996,1997
3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
19 __Named_exception::__Named_exception(const string
& __str
) {
20 size_t __size
= strlen(_STLP_PRIV
__get_c_string(__str
)) + 1;
21 if (__size
> _S_bufsize
) {
22 _M_name
= __STATIC_CAST(char*, malloc(__size
* sizeof(char)));
25 _M_name
= _M_static_name
;
28 *(__REINTERPRET_CAST(size_t*, &_M_static_name
[0])) = __size
* sizeof(char);
32 _M_name
= _M_static_name
;
34 #if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
35 strncpy(_M_name
, _STLP_PRIV
__get_c_string(__str
), __size
- 1);
36 _M_name
[__size
- 1] = '\0';
38 strncpy_s(_M_name
, __size
, _STLP_PRIV
__get_c_string(__str
), __size
- 1);
42 __Named_exception::__Named_exception(const __Named_exception
& __x
) {
43 size_t __size
= strlen(__x
._M_name
) + 1;
44 if (__size
> _S_bufsize
) {
45 _M_name
= __STATIC_CAST(char*, malloc(__size
* sizeof(char)));
48 _M_name
= _M_static_name
;
51 *(__REINTERPRET_CAST(size_t*, &_M_static_name
[0])) = __size
* sizeof(char);
55 _M_name
= _M_static_name
;
57 #if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
58 strncpy(_M_name
, __x
._M_name
, __size
- 1);
59 _M_name
[__size
- 1] = '\0';
61 strncpy_s(_M_name
, __size
, __x
._M_name
, __size
- 1);
65 __Named_exception
& __Named_exception::operator = (const __Named_exception
& __x
) {
66 size_t __size
= strlen(__x
._M_name
) + 1;
67 size_t __buf_size
= _M_name
!= _M_static_name
? *(__REINTERPRET_CAST(size_t*, &_M_static_name
[0])) : _S_bufsize
;
68 if (__size
> __buf_size
) {
69 // Being here necessarily mean that we need to allocate a buffer:
70 if (_M_name
!= _M_static_name
) free(_M_name
);
71 _M_name
= __STATIC_CAST(char*, malloc(__size
* sizeof(char)));
74 _M_name
= _M_static_name
;
77 *(__REINTERPRET_CAST(size_t*, &_M_static_name
[0])) = __size
* sizeof(char);
80 #if !defined (_STLP_USE_SAFE_STRING_FUNCTIONS)
81 strncpy(_M_name
, __x
._M_name
, __size
- 1);
82 _M_name
[__size
- 1] = '\0';
84 strncpy_s(_M_name
, __size
, __x
._M_name
, __size
- 1);
89 __Named_exception::~__Named_exception() _STLP_NOTHROW_INHERENTLY
{
90 if (_M_name
!= _M_static_name
)
94 const char* __Named_exception::what() const _STLP_NOTHROW_INHERENTLY