00001 #include "tao/String_Alloc.h" 00002 00003 #include "ace/OS_NS_string.h" 00004 #include "ace/OS_NS_wchar.h" 00005 #include "ace/OS_Memory.h" 00006 // FUZZ: disable check_for_streams_include 00007 #include "ace/streams.h" 00008 #include "tao/Allocation_Macros.h" 00009 00010 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00011 00012 char * 00013 CORBA::string_dup (const char *str) 00014 { 00015 if (!str) 00016 { 00017 errno = EINVAL; 00018 return 0; 00019 } 00020 00021 size_t const len = ACE_OS::strlen (str); 00022 00023 // This allocates an extra byte for the '\0'; 00024 char * copy = CORBA::string_alloc (static_cast<CORBA::ULong> (len)); 00025 00026 if (copy != 0) 00027 { 00028 // The memcpy() assumes that the destination is a valid buffer. 00029 ACE_OS::memcpy (copy, str, len + 1); 00030 } 00031 00032 return copy; 00033 } 00034 00035 char * 00036 CORBA::string_alloc (CORBA::ULong len) 00037 { 00038 // Allocate 1 + strlen to accomodate the null terminating character. 00039 char *s = 0; 00040 ACE_ALLOCATOR_NEW (s, 00041 char[size_t (len + 1)], 00042 0); 00043 00044 s[0]= '\0'; 00045 00046 return s; 00047 } 00048 00049 void 00050 CORBA::string_free (char *str) 00051 { 00052 ACE_Allocator::instance ()->free (str); 00053 } 00054 00055 // **************************************************************** 00056 00057 CORBA::WChar* 00058 CORBA::wstring_dup (const WChar *const str) 00059 { 00060 if (!str) 00061 { 00062 errno = EINVAL; 00063 return 0; 00064 } 00065 00066 CORBA::WChar* retval = 00067 CORBA::wstring_alloc (static_cast <CORBA::ULong> (ACE_OS::strlen (str))); 00068 00069 // The wscpy() below assumes that the destination is a valid buffer. 00070 if (retval == 0) 00071 { 00072 return 0; 00073 } 00074 00075 return ACE_OS::wscpy (retval, str); 00076 } 00077 00078 CORBA::WChar* 00079 CORBA::wstring_alloc (CORBA::ULong len) 00080 { 00081 CORBA::WChar *s = 0; 00082 ACE_ALLOCATOR_NEW (s, 00083 CORBA::WChar [(size_t) (len + 1)], 00084 0); 00085 00086 return s; 00087 } 00088 00089 void 00090 CORBA::wstring_free (CORBA::WChar *const str) 00091 { 00092 ACE_Allocator::instance ()->free(str); 00093 } 00094 00095 TAO_END_VERSIONED_NAMESPACE_DECL