Document return values
[ACE_TAO.git] / ACE / ace / FILE_Addr.cpp
blob733339af7907ea887925f7f0dc7191f24cbbb746
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__ */
12 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
14 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Addr)
16 ACE_FILE_Addr::ACE_FILE_Addr ()
17 : ACE_Addr (AF_FILE, sizeof this->filename_ / sizeof (ACE_TCHAR))
19 this->filename_[0] = '\0';
22 int
23 ACE_FILE_Addr::set (const ACE_FILE_Addr &sa)
25 if (sa.get_type () == AF_ANY)
27 #if defined (ACE_DISABLE_MKTEMP)
28 // Built without mktemp support; punt back to caller.
29 errno = ENOTSUP;
30 return -1;
31 #else
33 # if defined (ACE_DEFAULT_TEMP_FILE)
34 // Create a temporary file.
35 ACE_OS::strcpy (this->filename_,
36 ACE_DEFAULT_TEMP_FILE);
37 # else /* ACE_DEFAULT_TEMP_FILE */
38 if (ACE::get_temp_dir (this->filename_, MAXPATHLEN - 15) == -1)
39 // -15 for ace-file-XXXXXX
41 ACELIB_ERROR ((LM_ERROR,
42 ACE_TEXT ("Temporary path too long, ")
43 ACE_TEXT ("defaulting to current directory\n")));
44 this->filename_[0] = 0;
47 // Add the filename to the end
48 ACE_OS::strcat (this->filename_, ACE_TEXT ("ace-fileXXXXXX"));
50 # endif /* ACE_DEFAULT_TEMP_FILE */
52 if (ACE_OS::mktemp (this->filename_) == 0)
53 return -1;
54 this->base_set (AF_FILE,
55 static_cast<int> (ACE_OS::strlen (this->filename_) + 1));
56 #endif /* ACE_DISABLE_MKTEMP */
58 else
60 (void)ACE_OS::strsncpy (this->filename_, sa.filename_, sa.get_size ());
62 this->base_set (sa.get_type (), sa.get_size ());
64 return 0;
67 // Copy constructor.
69 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
70 : ACE_Addr (AF_FILE, sizeof this->filename_)
72 this->set (sa);
75 int
76 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
78 this->ACE_Addr::base_set (AF_FILE,
79 static_cast<int> (ACE_OS::strlen (filename) + 1));
80 (void) ACE_OS::strsncpy (this->filename_,
81 filename,
82 sizeof this->filename_ / sizeof (ACE_TCHAR));
83 return 0;
86 ACE_FILE_Addr &
87 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
89 if (this != &sa)
90 this->set (sa);
91 return *this;
94 // Create a ACE_Addr from a ACE_FILE pathname.
96 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
98 this->set (filename);
102 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
104 ACE_OS::strsncpy (s, this->filename_, len);
105 return 0;
108 // Return the address.
110 void *
111 ACE_FILE_Addr::get_addr () const
113 return (void *)&this->filename_;
116 void
117 ACE_FILE_Addr::dump () const
119 #if defined (ACE_HAS_DUMP)
120 ACE_TRACE ("ACE_FILE_Addr::dump");
122 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
123 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("filename_ = %s"), this->filename_));
124 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
125 #endif /* ACE_HAS_DUMP */
127 ACE_END_VERSIONED_NAMESPACE_DECL