libzypp  10.5.0
Fd.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 extern "C"
00013 {
00014 #include <sys/types.h>
00015 #include <sys/stat.h>
00016 #include <fcntl.h>
00017 }
00018 
00019 #include <iostream>
00020 
00021 #include "zypp/base/Exception.h"
00022 #include "zypp/base/Fd.h"
00023 
00025 namespace zypp
00026 { 
00027 
00028   namespace base
00029   { 
00030 
00032     //
00033     //  METHOD NAME : Fd::Fd
00034     //  METHOD TYPE : Ctor
00035     //
00036     Fd::Fd( const Pathname & file_r, int open_flags, mode_t mode )
00037     : m_fd( -1 )
00038     {
00039       m_fd = open( file_r.asString().c_str(), open_flags, mode );
00040       if ( m_fd == -1 )
00041         ZYPP_THROW_ERRNO_MSG( Exception, std::string("open ")+file_r.asString() );
00042     }
00043 
00045     //
00046     //  METHOD NAME : Fd::close
00047     //  METHOD TYPE : void
00048     //
00049     void Fd::close()
00050     {
00051       if ( m_fd != -1 )
00052         {
00053           ::close( m_fd );
00054           m_fd = -1;
00055         }
00056     }
00057 
00059   } // namespace base
00062 } // namespace zypp