Correct feature names
[ACE_TAO.git] / ACE / ace / FILE_Addr.cpp
blob9d043f5fcfdad73adecc0826e164cde1993d742f
1 #include "ace/FILE_Addr.h"
2 #include "ace/Lib_Find.h"
3 #include "ace/Log_Category.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/os_include/sys/os_socket.h"
8 #if !defined (__ACE_INLINE__)
9 #include "ace/FILE_Addr.inl"
10 #endif /* __ACE_INLINE__ */
14 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Addr)
18 ACE_FILE_Addr::ACE_FILE_Addr (void)
19 : ACE_Addr (AF_FILE, sizeof this->filename_ / sizeof (ACE_TCHAR))
21 this->filename_[0] = '\0';
24 int
25 ACE_FILE_Addr::set (const ACE_FILE_Addr &sa)
27 if (sa.get_type () == AF_ANY)
29 #if defined (ACE_DISABLE_MKTEMP)
30 // Built without mktemp support; punt back to caller.
31 errno = ENOTSUP;
32 return -1;
33 #else
35 # if defined (ACE_DEFAULT_TEMP_FILE)
36 // Create a temporary file.
37 ACE_OS::strcpy (this->filename_,
38 ACE_DEFAULT_TEMP_FILE);
39 # else /* ACE_DEFAULT_TEMP_FILE */
40 if (ACE::get_temp_dir (this->filename_, MAXPATHLEN - 15) == -1)
41 // -15 for ace-file-XXXXXX
43 ACELIB_ERROR ((LM_ERROR,
44 ACE_TEXT ("Temporary path too long, ")
45 ACE_TEXT ("defaulting to current directory\n")));
46 this->filename_[0] = 0;
49 // Add the filename to the end
50 ACE_OS::strcat (this->filename_, ACE_TEXT ("ace-fileXXXXXX"));
52 # endif /* ACE_DEFAULT_TEMP_FILE */
54 if (ACE_OS::mktemp (this->filename_) == 0)
55 return -1;
56 this->base_set (AF_FILE,
57 static_cast<int> (ACE_OS::strlen (this->filename_) + 1));
58 #endif /* ACE_DISABLE_MKTEMP */
60 else
62 (void)ACE_OS::strsncpy (this->filename_, sa.filename_, sa.get_size ());
64 this->base_set (sa.get_type (), sa.get_size ());
66 return 0;
69 // Copy constructor.
71 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
72 : ACE_Addr (AF_FILE, sizeof this->filename_)
74 this->set (sa);
77 int
78 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
80 this->ACE_Addr::base_set (AF_FILE,
81 static_cast<int> (ACE_OS::strlen (filename) + 1));
82 (void) ACE_OS::strsncpy (this->filename_,
83 filename,
84 sizeof this->filename_ / sizeof (ACE_TCHAR));
85 return 0;
88 ACE_FILE_Addr &
89 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
91 if (this != &sa)
92 this->set (sa);
93 return *this;
96 // Create a ACE_Addr from a ACE_FILE pathname.
98 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
100 this->set (filename);
104 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
106 ACE_OS::strsncpy (s, this->filename_, len);
107 return 0;
110 // Return the address.
112 void *
113 ACE_FILE_Addr::get_addr (void) const
115 return (void *)&this->filename_;
118 void
119 ACE_FILE_Addr::dump (void) const
121 #if defined (ACE_HAS_DUMP)
122 ACE_TRACE ("ACE_FILE_Addr::dump");
124 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
125 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("filename_ = %s"), this->filename_));
126 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
127 #endif /* ACE_HAS_DUMP */
129 ACE_END_VERSIONED_NAMESPACE_DECL