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';
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.
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)
54 this->base_set (AF_FILE
,
55 static_cast<int> (ACE_OS::strlen (this->filename_
) + 1));
56 #endif /* ACE_DISABLE_MKTEMP */
60 (void)ACE_OS::strsncpy (this->filename_
, sa
.filename_
, sa
.get_size ());
62 this->base_set (sa
.get_type (), sa
.get_size ());
69 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr
&sa
)
70 : ACE_Addr (AF_FILE
, sizeof this->filename_
)
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_
,
82 sizeof this->filename_
/ sizeof (ACE_TCHAR
));
87 ACE_FILE_Addr::operator= (const ACE_FILE_Addr
&sa
)
94 // Create a ACE_Addr from a ACE_FILE pathname.
96 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR
*filename
)
102 ACE_FILE_Addr::addr_to_string (ACE_TCHAR
*s
, size_t len
) const
104 ACE_OS::strsncpy (s
, this->filename_
, len
);
108 // Return the address.
111 ACE_FILE_Addr::get_addr () const
113 return (void *)&this->filename_
;
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