LCOV - code coverage report
Current view: top level - sal/osl/unx - uunxapi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 21 90.5 %
Date: 2012-08-25 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            :  #include "uunxapi.h"
      30                 :            :  #include "system.h"
      31                 :            :  #include <limits.h>
      32                 :            :  #include <rtl/ustring.hxx>
      33                 :            :  #include <osl/thread.h>
      34                 :            : 
      35                 :            :  #ifdef ANDROID
      36                 :            :  #include <osl/detail/android-bootstrap.h>
      37                 :            :  #endif
      38                 :            : 
      39                 :            :  //###########################
      40                 :     289287 :  inline rtl::OString OUStringToOString(const rtl_uString* s)
      41                 :            :  {
      42                 :            :     return rtl::OUStringToOString(
      43                 :            :         rtl::OUString(const_cast<rtl_uString*>(s)),
      44         [ +  - ]:     289287 :         osl_getThreadTextEncoding());
      45                 :            :  }
      46                 :            : 
      47                 :            :  //###########################
      48                 :            : #ifdef MACOSX
      49                 :            : /*
      50                 :            :  * Helper function for resolving Mac native alias files (not the same as unix alias files)
      51                 :            :  * and to return the resolved alias as rtl::OString
      52                 :            :  */
      53                 :            :  inline rtl::OString macxp_resolveAliasAndConvert(const rtl_uString* s)
      54                 :            :  {
      55                 :            :   rtl::OString p = OUStringToOString(s);
      56                 :            :   sal_Char path[PATH_MAX];
      57                 :            :   if (p.getLength() < PATH_MAX)
      58                 :            :     {
      59                 :            :       strcpy(path, p.getStr());
      60                 :            :       macxp_resolveAlias(path, PATH_MAX);
      61                 :            :       p = rtl::OString(path);
      62                 :            :     }
      63                 :            :   return p;
      64                 :            :  }
      65                 :            : #endif /* MACOSX */
      66                 :            : 
      67                 :            :  //###########################
      68                 :            :  //access_u
      69                 :     201616 :  int access_u(const rtl_uString* pustrPath, int mode)
      70                 :            :  {
      71                 :            : #ifndef MACOSX // not MACOSX
      72         [ +  - ]:     201616 :     rtl::OString fn = OUStringToOString(pustrPath);
      73                 :            : #ifdef ANDROID
      74                 :            :     if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
      75                 :            :         (fn.getStr()[sizeof("/assets")-1] == '\0' ||
      76                 :            :          fn.getStr()[sizeof("/assets")-1] == '/'))
      77                 :            :     {
      78                 :            :         struct stat stat;
      79                 :            :         if (lo_apk_lstat(fn.getStr(), &stat) == -1)
      80                 :            :             return -1;
      81                 :            :         if (mode & W_OK)
      82                 :            :         {
      83                 :            :             errno = EACCES;
      84                 :            :             return -1;
      85                 :            :         }
      86                 :            :         return 0;
      87                 :            :     }
      88                 :            : #endif
      89                 :     201616 :     return access(fn.getStr(), mode);
      90                 :            : #else
      91                 :            :     return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode);
      92                 :            : #endif
      93                 :            :  }
      94                 :            : 
      95                 :            :  //#########################
      96                 :            :  //realpath_u
      97                 :       4672 :  sal_Bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName)
      98                 :            :  {
      99                 :            : #ifndef MACOSX // not MACOSX
     100         [ +  - ]:       4672 :     rtl::OString fn = OUStringToOString(pustrFileName);
     101                 :            : #ifdef ANDROID
     102                 :            :     if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 &&
     103                 :            :         (fn.getStr()[sizeof("/assets")-1] == '\0' ||
     104                 :            :          fn.getStr()[sizeof("/assets")-1] == '/'))
     105                 :            :     {
     106                 :            :         if (access_u(pustrFileName, F_OK) == -1)
     107                 :            :             return sal_False;
     108                 :            : 
     109                 :            :         rtl_uString silly(*pustrFileName);
     110                 :            :         rtl_uString_assign(ppustrResolvedName, &silly);
     111                 :            : 
     112                 :            :         return sal_True;
     113                 :            :     }
     114                 :            : #endif
     115                 :            : #else
     116                 :            :     rtl::OString fn = macxp_resolveAliasAndConvert(pustrFileName);
     117                 :            : #endif
     118                 :            :     char  rp[PATH_MAX];
     119                 :       4672 :     bool  bRet = realpath(fn.getStr(), rp);
     120                 :            : 
     121         [ +  - ]:       4672 :     if (bRet)
     122                 :            :     {
     123                 :            :         rtl::OUString resolved = rtl::OStringToOUString(
     124                 :            :             rtl::OString(static_cast<sal_Char*>(rp)),
     125 [ +  - ][ +  - ]:       4672 :             osl_getThreadTextEncoding());
     126                 :            : 
     127                 :       4672 :         rtl_uString_assign(ppustrResolvedName, resolved.pData);
     128                 :            :     }
     129                 :       4672 :     return bRet;
     130                 :            :  }
     131                 :            : 
     132                 :            :  //#########################
     133                 :            :  //stat_c
     134                 :          0 :   int stat_c(const char* cpPath, struct stat* buf)
     135                 :            :  {
     136                 :            : #ifdef ANDROID
     137                 :            :     if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
     138                 :            :         (cpPath[sizeof("/assets")-1] == '\0' ||
     139                 :            :          cpPath[sizeof("/assets")-1] == '/'))
     140                 :            :         return lo_apk_lstat(cpPath, buf);
     141                 :            : #endif
     142                 :          0 :     return stat(cpPath, buf);
     143                 :            :  }
     144                 :            : 
     145                 :            :  //#########################
     146                 :            :  //lstat_c
     147                 :      95425 :   int lstat_c(const char* cpPath, struct stat* buf)
     148                 :            :  {
     149                 :            : #ifdef ANDROID
     150                 :            :     if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 &&
     151                 :            :         (cpPath[sizeof("/assets")-1] == '\0' ||
     152                 :            :          cpPath[sizeof("/assets")-1] == '/'))
     153                 :            :         return lo_apk_lstat(cpPath, buf);
     154                 :            : #endif
     155                 :      95425 :     return lstat(cpPath, buf);
     156                 :            :  }
     157                 :            : 
     158                 :            :  //#########################
     159                 :            :  //lstat_u
     160                 :      79600 :   int lstat_u(const rtl_uString* pustrPath, struct stat* buf)
     161                 :            :  {
     162                 :            : #ifndef MACOSX  // not MACOSX
     163         [ +  - ]:      79600 :     rtl::OString fn = OUStringToOString(pustrPath);
     164                 :      79600 :     return lstat_c(fn.getStr(), buf);
     165                 :            : #else
     166                 :            :     return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf);
     167                 :            : #endif
     168                 :            :  }
     169                 :            : 
     170                 :            :  //#########################
     171                 :            :  // @see mkdir
     172                 :       3399 :  int mkdir_u(const rtl_uString* path, mode_t mode)
     173                 :            :  {
     174                 :       3399 :     return mkdir(OUStringToOString(path).getStr(), mode);
     175                 :            :  }
     176                 :            : 
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10