Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / SPIPE_Addr.cpp
blobcd91eaf27f51ec4a5bbac5e76caabd139b1e9e8f
1 #include "ace/SPIPE_Addr.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/os_include/sys/os_socket.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/SPIPE_Addr.inl"
8 #endif /* __ACE_INLINE__ */
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Addr)
14 void
15 ACE_SPIPE_Addr::dump () const
19 // Set a pointer to the address.
20 void
21 ACE_SPIPE_Addr::set_addr (const void *addr, int len)
23 ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
25 this->ACE_Addr::base_set (AF_SPIPE, len);
26 ACE_OS::memcpy (&this->SPIPE_addr_, addr, len);
29 // Return the address.
30 void *
31 ACE_SPIPE_Addr::get_addr () const
33 return (void *) &this->SPIPE_addr_;
36 // Do nothing constructor.
37 ACE_SPIPE_Addr::ACE_SPIPE_Addr ()
38 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
40 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
42 sizeof this->SPIPE_addr_);
45 int
46 ACE_SPIPE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
48 ACE_OS::strsncpy (s,
49 this->SPIPE_addr_.rendezvous_,
50 len);
51 return 0;
54 // Transform the string into the current addressing format.
55 int
56 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR *addr)
58 return this->set (addr);
61 int
62 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr &sa)
64 this->base_set (sa.get_type (), sa.get_size ());
66 if (sa.get_type () == AF_ANY)
67 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_,
69 sizeof this->SPIPE_addr_);
70 else
71 (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_, (void *)
72 &sa.SPIPE_addr_,
73 sa.get_size ());
74 return 0;
77 // Copy constructor.
78 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr &sa)
79 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
81 this->set (sa);
84 int
85 ACE_SPIPE_Addr::set (const ACE_TCHAR *addr,
86 gid_t gid,
87 uid_t uid)
89 int len = sizeof (this->SPIPE_addr_.uid_);
90 len += sizeof (this->SPIPE_addr_.gid_);
92 #if defined (ACE_WIN32)
93 const ACE_TCHAR *colonp = ACE_OS::strchr (addr, ':');
94 ACE_TCHAR temp[BUFSIZ];
96 if (colonp == 0) // Assume it's a local name.
98 ACE_OS::strcpy (temp, ACE_TEXT ( "\\\\.\\pipe\\"));
99 ACE_OS::strcat (temp, addr);
101 else
103 if (ACE_OS::strncmp (addr,
104 ACE_TEXT ("localhost"),
105 ACE_OS::strlen ("localhost")) == 0)
106 // change "localhost" to "."
107 ACE_OS::strcpy (temp, ACE_TEXT ("\\\\."));
108 else
110 ACE_OS::strcpy (temp, ACE_TEXT ("\\\\"));
112 ACE_TCHAR *t;
114 // We need to allocate a duplicate so that we can write a
115 // NUL character into it.
116 ACE_ALLOCATOR_RETURN (t, ACE_OS::strdup (addr), -1);
118 t[colonp - addr] = ACE_TEXT ('\0');
119 ACE_OS::strcat (temp, t);
121 ACE_OS::free (t);
124 ACE_OS::strcat (temp, ACE_TEXT ("\\pipe\\"));
125 ACE_OS::strcat (temp, colonp + 1);
127 len += static_cast<int> (ACE_OS::strlen (temp));
128 this->ACE_Addr::base_set (AF_SPIPE, len);
130 ACE_OS::strcpy (this->SPIPE_addr_.rendezvous_, temp);
131 #else
132 this->ACE_Addr::base_set (AF_SPIPE,
133 ACE_OS::strlen (addr) + 1 + len);
134 ACE_OS::strsncpy (this->SPIPE_addr_.rendezvous_,
135 addr,
136 sizeof this->SPIPE_addr_.rendezvous_);
137 #endif /* ACE_WIN32 */
138 this->SPIPE_addr_.gid_ = gid == 0 ? ACE_OS::getgid () : gid;
139 this->SPIPE_addr_.uid_ = uid == 0 ? ACE_OS::getuid () : uid;
140 return 0;
143 // Create a ACE_Addr from a ACE_SPIPE pathname.
144 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR *addr,
145 gid_t gid,
146 uid_t uid)
147 : ACE_Addr (AF_SPIPE, sizeof this->SPIPE_addr_)
149 this->set (addr, gid, uid);
152 ACE_END_VERSIONED_NAMESPACE_DECL