OpenDDS  Snapshot(2023/04/28-20:55)
String_Alloc.cpp
Go to the documentation of this file.
1 #include "tao/String_Alloc.h"
2 
3 #include "ace/OS_NS_string.h"
4 #include "ace/OS_NS_wchar.h"
5 #include "ace/OS_Memory.h"
6 // FUZZ: disable check_for_streams_include
7 #include "ace/streams.h"
9 
11 
12 char *
13 CORBA::string_dup (const char *str)
14 {
15  if (!str)
16  {
17  errno = EINVAL;
18  return 0;
19  }
20 
21  size_t const len = ACE_OS::strlen (str);
22 
23  // This allocates an extra byte for the '\0';
24  char * copy = CORBA::string_alloc (static_cast<CORBA::ULong> (len));
25 
26  if (copy != 0)
27  {
28  // The memcpy() assumes that the destination is a valid buffer.
29  ACE_OS::memcpy (copy, str, len + 1);
30  }
31 
32  return copy;
33 }
34 
35 char *
37 {
38  // Allocate 1 + strlen to accommodate the null terminating character.
39  char *s = 0;
41  char[size_t (len + 1)],
42  0);
43 
44  s[0]= '\0';
45 
46  return s;
47 }
48 
49 void
50 CORBA::string_free (char *str)
51 {
52  ACE_Allocator::instance ()->free (str);
53 }
54 
55 // ****************************************************************
56 
58 CORBA::wstring_dup (const WChar *const str)
59 {
60  if (!str)
61  {
62  errno = EINVAL;
63  return 0;
64  }
65 
66  CORBA::WChar* retval =
67  CORBA::wstring_alloc (static_cast <CORBA::ULong> (ACE_OS::strlen (str)));
68 
69  // The wscpy() below assumes that the destination is a valid buffer.
70  if (retval == 0)
71  {
72  return 0;
73  }
74 
75  return ACE_OS::wscpy (retval, str);
76 }
77 
80 {
81  CORBA::WChar *s = 0;
83  CORBA::WChar [(size_t) (len + 1)],
84  0);
85 
86  return s;
87 }
88 
89 void
91 {
93 }
94 
#define TAO_BEGIN_VERSIONED_NAMESPACE_DECL
ACE_WCHAR_T WChar
void wstring_free(WChar *const)
char * string_alloc(ULong len)
void * memcpy(void *t, const void *s, size_t len)
virtual void free(void *ptr)=0
#define ACE_ALLOCATOR_NEW(POINTER, CONSTRUCTOR, RET_VAL)
size_t strlen(const char *s)
char * string_dup(const char *)
ACE_CDR::ULong ULong
static ACE_Allocator * instance(void)
WChar * wstring_dup(const WChar *const)
WChar * wstring_alloc(ULong len)
void string_free(char *)
DDS::ReturnCode_t copy(DDS::DynamicData_ptr dest, DDS::DynamicData_ptr src)
ACE_CDR::WChar WChar
WChar * wscpy(WChar *, const WChar *)
#define TAO_END_VERSIONED_NAMESPACE_DECL