1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_tools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir #include <ctype.h> 33*cdf0e10cSrcweir #include <stdlib.h> 34*cdf0e10cSrcweir #include <unistd.h> 35*cdf0e10cSrcweir #include <utime.h> 36*cdf0e10cSrcweir #if defined HPUX || defined LINUX 37*cdf0e10cSrcweir #include <mntent.h> 38*cdf0e10cSrcweir #define mnttab mntent 39*cdf0e10cSrcweir #elif defined SCO 40*cdf0e10cSrcweir #include <mnttab.h> 41*cdf0e10cSrcweir #elif defined AIX 42*cdf0e10cSrcweir #include <sys/mntctl.h> 43*cdf0e10cSrcweir #include <sys/vmount.h> 44*cdf0e10cSrcweir extern "C" int mntctl( int cmd, size_t size, char* buf ); 45*cdf0e10cSrcweir #elif defined(NETBSD) 46*cdf0e10cSrcweir #include <sys/mount.h> 47*cdf0e10cSrcweir #elif defined(FREEBSD) || defined(MACOSX) 48*cdf0e10cSrcweir #elif defined DECUNIX 49*cdf0e10cSrcweir struct mnttab 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir char *mnt_dir; 52*cdf0e10cSrcweir char *mnt_fsname; 53*cdf0e10cSrcweir }; 54*cdf0e10cSrcweir #else 55*cdf0e10cSrcweir #include <sys/mnttab.h> 56*cdf0e10cSrcweir #endif 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #ifndef MAXPATHLEN 59*cdf0e10cSrcweir #define MAXPATHLEN 1024 60*cdf0e10cSrcweir #endif 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #include <tools/debug.hxx> 63*cdf0e10cSrcweir #include <tools/list.hxx> 64*cdf0e10cSrcweir #include <tools/fsys.hxx> 65*cdf0e10cSrcweir #include "comdep.hxx" 66*cdf0e10cSrcweir #include <rtl/instance.hxx> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir DECLARE_LIST( DirEntryList, DirEntry* ) 69*cdf0e10cSrcweir DECLARE_LIST( FSysSortList, FSysSort* ) 70*cdf0e10cSrcweir DECLARE_LIST( FileStatList, FileStat* ) 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #if defined SOLARIS || defined SINIX 73*cdf0e10cSrcweir #define MOUNTSPECIAL mnt_special 74*cdf0e10cSrcweir #define MOUNTPOINT mnt_mountp 75*cdf0e10cSrcweir #define MOUNTOPTS mnt_mntopts 76*cdf0e10cSrcweir #define MOUNTFS mnt_fstype 77*cdf0e10cSrcweir #elif defined SCO 78*cdf0e10cSrcweir #define MNTTAB "/etc/mnttab" 79*cdf0e10cSrcweir #define MOUNTSPECIAL mt_dev 80*cdf0e10cSrcweir #define MOUNTPOINT mt_filsys 81*cdf0e10cSrcweir #else 82*cdf0e10cSrcweir #define MOUNTSPECIAL mnt_fsname 83*cdf0e10cSrcweir #define MOUNTPOINT mnt_dir 84*cdf0e10cSrcweir #define MOUNTFS mnt_type 85*cdf0e10cSrcweir #endif 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir struct mymnttab 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir dev_t mountdevice; 90*cdf0e10cSrcweir ByteString mountspecial; 91*cdf0e10cSrcweir ByteString mountpoint; 92*cdf0e10cSrcweir ByteString mymnttab_filesystem; 93*cdf0e10cSrcweir mymnttab() { mountdevice = (dev_t) -1; } 94*cdf0e10cSrcweir }; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir #if defined(NETBSD) || defined(FREEBSD) || defined(MACOSX) 98*cdf0e10cSrcweir sal_Bool GetMountEntry(dev_t /* dev */, struct mymnttab * /* mytab */ ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir DBG_WARNING( "Sorry, not implemented: GetMountEntry" ); 101*cdf0e10cSrcweir return sal_False; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir #elif defined AIX 105*cdf0e10cSrcweir sal_Bool GetMountEntry(dev_t dev, struct mymnttab *mytab) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir int bufsize; 108*cdf0e10cSrcweir if (mntctl (MCTL_QUERY, sizeof bufsize, (char*) &bufsize)) 109*cdf0e10cSrcweir return sal_False; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir char* buffer = (char *)malloc( bufsize * sizeof(char) ); 112*cdf0e10cSrcweir if (mntctl (MCTL_QUERY, bufsize, buffer) != -1) 113*cdf0e10cSrcweir for ( char* vmt = buffer; 114*cdf0e10cSrcweir vmt < buffer + bufsize; 115*cdf0e10cSrcweir vmt += ((struct vmount*)vmt)->vmt_length) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir struct stat buf; 118*cdf0e10cSrcweir char *mountp = vmt2dataptr((struct vmount*)vmt, VMT_STUB); 119*cdf0e10cSrcweir if ((stat (mountp, &buf) != -1) && (buf.st_dev == dev)) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir mytab->mountpoint = mountp; 122*cdf0e10cSrcweir mytab->mountspecial 123*cdf0e10cSrcweir = vmt2dataptr((struct vmount*)vmt, VMT_HOSTNAME); 124*cdf0e10cSrcweir if (mytab->mountspecial.Len()) 125*cdf0e10cSrcweir mytab->mountspecial += ':'; 126*cdf0e10cSrcweir mytab->mountspecial 127*cdf0e10cSrcweir += vmt2dataptr((struct vmount*)vmt, VMT_OBJECT); 128*cdf0e10cSrcweir mytab->mountdevice = dev; 129*cdf0e10cSrcweir free( buffer ); 130*cdf0e10cSrcweir return sal_True; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir free( buffer ); 134*cdf0e10cSrcweir return sal_False; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir #else 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir static sal_Bool GetMountEntry(dev_t dev, struct mymnttab *mytab) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir #if defined SOLARIS || defined SINIX 143*cdf0e10cSrcweir FILE *fp = fopen (MNTTAB, "r"); 144*cdf0e10cSrcweir if (! fp) 145*cdf0e10cSrcweir return sal_False; 146*cdf0e10cSrcweir struct mnttab mnt[1]; 147*cdf0e10cSrcweir while (getmntent (fp, mnt) != -1) 148*cdf0e10cSrcweir #elif defined SCO 149*cdf0e10cSrcweir FILE *fp = fopen (MNTTAB, "r"); 150*cdf0e10cSrcweir if (! fp) 151*cdf0e10cSrcweir return sal_False; 152*cdf0e10cSrcweir struct mnttab mnt[1]; 153*cdf0e10cSrcweir while (fread (&mnt, sizeof mnt, 1, fp) > 0) 154*cdf0e10cSrcweir #elif defined DECUNIX || defined AIX 155*cdf0e10cSrcweir FILE *fp = NULL; 156*cdf0e10cSrcweir if (! fp) 157*cdf0e10cSrcweir return sal_False; 158*cdf0e10cSrcweir struct mnttab mnt[1]; 159*cdf0e10cSrcweir while ( 0 ) 160*cdf0e10cSrcweir #else 161*cdf0e10cSrcweir FILE *fp = setmntent (MOUNTED, "r"); 162*cdf0e10cSrcweir if (! fp) 163*cdf0e10cSrcweir return sal_False; 164*cdf0e10cSrcweir struct mnttab *mnt; 165*cdf0e10cSrcweir while ((mnt = getmntent (fp)) != NULL) 166*cdf0e10cSrcweir #endif 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir #ifdef SOLARIS 169*cdf0e10cSrcweir char *devopt = NULL; 170*cdf0e10cSrcweir if ( mnt->MOUNTOPTS != NULL ) 171*cdf0e10cSrcweir devopt = strstr (mnt->MOUNTOPTS, "dev="); 172*cdf0e10cSrcweir if (devopt) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir if (dev != (dev_t) strtoul (devopt+4, NULL, 16)) 175*cdf0e10cSrcweir continue; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir #endif 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir struct stat buf; 181*cdf0e10cSrcweir if ((stat (mnt->MOUNTPOINT, &buf) == -1) || (buf.st_dev != dev)) 182*cdf0e10cSrcweir continue; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir # ifdef LINUX 185*cdf0e10cSrcweir /* #61624# File mit setmntent oeffnen und mit fclose schliessen stoesst 186*cdf0e10cSrcweir bei der glibc-2.1 auf wenig Gegenliebe */ 187*cdf0e10cSrcweir endmntent( fp ); 188*cdf0e10cSrcweir # else 189*cdf0e10cSrcweir fclose (fp); 190*cdf0e10cSrcweir # endif 191*cdf0e10cSrcweir mytab->mountspecial = mnt->MOUNTSPECIAL; 192*cdf0e10cSrcweir mytab->mountpoint = mnt->MOUNTPOINT; 193*cdf0e10cSrcweir mytab->mountdevice = dev; 194*cdf0e10cSrcweir #ifndef SCO 195*cdf0e10cSrcweir mytab->mymnttab_filesystem = mnt->MOUNTFS; 196*cdf0e10cSrcweir #else 197*cdf0e10cSrcweir mytab->mymnttab_filesystem = "ext2"; //default ist case sensitiv unter unix 198*cdf0e10cSrcweir #endif 199*cdf0e10cSrcweir return sal_True; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir # ifdef LINUX 202*cdf0e10cSrcweir /* #61624# dito */ 203*cdf0e10cSrcweir endmntent( fp ); 204*cdf0e10cSrcweir # else 205*cdf0e10cSrcweir fclose (fp); 206*cdf0e10cSrcweir # endif 207*cdf0e10cSrcweir return sal_False; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir #endif 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir /************************************************************************ 213*cdf0e10cSrcweir |* 214*cdf0e10cSrcweir |* DirEntry::IsCaseSensitive() 215*cdf0e10cSrcweir |* 216*cdf0e10cSrcweir |* Beschreibung 217*cdf0e10cSrcweir |* Ersterstellung TPF 25.02.1999 218*cdf0e10cSrcweir |* Letzte Aenderung TPF 25.02.1999 219*cdf0e10cSrcweir |* 220*cdf0e10cSrcweir *************************************************************************/ 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir sal_Bool DirEntry::IsCaseSensitive( FSysPathStyle eFormatter ) const 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir if (eFormatter==FSYS_STYLE_HOST) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir #ifdef NETBSD 228*cdf0e10cSrcweir return sal_True; 229*cdf0e10cSrcweir #else 230*cdf0e10cSrcweir struct stat buf; 231*cdf0e10cSrcweir DirEntry aPath(*this); 232*cdf0e10cSrcweir aPath.ToAbs(); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir while (stat (ByteString(aPath.GetFull(), osl_getThreadTextEncoding()).GetBuffer(), &buf)) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir if (aPath.Level() == 1) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir return sal_True; // ich bin unter UNIX, also ist der default im Zweifelsfall case sensitiv 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir aPath = aPath [1]; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir struct mymnttab fsmnt; 244*cdf0e10cSrcweir GetMountEntry(buf.st_dev, &fsmnt); 245*cdf0e10cSrcweir if ((fsmnt.mymnttab_filesystem.CompareTo("msdos")==COMPARE_EQUAL) || 246*cdf0e10cSrcweir (fsmnt.mymnttab_filesystem.CompareTo("umsdos")==COMPARE_EQUAL) || 247*cdf0e10cSrcweir (fsmnt.mymnttab_filesystem.CompareTo("vfat")==COMPARE_EQUAL) || 248*cdf0e10cSrcweir (fsmnt.mymnttab_filesystem.CompareTo("hpfs")==COMPARE_EQUAL) || 249*cdf0e10cSrcweir (fsmnt.mymnttab_filesystem.CompareTo("smb") ==COMPARE_EQUAL) || 250*cdf0e10cSrcweir (fsmnt.mymnttab_filesystem.CompareTo("ncpfs")==COMPARE_EQUAL)) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir return sal_False; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir else 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir return sal_True; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir #endif 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir else 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir sal_Bool isCaseSensitive = sal_True; // ich bin unter UNIX, also ist der default im Zweifelsfall case sensitiv 263*cdf0e10cSrcweir switch ( eFormatter ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir case FSYS_STYLE_MAC: 266*cdf0e10cSrcweir case FSYS_STYLE_FAT: 267*cdf0e10cSrcweir case FSYS_STYLE_VFAT: 268*cdf0e10cSrcweir case FSYS_STYLE_NTFS: 269*cdf0e10cSrcweir case FSYS_STYLE_NWFS: 270*cdf0e10cSrcweir case FSYS_STYLE_HPFS: 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir isCaseSensitive = sal_False; 273*cdf0e10cSrcweir break; 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir case FSYS_STYLE_SYSV: 276*cdf0e10cSrcweir case FSYS_STYLE_BSD: 277*cdf0e10cSrcweir case FSYS_STYLE_DETECT: 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir isCaseSensitive = sal_True; 280*cdf0e10cSrcweir break; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir default: 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir isCaseSensitive = sal_True; // ich bin unter UNIX, also ist der default im Zweifelsfall case sensitiv 285*cdf0e10cSrcweir break; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir return isCaseSensitive; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir /************************************************************************ 293*cdf0e10cSrcweir |* 294*cdf0e10cSrcweir |* DirEntry::ToAbs() 295*cdf0e10cSrcweir |* 296*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 297*cdf0e10cSrcweir |* Ersterstellung MI 26.04.91 298*cdf0e10cSrcweir |* Letzte Aenderung MA 02.12.91 13:30 299*cdf0e10cSrcweir |* 300*cdf0e10cSrcweir *************************************************************************/ 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir sal_Bool DirEntry::ToAbs() 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir if ( FSYS_FLAG_VOLUME == eFlag ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir eFlag = FSYS_FLAG_ABSROOT; 307*cdf0e10cSrcweir return sal_True; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir if ( IsAbs() ) 311*cdf0e10cSrcweir return sal_True; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir char sBuf[MAXPATHLEN + 1]; 314*cdf0e10cSrcweir *this = DirEntry( String( getcwd( sBuf, MAXPATHLEN ), osl_getThreadTextEncoding() ) ) + *this; 315*cdf0e10cSrcweir return IsAbs(); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir /************************************************************************* 319*cdf0e10cSrcweir |* 320*cdf0e10cSrcweir |* DirEntry::GetVolume() 321*cdf0e10cSrcweir |* 322*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 323*cdf0e10cSrcweir |* Ersterstellung MI 04.03.92 324*cdf0e10cSrcweir |* Letzte Aenderung 325*cdf0e10cSrcweir |* 326*cdf0e10cSrcweir *************************************************************************/ 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir namespace { struct mymnt : public rtl::Static< mymnttab, mymnt > {}; } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir String DirEntry::GetVolume() const 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir DirEntry aPath( *this ); 335*cdf0e10cSrcweir aPath.ToAbs(); 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir struct stat buf; 338*cdf0e10cSrcweir while (stat (ByteString(aPath.GetFull(), osl_getThreadTextEncoding()).GetBuffer(), &buf)) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir if (aPath.Level() <= 1) 341*cdf0e10cSrcweir return String(); 342*cdf0e10cSrcweir aPath = aPath [1]; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir mymnttab &rMnt = mymnt::get(); 345*cdf0e10cSrcweir return ((buf.st_dev == rMnt.mountdevice || 346*cdf0e10cSrcweir GetMountEntry(buf.st_dev, &rMnt)) ? 347*cdf0e10cSrcweir String(rMnt.mountspecial, osl_getThreadTextEncoding()) : 348*cdf0e10cSrcweir String()); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir DirEntry DirEntry::GetDevice() const 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir DirEntry aPath( *this ); 356*cdf0e10cSrcweir aPath.ToAbs(); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir struct stat buf; 359*cdf0e10cSrcweir while (stat (ByteString(aPath.GetFull(), osl_getThreadTextEncoding()).GetBuffer(), &buf)) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir if (aPath.Level() <= 1) 362*cdf0e10cSrcweir return String(); 363*cdf0e10cSrcweir aPath = aPath [1]; 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir mymnttab &rMnt = mymnt::get(); 366*cdf0e10cSrcweir return ((buf.st_dev == rMnt.mountdevice || 367*cdf0e10cSrcweir GetMountEntry(buf.st_dev, &rMnt)) ? 368*cdf0e10cSrcweir String( rMnt.mountpoint, osl_getThreadTextEncoding()) : 369*cdf0e10cSrcweir String()); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir /************************************************************************* 373*cdf0e10cSrcweir |* 374*cdf0e10cSrcweir |* DirEntry::SetCWD() 375*cdf0e10cSrcweir |* 376*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 377*cdf0e10cSrcweir |* Ersterstellung MI 26.04.91 378*cdf0e10cSrcweir |* Letzte Aenderung DV 04.11.92 379*cdf0e10cSrcweir |* 380*cdf0e10cSrcweir *************************************************************************/ 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir sal_Bool DirEntry::SetCWD( sal_Bool bSloppy ) const 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir DBG_CHKTHIS( DirEntry, ImpCheckDirEntry ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir ByteString aPath( GetFull(), osl_getThreadTextEncoding()); 388*cdf0e10cSrcweir if ( !chdir( aPath.GetBuffer() ) ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir return sal_True; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir else 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir if ( bSloppy && !chdir(aPath.GetBuffer()) ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir return sal_True; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir else 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir return sal_False; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir //------------------------------------------------------------------------- 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir sal_uInt16 DirReader_Impl::Init() 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir return 0; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir //------------------------------------------------------------------------- 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir sal_uInt16 DirReader_Impl::Read() 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir if (!pDosDir) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir pDosDir = opendir( (char*) ByteString(aPath, osl_getThreadTextEncoding()).GetBuffer() ); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir if (!pDosDir) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir bReady = sal_True; 424*cdf0e10cSrcweir return 0; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir // Directories und Files auflisten? 428*cdf0e10cSrcweir if ( ( pDir->eAttrMask & FSYS_KIND_DIR || pDir->eAttrMask & FSYS_KIND_FILE ) && 429*cdf0e10cSrcweir ( ( pDosEntry = readdir( pDosDir ) ) != NULL ) ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir String aD_Name(pDosEntry->d_name, osl_getThreadTextEncoding()); 432*cdf0e10cSrcweir if ( pDir->aNameMask.Matches( aD_Name ) ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir DirEntryFlag eFlag = 435*cdf0e10cSrcweir 0 == strcmp( pDosEntry->d_name, "." ) ? FSYS_FLAG_CURRENT 436*cdf0e10cSrcweir : 0 == strcmp( pDosEntry->d_name, ".." ) ? FSYS_FLAG_PARENT 437*cdf0e10cSrcweir : FSYS_FLAG_NORMAL; 438*cdf0e10cSrcweir DirEntry *pTemp = new DirEntry( ByteString(pDosEntry->d_name), eFlag, FSYS_STYLE_UNX ); 439*cdf0e10cSrcweir if ( pParent ) 440*cdf0e10cSrcweir pTemp->ImpChangeParent( new DirEntry( *pParent ), sal_False); 441*cdf0e10cSrcweir FileStat aStat( *pTemp ); 442*cdf0e10cSrcweir if ( ( ( ( pDir->eAttrMask & FSYS_KIND_DIR ) && 443*cdf0e10cSrcweir ( aStat.IsKind( FSYS_KIND_DIR ) ) ) || 444*cdf0e10cSrcweir ( ( pDir->eAttrMask & FSYS_KIND_FILE ) && 445*cdf0e10cSrcweir !( aStat.IsKind( FSYS_KIND_DIR ) ) ) ) && 446*cdf0e10cSrcweir !( pDir->eAttrMask & FSYS_KIND_VISIBLE && 447*cdf0e10cSrcweir pDosEntry->d_name[0] == '.' ) ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir if ( pDir->pStatLst ) //Status fuer Sort gewuenscht? 450*cdf0e10cSrcweir pDir->ImpSortedInsert( pTemp, new FileStat( aStat ) ); 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir pDir->ImpSortedInsert( pTemp, NULL );; 453*cdf0e10cSrcweir return 1; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir else 456*cdf0e10cSrcweir delete pTemp; 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir else 460*cdf0e10cSrcweir bReady = sal_True; 461*cdf0e10cSrcweir return 0; 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir /************************************************************************* 465*cdf0e10cSrcweir |* 466*cdf0e10cSrcweir |* FileStat::FileStat() 467*cdf0e10cSrcweir |* 468*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 469*cdf0e10cSrcweir |* Ersterstellung MA 05.11.91 470*cdf0e10cSrcweir |* Letzte Aenderung MA 07.11.91 471*cdf0e10cSrcweir |* 472*cdf0e10cSrcweir *************************************************************************/ 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir FileStat::FileStat( const void *, const void * ): 475*cdf0e10cSrcweir aDateCreated(0), 476*cdf0e10cSrcweir aTimeCreated(0), 477*cdf0e10cSrcweir aDateModified(0), 478*cdf0e10cSrcweir aTimeModified(0), 479*cdf0e10cSrcweir aDateAccessed(0), 480*cdf0e10cSrcweir aTimeAccessed(0) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir /************************************************************************* 485*cdf0e10cSrcweir |* 486*cdf0e10cSrcweir |* FileStat::Update() 487*cdf0e10cSrcweir |* 488*cdf0e10cSrcweir |* Beschreibung FSYS.SDW 489*cdf0e10cSrcweir |* Ersterstellung MI 11.06.91 490*cdf0e10cSrcweir |* Letzte Aenderung MA 07.11.91 491*cdf0e10cSrcweir |* 492*cdf0e10cSrcweir *************************************************************************/ 493*cdf0e10cSrcweir sal_Bool FileStat::Update( const DirEntry& rDirEntry, sal_Bool ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir nSize = 0; 497*cdf0e10cSrcweir nKindFlags = 0; 498*cdf0e10cSrcweir aCreator.Erase(); 499*cdf0e10cSrcweir aType.Erase(); 500*cdf0e10cSrcweir aDateCreated = Date(0); 501*cdf0e10cSrcweir aTimeCreated = Time(0); 502*cdf0e10cSrcweir aDateModified = Date(0); 503*cdf0e10cSrcweir aTimeModified = Time(0); 504*cdf0e10cSrcweir aDateAccessed = Date(0); 505*cdf0e10cSrcweir aTimeAccessed = Time(0); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir if ( !rDirEntry.IsValid() ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 510*cdf0e10cSrcweir return sal_False; 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir // Sonderbehandlung falls es sich um eine Root handelt 514*cdf0e10cSrcweir if ( rDirEntry.eFlag == FSYS_FLAG_ABSROOT ) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir nKindFlags = FSYS_KIND_DIR; 517*cdf0e10cSrcweir nError = FSYS_ERR_OK; 518*cdf0e10cSrcweir return sal_True; 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir struct stat aStat; 522*cdf0e10cSrcweir ByteString aPath( rDirEntry.GetFull(), osl_getThreadTextEncoding() ); 523*cdf0e10cSrcweir if ( stat( (char*) aPath.GetBuffer(), &aStat ) ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir // pl: #67851# 526*cdf0e10cSrcweir // do this here, because an existing filename containing "wildcards" 527*cdf0e10cSrcweir // should be handled as a file, not a wildcard 528*cdf0e10cSrcweir // note that this is not a solution, since filenames containing special characters 529*cdf0e10cSrcweir // are handled badly across the whole Office 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir // Sonderbehandlung falls es sich um eine Wildcard handelt 532*cdf0e10cSrcweir ByteString aTempName( rDirEntry.GetName(), osl_getThreadTextEncoding() ); 533*cdf0e10cSrcweir if ( strchr( (char*) aTempName.GetBuffer(), '?' ) || 534*cdf0e10cSrcweir strchr( (char*) aTempName.GetBuffer(), '*' ) || 535*cdf0e10cSrcweir strchr( (char*) aTempName.GetBuffer(), ';' ) ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir nKindFlags = FSYS_KIND_WILD; 538*cdf0e10cSrcweir nError = FSYS_ERR_OK; 539*cdf0e10cSrcweir return sal_True; 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir nError = FSYS_ERR_NOTEXISTS; 543*cdf0e10cSrcweir return sal_False; 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir nError = FSYS_ERR_OK; 547*cdf0e10cSrcweir nSize = aStat.st_size; 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir nKindFlags = FSYS_KIND_UNKNOWN; 550*cdf0e10cSrcweir if ( ( aStat.st_mode & S_IFDIR ) == S_IFDIR ) 551*cdf0e10cSrcweir nKindFlags = nKindFlags | FSYS_KIND_DIR; 552*cdf0e10cSrcweir if ( ( aStat.st_mode & S_IFREG ) == S_IFREG ) 553*cdf0e10cSrcweir nKindFlags = nKindFlags | FSYS_KIND_FILE; 554*cdf0e10cSrcweir if ( ( aStat.st_mode & S_IFCHR ) == S_IFCHR ) 555*cdf0e10cSrcweir nKindFlags = nKindFlags | FSYS_KIND_DEV | FSYS_KIND_CHAR; 556*cdf0e10cSrcweir if ( ( aStat.st_mode & S_IFBLK ) == S_IFBLK ) 557*cdf0e10cSrcweir nKindFlags = nKindFlags | FSYS_KIND_DEV | FSYS_KIND_BLOCK; 558*cdf0e10cSrcweir if ( nKindFlags == FSYS_KIND_UNKNOWN ) 559*cdf0e10cSrcweir nKindFlags = nKindFlags | FSYS_KIND_FILE; 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir Unx2DateAndTime( aStat.st_ctime, aTimeCreated, aDateCreated ); 562*cdf0e10cSrcweir Unx2DateAndTime( aStat.st_mtime, aTimeModified, aDateModified ); 563*cdf0e10cSrcweir Unx2DateAndTime( aStat.st_atime, aTimeAccessed, aDateAccessed ); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir return sal_True; 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir //==================================================================== 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir const char *TempDirImpl( char *pBuf ) 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir #ifdef MACOSX 573*cdf0e10cSrcweir // P_tmpdir is /var/tmp on Mac OS X, and it is not cleaned up on system 574*cdf0e10cSrcweir // startup 575*cdf0e10cSrcweir strcpy( pBuf, "/tmp" ); 576*cdf0e10cSrcweir #else 577*cdf0e10cSrcweir const char *pValue = getenv( "TEMP" ); 578*cdf0e10cSrcweir if ( !pValue ) 579*cdf0e10cSrcweir pValue = getenv( "TMP" ); 580*cdf0e10cSrcweir if ( pValue ) 581*cdf0e10cSrcweir strcpy( pBuf, pValue ); 582*cdf0e10cSrcweir else 583*cdf0e10cSrcweir // auf Solaris und Linux ist P_tmpdir vorgesehen 584*cdf0e10cSrcweir strcpy( pBuf, P_tmpdir ); 585*cdf0e10cSrcweir // hart auf "/tmp" sollte wohl nur im Notfall verwendet werden 586*cdf0e10cSrcweir //strcpy( pBuf, "/tmp" ); 587*cdf0e10cSrcweir #endif /* MACOSX */ 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir return pBuf; 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir /************************************************************************* 593*cdf0e10cSrcweir |* 594*cdf0e10cSrcweir |* DirEntry::GetPathStyle() const 595*cdf0e10cSrcweir |* 596*cdf0e10cSrcweir |* Beschreibung 597*cdf0e10cSrcweir |* Ersterstellung MI 11.05.95 598*cdf0e10cSrcweir |* Letzte Aenderung MI 11.05.95 599*cdf0e10cSrcweir |* 600*cdf0e10cSrcweir *************************************************************************/ 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir FSysPathStyle DirEntry::GetPathStyle( const String & ) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir return FSYS_STYLE_UNX; 605*cdf0e10cSrcweir } 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir /************************************************************************* 608*cdf0e10cSrcweir |* 609*cdf0e10cSrcweir |* FileStat::SetDateTime 610*cdf0e10cSrcweir |* 611*cdf0e10cSrcweir |* Ersterstellung PB 27.06.97 612*cdf0e10cSrcweir |* Letzte Aenderung 613*cdf0e10cSrcweir |* 614*cdf0e10cSrcweir *************************************************************************/ 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir void FileStat::SetDateTime( const String& rFileName, 617*cdf0e10cSrcweir const DateTime& rNewDateTime ) 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir tm times; 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir times.tm_year = rNewDateTime.GetYear() - 1900; // 1997 -> 97 622*cdf0e10cSrcweir times.tm_mon = rNewDateTime.GetMonth() - 1; // 0 == Januar! 623*cdf0e10cSrcweir times.tm_mday = rNewDateTime.GetDay(); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir times.tm_hour = rNewDateTime.GetHour(); 626*cdf0e10cSrcweir times.tm_min = rNewDateTime.GetMin(); 627*cdf0e10cSrcweir times.tm_sec = rNewDateTime.GetSec(); 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir times.tm_wday = 0; 630*cdf0e10cSrcweir times.tm_yday = 0; 631*cdf0e10cSrcweir #ifdef SOLARIS 632*cdf0e10cSrcweir times.tm_isdst = -1; 633*cdf0e10cSrcweir #else 634*cdf0e10cSrcweir times.tm_isdst = 0; 635*cdf0e10cSrcweir #endif 636*cdf0e10cSrcweir 637*cdf0e10cSrcweir time_t time = mktime (×); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir if (time != (time_t) -1) 640*cdf0e10cSrcweir { 641*cdf0e10cSrcweir struct utimbuf u_time; 642*cdf0e10cSrcweir u_time.actime = time; 643*cdf0e10cSrcweir u_time.modtime = time; 644*cdf0e10cSrcweir utime (ByteString(rFileName, osl_getThreadTextEncoding()).GetBuffer(), &u_time); 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir //========================================================================= 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir ErrCode FileStat::QueryDiskSpace( const String &, BigInt &, BigInt & ) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir return ERRCODE_IO_NOTSUPPORTED; 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir //========================================================================= 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir void FSysEnableSysErrorBox( sal_Bool ) 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir } 660*cdf0e10cSrcweir 661