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';
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
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)
52 this->base_set (AF_FILE
,
53 static_cast<int> (ACE_OS::strlen (this->filename_
) + 1));
57 (void)ACE_OS::strsncpy (this->filename_
, sa
.filename_
, sa
.get_size ());
59 this->base_set (sa
.get_type (), sa
.get_size ());
66 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr
&sa
)
67 : ACE_Addr (AF_FILE
, sizeof this->filename_
)
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_
,
79 sizeof this->filename_
/ sizeof (ACE_TCHAR
));
84 ACE_FILE_Addr::operator= (const ACE_FILE_Addr
&sa
)
91 // Create a ACE_Addr from a ACE_FILE pathname.
93 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR
*filename
)
99 ACE_FILE_Addr::addr_to_string (ACE_TCHAR
*s
, size_t len
) const
101 ACE_OS::strsncpy (s
, this->filename_
, len
);
105 // Return the address.
108 ACE_FILE_Addr::get_addr (void) const
110 return (void *)&this->filename_
;
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