LCOV - code coverage report
Current view: top level - rdbmaker/source/codemaker - global.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 55 40.0 %
Date: 2012-08-25 Functions: 5 10 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 63 30.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : #include <osl/process.h>
      20                 :            : #include <rtl/strbuf.hxx>
      21                 :            : #include <rtl/ustring.hxx>
      22                 :            : #include    <osl/thread.h>
      23                 :            : #include    <osl/file.hxx>
      24                 :            : 
      25                 :            : #include <stdlib.h>
      26                 :            : #include <stdio.h>
      27                 :            : #if defined(SAL_W32)
      28                 :            : #include <io.h>
      29                 :            : #include <direct.h>
      30                 :            : #include <errno.h>
      31                 :            : #endif
      32                 :            : 
      33                 :            : #ifdef UNX
      34                 :            : #include <sys/stat.h>
      35                 :            : #include <errno.h>
      36                 :            : #include <unistd.h>
      37                 :            : #endif
      38                 :            : #include    <codemaker/global.hxx>
      39                 :            : 
      40                 :            : #ifdef SAL_UNX
      41                 :            : #define SEPARATOR '/'
      42                 :            : #else
      43                 :            : #define SEPARATOR '\\'
      44                 :            : #endif
      45                 :            : 
      46                 :            : using namespace ::rtl;
      47                 :            : using namespace ::osl;
      48                 :            : 
      49                 :        960 : const OString inGlobalSet(const OUString & rValue)
      50                 :            : {
      51         [ +  - ]:        960 :     OString sValue( OUStringToOString(rValue, RTL_TEXTENCODING_UTF8) );
      52 [ +  + ][ +  - ]:        960 :     static StringSet aGlobalMap;
         [ +  - ][ #  # ]
      53         [ +  - ]:        960 :     StringSet::iterator iter = aGlobalMap.find( sValue );
      54         [ +  + ]:        960 :     if( iter != aGlobalMap.end() )
      55                 :        800 :         return *iter;
      56         [ +  - ]:        960 :     return *(aGlobalMap.insert( sValue ).first);
      57                 :            : }
      58                 :            : 
      59                 :          2 : static sal_Bool isFileUrl(const OString& fileName)
      60                 :            : {
      61         [ -  + ]:          2 :     if (fileName.indexOf("file://") == 0 )
      62                 :          0 :         return sal_True;
      63                 :          2 :     return sal_False;
      64                 :            : }
      65                 :            : 
      66                 :          2 : OUString convertToFileUrl(const OString& fileName)
      67                 :            : {
      68 [ +  - ][ -  + ]:          2 :     if ( isFileUrl(fileName) )
      69                 :            :     {
      70 [ #  # ][ #  # ]:          0 :         return OStringToOUString(fileName, osl_getThreadTextEncoding());
      71                 :            :     }
      72                 :            : 
      73                 :          2 :     OUString uUrlFileName;
      74 [ +  - ][ +  - ]:          2 :     OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding());
      75 [ +  - ][ -  + ]:          2 :     if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 )
                 [ -  + ]
      76                 :            :     {
      77                 :          0 :         OUString uWorkingDir;
      78         [ #  # ]:          0 :         if (osl_getProcessWorkingDir(&uWorkingDir.pData) != osl_Process_E_None) {
      79                 :            :             OSL_ASSERT(false);
      80                 :            :         }
      81         [ #  # ]:          0 :         if (FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName)
      82                 :            :             != FileBase::E_None)
      83                 :            :         {
      84                 :            :             OSL_ASSERT(false);
      85                 :          0 :         }
      86                 :            :     } else
      87                 :            :     {
      88         [ +  - ]:          2 :         if (FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName)
      89                 :            :             != FileBase::E_None)
      90                 :            :         {
      91                 :            :             OSL_ASSERT(false);
      92                 :            :         }
      93                 :            :     }
      94                 :            : 
      95                 :          2 :     return uUrlFileName;
      96                 :            : }
      97                 :            : 
      98                 :            : //*************************************************************************
      99                 :            : // FileStream
     100                 :            : //*************************************************************************
     101                 :          2 : FileStream::FileStream()
     102                 :            : {
     103                 :          2 : }
     104                 :            : 
     105                 :          0 : FileStream::~FileStream()
     106                 :            : {
     107         [ #  # ]:          0 :     if ( isValid() )
     108                 :            :     {
     109         [ #  # ]:          0 :         fflush(m_pFile);
     110         [ #  # ]:          0 :         fclose(m_pFile);
     111                 :            :     }
     112         [ #  # ]:          0 : }
     113                 :            : 
     114                 :          2 : sal_Bool FileStream::isValid()
     115                 :            : {
     116         [ -  + ]:          2 :     if ( m_pFile )
     117                 :          0 :         return sal_True;
     118                 :            : 
     119                 :          2 :     return sal_False;
     120                 :            : }
     121                 :            : 
     122                 :          0 : void FileStream::open(const OString& name, FileAccessMode mode)
     123                 :            : {
     124         [ #  # ]:          0 :     if ( !name.isEmpty() )
     125                 :            :     {
     126                 :          0 :         m_name = name;
     127                 :          0 :         m_pFile = fopen(m_name.getStr(), checkAccessMode(mode));
     128                 :            :     }
     129                 :          0 : }
     130                 :            : 
     131                 :          0 : void FileStream::close()
     132                 :            : {
     133         [ #  # ]:          0 :     if ( isValid() )
     134                 :            :     {
     135                 :          0 :         fflush(m_pFile);
     136                 :          0 :         fclose(m_pFile);
     137                 :          0 :         m_pFile = NULL;
     138                 :          0 :         m_name = OString();
     139                 :            :     }
     140                 :          0 : }
     141                 :            : 
     142                 :          0 : const sal_Char* FileStream::checkAccessMode(FileAccessMode mode)
     143                 :            : {
     144   [ #  #  #  #  :          0 :     switch( mode )
                #  #  # ]
     145                 :            :     {
     146                 :            :     case FAM_READ:
     147                 :          0 :         return "r";
     148                 :            :     case FAM_WRITE:
     149                 :          0 :         return "w";
     150                 :            :     case FAM_APPEND:
     151                 :          0 :         return "a";
     152                 :            :     case FAM_READWRITE_EXIST:
     153                 :          0 :         return "r+";
     154                 :            :     case FAM_READWRITE:
     155                 :          0 :         return "w+";
     156                 :            :     case FAM_READAPPEND:
     157                 :          0 :         return "a+";
     158                 :            :     }
     159                 :          0 :     return "w+";
     160                 :            : }
     161                 :            : 
     162                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10