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