LCOV - code coverage report
Current view: top level - common - utils.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 0 3 0.0 %
Date: 2011-08-21 Functions: 0 2 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* utils.h: Various useful utilities
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2002 Ananova Ltd
       5                 :            :  * Copyright 2003,2004,2005,2006,2007,2009 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #ifndef OM_HGUARD_UTILS_H
      24                 :            : #define OM_HGUARD_UTILS_H
      25                 :            : 
      26                 :            : #include <xapian/visibility.h>
      27                 :            : 
      28                 :            : #include <string>
      29                 :            : using std::string;
      30                 :            : 
      31                 :            : #include <cstdlib>
      32                 :            : #include <sys/types.h>
      33                 :            : #include "safesysstat.h"
      34                 :            : #include "safeunistd.h"
      35                 :            : 
      36                 :            : /** Return true if the file fname exists.
      37                 :            :  */
      38                 :            : XAPIAN_VISIBILITY_DEFAULT
      39                 :            : bool file_exists(const string &fname);
      40                 :            : 
      41                 :            : /** Return true if the directory dirname exists.
      42                 :            :  */
      43                 :            : XAPIAN_VISIBILITY_DEFAULT
      44                 :            : bool dir_exists(const string &dirname);
      45                 :            : 
      46                 :            : /// Allow unlink to work directly on C++ strings.
      47                 :          0 : inline int unlink(const string &filename) { return unlink(filename.c_str()); }
      48                 :            : 
      49                 :            : /// Allow system to work directly on C++ strings.
      50                 :            : inline int system(const string &command) { return system(command.c_str()); }
      51                 :            : 
      52                 :            : /// Allow mkdir to work directly on C++ strings.
      53                 :            : inline int mkdir(const string &filename, mode_t mode) {
      54                 :            :     return mkdir(filename.c_str(), mode);
      55                 :            : }
      56                 :            : 
      57                 :            : /// Allow stat to work directly on C++ strings.
      58                 :          0 : inline int stat(const string &filename, struct stat *buf) {
      59                 :          0 :     return stat(filename.c_str(), buf);
      60                 :            : }
      61                 :            : 
      62                 :            : /** Remove a directory, and its contents.
      63                 :            :  *
      64                 :            :  *  If dirname doesn't refer to a file or directory, no error is generated.
      65                 :            :  *
      66                 :            :  *  Note - this doesn't currently cope with directories which contain
      67                 :            :  *  subdirectories.
      68                 :            :  */
      69                 :            : void removedir(const string &dirname);
      70                 :            : 
      71                 :            : namespace Xapian {
      72                 :            :     namespace Internal {
      73                 :            :         bool within_DBL_EPSILON(double a, double b);
      74                 :            :     }
      75                 :            : }
      76                 :            : 
      77                 :            : /** A tiny class used to close a filehandle safely in the presence
      78                 :            :  *  of exceptions.
      79                 :            :  */
      80                 :            : class fdcloser {
      81                 :            :     public:
      82                 :            :         fdcloser(int fd_) : fd(fd_) {}
      83                 :            :         ~fdcloser() {
      84                 :            :             if (fd >= 0) {
      85                 :            :                 (void)close(fd);
      86                 :            :             }
      87                 :            :         }
      88                 :            :     private:
      89                 :            :         int fd;
      90                 :            : };
      91                 :            : 
      92                 :            : #endif /* OM_HGUARD_UTILS_H */

Generated by: LCOV version 1.8