FILE.cpp

Go to the documentation of this file.
00001 // FILE.cpp
00002 // FILE.cpp,v 4.22 2006/06/01 13:58:41 jwillemsen Exp
00003 
00004 /* Defines the member functions for the base class of the ACE_IO_SAP
00005    ACE_FILE abstraction. */
00006 
00007 #include "ace/FILE.h"
00008 
00009 #include "ace/OS_NS_unistd.h"
00010 #include "ace/OS_NS_sys_stat.h"
00011 
00012 #if !defined (__ACE_INLINE__)
00013 #include "ace/FILE.inl"
00014 #endif /* __ACE_INLINE__ */
00015 
00016 ACE_RCSID(ace, FILE, "FILE.cpp,v 4.22 2006/06/01 13:58:41 jwillemsen Exp")
00017 
00018 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 ACE_ALLOC_HOOK_DEFINE(ACE_FILE)
00021 
00022 void
00023 ACE_FILE::dump (void) const
00024 {
00025 #if defined (ACE_HAS_DUMP)
00026   ACE_TRACE ("ACE_FILE::dump");
00027   ACE_IO_SAP::dump ();
00028 #endif /* ACE_HAS_DUMP */
00029 }
00030 
00031 // This is the do-nothing constructor.
00032 
00033 ACE_FILE::ACE_FILE (void)
00034 {
00035   ACE_TRACE ("ACE_FILE::ACE_FILE");
00036 }
00037 
00038 // Close the file
00039 
00040 int
00041 ACE_FILE::close (void)
00042 {
00043   ACE_TRACE ("ACE_FILE::close");
00044   int result = 0;
00045 
00046   if (this->get_handle () != ACE_INVALID_HANDLE)
00047     {
00048       result = ACE_OS::close (this->get_handle ());
00049       this->set_handle (ACE_INVALID_HANDLE);
00050     }
00051   return result;
00052 }
00053 
00054 int
00055 ACE_FILE::get_info (ACE_FILE_Info *finfo)
00056 {
00057   ACE_TRACE ("ACE_FILE::get_info");
00058   ACE_stat filestatus;
00059 
00060   int const result = ACE_OS::fstat (this->get_handle (),
00061                                     &filestatus);
00062 
00063   if (result == 0)
00064     {
00065       finfo->mode_ = filestatus.st_mode;
00066       finfo->nlink_ = filestatus.st_nlink;
00067       finfo->size_ = filestatus.st_size;
00068     }
00069 
00070   return result;
00071 }
00072 
00073 int
00074 ACE_FILE::get_info (ACE_FILE_Info &finfo)
00075 {
00076   ACE_TRACE ("ACE_FILE::get_info");
00077 
00078   return this->get_info (&finfo);
00079 }
00080 
00081 int
00082 ACE_FILE::truncate (off_t length)
00083 {
00084   ACE_TRACE ("ACE_FILE::truncate");
00085   return ACE_OS::ftruncate (this->get_handle(), length);
00086 }
00087 
00088 off_t
00089 ACE_FILE::seek (off_t offset, int startpos)
00090 {
00091   return ACE_OS::lseek (this->get_handle (),
00092                         offset,
00093                         startpos);
00094 }
00095 
00096 off_t
00097 ACE_FILE::tell (void)
00098 {
00099   ACE_TRACE ("ACE_FILE::tell");
00100   return ACE_OS::lseek (this->get_handle (), 0, SEEK_CUR);
00101 }
00102 
00103 // Return the local endpoint address.
00104 
00105 int
00106 ACE_FILE::get_local_addr (ACE_Addr &addr) const
00107 {
00108   ACE_TRACE ("ACE_FILE::get_local_addr");
00109 
00110   // Perform the downcast since <addr> had better be an
00111   // <ACE_FILE_Addr>.
00112   ACE_FILE_Addr *file_addr =
00113     dynamic_cast<ACE_FILE_Addr *> (&addr);
00114 
00115   if (file_addr == 0)
00116     return -1;
00117   else
00118     {
00119       *file_addr = this->addr_;
00120       return 0;
00121     }
00122 }
00123 
00124 // Return the same result as <get_local_addr>.
00125 
00126 int
00127 ACE_FILE::get_remote_addr (ACE_Addr &addr) const
00128 {
00129   ACE_TRACE ("ACE_FILE::get_remote_addr");
00130 
00131   return this->get_local_addr (addr);
00132 }
00133 
00134 int
00135 ACE_FILE::remove (void)
00136 {
00137   ACE_TRACE ("ACE_FILE::remove");
00138 
00139   this->close ();
00140   return ACE_OS::unlink (this->addr_.get_path_name ());
00141 }
00142 
00143 int
00144 ACE_FILE::unlink (void)
00145 {
00146   ACE_TRACE ("ACE_FILE::unlink");
00147 
00148   return ACE_OS::unlink (this->addr_.get_path_name ());
00149 }
00150 
00151 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:50 2006 for ACE by doxygen 1.3.6