Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

FILE_Addr.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: FILE_Addr.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $
00003 
00004 #include "ace/FILE_Addr.h"
00005 #include "ace/Log_Msg.h"
00006 
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/FILE_Addr.i"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 ACE_RCSID(ace, FILE_Addr, "$Id: FILE_Addr.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:21 chad Exp $")
00012 
00013 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Addr)
00014 
00015 ACE_FILE_Addr::ACE_FILE_Addr (void)
00016   : ACE_Addr (AF_FILE, sizeof this->filename_ / sizeof (ACE_TCHAR))
00017 {
00018   this->filename_[0] = '\0';
00019 }
00020 
00021 int
00022 ACE_FILE_Addr::set (const ACE_FILE_Addr &sa)
00023 {
00024   if (sa.get_type () == AF_ANY)
00025     {
00026 #if defined (ACE_DEFAULT_TEMP_FILE)
00027       // Create a temporary file.
00028       ACE_OS::strcpy (this->filename_,
00029                       ACE_DEFAULT_TEMP_FILE);
00030 #else /* ACE_DEFAULT_TEMP_FILE */
00031       if (ACE_Lib_Find::get_temp_dir (this->filename_,
00032                                       MAXPATHLEN - 15) == -1)
00033         // -15 for ace-file-XXXXXX
00034         {
00035           ACE_ERROR ((LM_ERROR,
00036                       ACE_LIB_TEXT ("Temporary path too long, ")
00037                       ACE_LIB_TEXT ("defaulting to current directory\n")));
00038           this->filename_[0] = 0;
00039         }
00040 
00041       // Add the filename to the end
00042       ACE_OS::strcat (this->filename_, ACE_LIB_TEXT ("ace-fileXXXXXX"));
00043 
00044 #endif /* ACE_DEFAULT_TEMP_FILE */
00045 
00046       if (ACE_OS::mktemp (this->filename_) == 0)
00047         return -1;
00048       this->base_set (AF_FILE,
00049                       ACE_static_cast (int,
00050                                        ACE_OS::strlen (this->filename_) + 1));
00051     }
00052   else
00053     {
00054       (void) ACE_OS::strsncpy (this->filename_,
00055                                sa.filename_,
00056                                sa.get_size ());
00057 
00058       this->base_set (sa.get_type (),
00059                       sa.get_size ());
00060     }
00061   return 0;
00062 }
00063 
00064 // Copy constructor.
00065 
00066 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
00067   : ACE_Addr (AF_FILE, sizeof this->filename_)
00068 {
00069   this->set (sa);
00070 }
00071 
00072 int
00073 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
00074 {
00075   this->ACE_Addr::base_set (AF_FILE,
00076                             ACE_static_cast (int,
00077                                              ACE_OS::strlen (filename) + 1));
00078   (void) ACE_OS::strsncpy (this->filename_,
00079                            filename,
00080                            sizeof this->filename_ / sizeof (ACE_TCHAR));
00081   return 0;
00082 }
00083 
00084 ACE_FILE_Addr &
00085 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
00086 {
00087   if (this != &sa)
00088     this->set (sa);
00089   return *this;
00090 }
00091 
00092 // Create a ACE_Addr from a ACE_FILE pathname.
00093 
00094 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
00095 {
00096   this->set (filename);
00097 }
00098 
00099 int
00100 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
00101 {
00102   ACE_OS::strsncpy (s, this->filename_, len);
00103   return 0;
00104 }
00105 
00106 void
00107 ACE_FILE_Addr::dump (void) const
00108 {
00109   ACE_TRACE ("ACE_FILE_Addr::dump");
00110 
00111   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00112   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("filename_ = %s"), this->filename_));
00113   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00114 }

Generated on Mon Jun 16 11:19:41 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002