Initial Patch of Auction House bot rev. 135
[auctionmangos.git] / dep / ACE_wrappers / ace / FILE_Addr.cpp
blob6d8fbeb775b05f9964b6e59db44c84ed92f3dde8
1 // $Id: FILE_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/FILE_Addr.h"
4 #include "ace/Lib_Find.h"
5 #include "ace/Log_Msg.h"
6 #include "ace/OS_NS_stdlib.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/os_include/sys/os_socket.h"
10 #if !defined (__ACE_INLINE__)
11 #include "ace/FILE_Addr.inl"
12 #endif /* __ACE_INLINE__ */
14 ACE_RCSID(ace, FILE_Addr, "$Id: FILE_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $")
16 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
18 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Addr)
20 ACE_FILE_Addr::ACE_FILE_Addr (void)
21 : ACE_Addr (AF_FILE, sizeof this->filename_ / sizeof (ACE_TCHAR))
23 this->filename_[0] = '\0';
26 int
27 ACE_FILE_Addr::set (const ACE_FILE_Addr &sa)
29 if (sa.get_type () == AF_ANY)
31 #if defined (ACE_DEFAULT_TEMP_FILE)
32 // Create a temporary file.
33 ACE_OS::strcpy (this->filename_,
34 ACE_DEFAULT_TEMP_FILE);
35 #else /* ACE_DEFAULT_TEMP_FILE */
36 if (ACE::get_temp_dir (this->filename_, MAXPATHLEN - 15) == -1)
37 // -15 for ace-file-XXXXXX
39 ACE_ERROR ((LM_ERROR,
40 ACE_TEXT ("Temporary path too long, ")
41 ACE_TEXT ("defaulting to current directory\n")));
42 this->filename_[0] = 0;
45 // Add the filename to the end
46 ACE_OS::strcat (this->filename_, ACE_TEXT ("ace-fileXXXXXX"));
48 #endif /* ACE_DEFAULT_TEMP_FILE */
50 if (ACE_OS::mktemp (this->filename_) == 0)
51 return -1;
52 this->base_set (AF_FILE,
53 static_cast<int> (ACE_OS::strlen (this->filename_) + 1));
55 else
57 (void)ACE_OS::strsncpy (this->filename_, sa.filename_, sa.get_size ());
59 this->base_set (sa.get_type (), sa.get_size ());
61 return 0;
64 // Copy constructor.
66 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
67 : ACE_Addr (AF_FILE, sizeof this->filename_)
69 this->set (sa);
72 int
73 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
75 this->ACE_Addr::base_set (AF_FILE,
76 static_cast<int> (ACE_OS::strlen (filename) + 1));
77 (void) ACE_OS::strsncpy (this->filename_,
78 filename,
79 sizeof this->filename_ / sizeof (ACE_TCHAR));
80 return 0;
83 ACE_FILE_Addr &
84 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
86 if (this != &sa)
87 this->set (sa);
88 return *this;
91 // Create a ACE_Addr from a ACE_FILE pathname.
93 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
95 this->set (filename);
98 int
99 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
101 ACE_OS::strsncpy (s, this->filename_, len);
102 return 0;
105 // Return the address.
107 void *
108 ACE_FILE_Addr::get_addr (void) const
110 return (void *)&this->filename_;
113 void
114 ACE_FILE_Addr::dump (void) const
116 #if defined (ACE_HAS_DUMP)
117 ACE_TRACE ("ACE_FILE_Addr::dump");
119 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
120 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("filename_ = %s"), this->filename_));
121 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
122 #endif /* ACE_HAS_DUMP */
124 ACE_END_VERSIONED_NAMESPACE_DECL