00001 #include "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
00007
00008 #include "ace/streams.h"
00009
00010 ACE_RCSID (tao,
00011 String_Alloc,
00012 "String_Alloc.cpp,v 1.3 2006/05/09 07:45:27 jwillemsen Exp")
00013
00014 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00015
00016 char *
00017 CORBA::string_dup (const char *str)
00018 {
00019 if (!str)
00020 {
00021 errno = EINVAL;
00022 return 0;
00023 }
00024
00025 size_t const len = ACE_OS::strlen (str);
00026
00027
00028 char * copy = CORBA::string_alloc (static_cast<CORBA::ULong> (len));
00029
00030 if (copy != 0)
00031 {
00032
00033 ACE_OS::memcpy (copy,
00034 str,
00035 len + 1);
00036 }
00037
00038 return copy;
00039 }
00040
00041 char *
00042 CORBA::string_alloc (CORBA::ULong len)
00043 {
00044
00045 char *s = 0;
00046 ACE_NEW_RETURN (s,
00047 char[size_t (len + 1)],
00048 0);
00049
00050 s[0]= '\0';
00051
00052 return s;
00053 }
00054
00055 void
00056 CORBA::string_free (char *str)
00057 {
00058 delete [] str;
00059 }
00060
00061
00062
00063 CORBA::WChar*
00064 CORBA::wstring_dup (const WChar *const str)
00065 {
00066 if (!str)
00067 {
00068 errno = EINVAL;
00069 return 0;
00070 }
00071
00072 CORBA::WChar* retval =
00073 CORBA::wstring_alloc (static_cast <CORBA::ULong> (ACE_OS::strlen (str)));
00074
00075
00076 if (retval == 0)
00077 {
00078 return 0;
00079 }
00080
00081 return ACE_OS::wscpy (retval,
00082 str);
00083 }
00084
00085 CORBA::WChar*
00086 CORBA::wstring_alloc (CORBA::ULong len)
00087 {
00088 CORBA::WChar *s = 0;
00089 ACE_NEW_RETURN (s,
00090 CORBA::WChar [(size_t) (len + 1)],
00091 0);
00092
00093 return s;
00094 }
00095
00096 void
00097 CORBA::wstring_free (CORBA::WChar *const str)
00098 {
00099 delete [] str;
00100 }
00101
00102 TAO_END_VERSIONED_NAMESPACE_DECL