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