2 #include "tao/String_Alloc.h"
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_wchar.h"
5 #include "ace/OS_Memory.h"
8 #ifndef TAO_NO_SHARED_NULL_CORBA_STRING
9 static char null_char
[]= "";
10 static CORBA::WChar null_wchar
[]=
11 # if defined(ACE_HAS_WCHAR) || defined(ACE_HAS_XPG4_MULTIBYTE_CHAR)
16 #endif /* TAO_NO_SHARED_NULL_CORBA_STRING */
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
21 CORBA::string_dup (const char *str
)
29 #ifndef TAO_NO_SHARED_NULL_CORBA_STRING
32 #endif /* TAO_NO_SHARED_NULL_CORBA_STRING */
34 size_t const len
= std::strlen (str
);
36 // This allocates an extra byte for the '\0';
37 char * copy
= CORBA::string_alloc (static_cast<CORBA::ULong
> (len
));
40 // The memcpy() assumes that the destination is a valid buffer.
41 ACE_OS::memcpy (copy
, str
, len
+ 1);
48 CORBA::string_alloc (CORBA::ULong len
)
50 // Allocate 1 + strlen to accomodate the null terminating character.
53 char[size_t (len
+ 1)],
61 CORBA::string_free (char *str
)
63 #ifndef TAO_NO_SHARED_NULL_CORBA_STRING
65 #endif /* TAO_NO_SHARED_NULL_CORBA_STRING */
69 // ****************************************************************
72 CORBA::wstring_dup (const WChar
*const str
)
80 #ifndef TAO_NO_SHARED_NULL_CORBA_STRING
83 #endif /* TAO_NO_SHARED_NULL_CORBA_STRING */
85 CORBA::WChar
* retval
=
86 CORBA::wstring_alloc (static_cast <CORBA::ULong
> (ACE_OS::strlen (str
)));
87 if (retval
== nullptr)
89 // The wscpy() below assumes that the destination is a valid buffer.
93 return ACE_OS::wscpy (retval
, str
);
97 CORBA::wstring_alloc (CORBA::ULong len
)
99 CORBA::WChar
*s
= nullptr;
101 CORBA::WChar
[(size_t) (len
+ 1)],
107 CORBA::wstring_free (CORBA::WChar
*const str
)
109 #ifndef TAO_NO_SHARED_NULL_CORBA_STRING
110 if (null_wchar
!= str
)
111 #endif /* TAO_NO_SHARED_NULL_CORBA_STRING */
115 TAO_END_VERSIONED_NAMESPACE_DECL