xref: /trunk/main/sal/inc/osl/file.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 /** @HTML */
29 
30 #ifndef _OSL_FILE_HXX_
31 #define _OSL_FILE_HXX_
32 
33 #ifdef __cplusplus
34 
35 #include <osl/time.h>
36 #   include <rtl/memory.h>
37 #   include <rtl/ustring.hxx>
38 
39 #include <osl/file.h>
40 #   include <rtl/byteseq.hxx>
41 
42 #include <stdio.h>
43 
44 namespace osl
45 {
46 
47 
48 // -----------------------------------------------------------------------------
49 /** Base class for all File System specific objects.
50 
51     @see Directory
52     @see DirectoryItem
53     @see File
54  */
55 
56 class FileBase
57 {
58 public:
59 
60     enum RC {
61         E_None         = osl_File_E_None,
62         E_PERM         = osl_File_E_PERM,
63         E_NOENT        = osl_File_E_NOENT,
64         E_SRCH         = osl_File_E_SRCH,
65         E_INTR         = osl_File_E_INTR,
66         E_IO           = osl_File_E_IO,
67         E_NXIO         = osl_File_E_NXIO,
68         E_2BIG         = osl_File_E_2BIG,
69         E_NOEXEC       = osl_File_E_NOEXEC,
70         E_BADF         = osl_File_E_BADF,
71         E_CHILD        = osl_File_E_CHILD,
72         E_AGAIN        = osl_File_E_AGAIN,
73         E_NOMEM        = osl_File_E_NOMEM,
74         E_ACCES        = osl_File_E_ACCES,
75         E_FAULT        = osl_File_E_FAULT,
76         E_BUSY         = osl_File_E_BUSY,
77         E_EXIST        = osl_File_E_EXIST,
78         E_XDEV         = osl_File_E_XDEV,
79         E_NODEV        = osl_File_E_NODEV,
80         E_NOTDIR       = osl_File_E_NOTDIR,
81         E_ISDIR        = osl_File_E_ISDIR,
82         E_INVAL        = osl_File_E_INVAL,
83         E_NFILE        = osl_File_E_NFILE,
84         E_MFILE        = osl_File_E_MFILE,
85         E_NOTTY        = osl_File_E_NOTTY,
86         E_FBIG         = osl_File_E_FBIG,
87         E_NOSPC        = osl_File_E_NOSPC,
88         E_SPIPE        = osl_File_E_SPIPE,
89         E_ROFS         = osl_File_E_ROFS,
90         E_MLINK        = osl_File_E_MLINK,
91         E_PIPE         = osl_File_E_PIPE,
92         E_DOM          = osl_File_E_DOM,
93         E_RANGE        = osl_File_E_RANGE,
94         E_DEADLK       = osl_File_E_DEADLK,
95         E_NAMETOOLONG  = osl_File_E_NAMETOOLONG,
96         E_NOLCK        = osl_File_E_NOLCK,
97         E_NOSYS        = osl_File_E_NOSYS,
98         E_NOTEMPTY     = osl_File_E_NOTEMPTY,
99         E_LOOP         = osl_File_E_LOOP,
100         E_ILSEQ        = osl_File_E_ILSEQ,
101         E_NOLINK       = osl_File_E_NOLINK,
102         E_MULTIHOP     = osl_File_E_MULTIHOP,
103         E_USERS        = osl_File_E_USERS,
104         E_OVERFLOW     = osl_File_E_OVERFLOW,
105         E_NOTREADY     = osl_File_E_NOTREADY,
106         E_invalidError = osl_File_E_invalidError,   /* unmapped error: always last entry in enum! */
107         E_TIMEDOUT     = osl_File_E_TIMEDOUT,
108         E_NETWORK      = osl_File_E_NETWORK
109     };
110 
111 
112 public:
113 
114     /** Determine a valid unused canonical name for a requested name.
115 
116         Determines a valid unused canonical name for a requested name.
117         Depending on the Operating System and the File System the illegal characters are replaced by valid ones.
118         If a file or directory with the requested name already exists a new name is generated following
119         the common rules on the actual Operating System and File System.
120 
121         @param ustrRequestedURL [in]
122         Requested name of a file or directory.
123 
124         @param pustrValidURL [out]
125         On success receives a name which is unused and valid on the actual Operating System and
126         File System.
127 
128         @return
129         E_None on success
130         E_INVAL the format of the parameters was not valid
131 
132         @see DirectoryItem::getFileStatus()
133     */
134 
135     static inline RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
136     {
137         return (RC) osl_getCanonicalName( ustrRequestedURL.pData, &ustrValidURL.pData );
138     }
139 
140     /** Convert a path relative to a given directory into an full qualified file URL.
141 
142         Convert a path relative to a given directory into an full qualified file URL.
143         The function resolves symbolic links if possible and path ellipses, so on success
144         the resulting absolute path is fully resolved.
145 
146         @param ustrBaseDirectoryURL [in]
147         Base directory URL to which the relative path is related to.
148 
149         @param ustrRelativeFileURL [in]
150         An URL of a file or directory relative to the directory path specified by ustrBaseDirectoryURL
151         or an absolute path.
152         If ustrRelativeFileURL denotes an absolute path ustrBaseDirectoryURL will be ignored.
153 
154         @param ustrAbsoluteFileURL [out]
155         On success it receives the full qualified absoulte file URL.
156 
157         @return
158         E_None on success
159         E_INVAL the format of the parameters was not valid
160         E_NOMEM not enough memory for allocating structures
161         E_NOTDIR not a directory
162         E_ACCES permission denied
163         E_NOENT no such file or directory
164         E_NAMETOOLONG file name too long
165         E_OVERFLOW value too large for defined data type
166         E_FAULT bad address
167         E_INTR function call was interrupted
168         E_LOOP too many symbolic links encountered
169         E_MULTIHOP multihop attempted
170         E_NOLINK link has been severed
171 
172         @see DirectoryItem::getFileStatus()
173     */
174 
175     static inline RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, const ::rtl::OUString& ustrRelativeFileURL, ::rtl::OUString& ustrAbsoluteFileURL )
176     {
177         return (RC) osl_getAbsoluteFileURL( ustrBaseDirectoryURL.pData, ustrRelativeFileURL.pData, &ustrAbsoluteFileURL.pData );
178     }
179 
180     /** Convert a file URL into a system dependend path.
181 
182         @param ustrFileURL [in]
183         A File URL.
184 
185         @param ustrSystemPath [out]
186         On success it receives the system path.
187 
188         @return
189         E_None on success
190         E_INVAL the format of the parameters was not valid
191 
192         @see getFileURLFromSystemPath()
193     */
194 
195     static inline RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, ::rtl::OUString& ustrSystemPath )
196     {
197         return (RC) osl_getSystemPathFromFileURL( ustrFileURL.pData, &ustrSystemPath.pData );
198     }
199 
200     /** Convert a system dependend path into a file URL.
201 
202         @param ustrSystemPath [in]
203         A System dependent path of a file or directory.
204 
205         @param ustrFileURL [out]
206         On success it receives the file URL.
207 
208         @return
209         E_None on success
210         E_INVAL the format of the parameters was not valid
211 
212         @see getSystemPathFromFileURL()
213     */
214 
215     static inline RC getFileURLFromSystemPath( const ::rtl::OUString& ustrSystemPath, ::rtl::OUString& ustrFileURL )
216     {
217         return (RC) osl_getFileURLFromSystemPath( ustrSystemPath.pData, &ustrFileURL.pData );
218     }
219 
220     /** Searche a full qualified system path or a file URL.
221 
222         @param ustrFileName [in]
223         A system dependent path, a file URL, a file or relative directory
224 
225         @param ustrSearchPath [in]
226         A list of system paths, in which a given file has to be searched. The Notation of a path list is
227         system dependend, e.g. on UNIX system "/usr/bin:/bin" and on Windows "C:\BIN;C:\BATCH".
228         These paths are only for the search of a file or a relative path, otherwise it will be ignored.
229         If ustrSearchPath is NULL or while using the search path the search failed, the function searches for
230         a matching file in all system directories and in the directories listed in the PATH environment
231         variable.
232         The value of an environment variable should be used (e.g. LD_LIBRARY_PATH) if the caller is not
233         aware of the Operating System and so doesn't know which path list delimiter to use.
234 
235         @param ustrFileURL [out]
236         On success it receives the full qualified file URL.
237 
238         @return
239         E_None on success
240         E_INVAL the format of the parameters was not valid
241         E_NOTDIR not a directory
242         E_NOENT no such file or directory not found
243 
244         @see getFileURLFromSystemPath()
245         @see getSystemPathFromFileURL()
246     */
247 
248     static inline RC searchFileURL( const ::rtl::OUString& ustrFileName, const ::rtl::OUString& ustrSearchPath, ::rtl::OUString& ustrFileURL )
249     {
250         return (RC) osl_searchFileURL( ustrFileName.pData, ustrSearchPath.pData, &ustrFileURL.pData );
251     }
252 
253     /** Retrieves the file URL of the system's temporary directory path.
254 
255         @param ustrTempDirURL[out]
256         On success receives the URL of system's temporary directory path.
257 
258         @return
259         E_None on success
260         E_NOENT no such file or directory not found
261     */
262 
263     static inline RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
264     {
265         return (RC) osl_getTempDirURL( &ustrTempDirURL.pData );
266     }
267 
268     /** Creates a temporary file in the directory provided by the caller or the
269         directory returned by getTempDirURL.
270         Under UNIX Operating Systems the file will be created with read and write
271         access for the user exclusively.
272         If the caller requests only a handle to the open file but not the name of
273         it, the file will be automatically removed on close else the caller is
274         responsible for removing the file on success.<br><br>
275 
276         @param  pustrDirectoryURL [in]
277         Specifies the full qualified URL where the temporary file should be created.
278         If pustrDirectoryURL is 0 the path returned by osl_getTempDirURL will be used.
279 
280         @param  pHandle [out]
281         On success receives a handle to the open file.
282         If pHandle is 0 the file will be closed on return, in this case
283         pustrTempFileURL must not be 0.
284 
285         @param  pustrTempFileURL [out]
286         On success receives the full qualified URL of the temporary file.
287         If pustrTempFileURL is 0 the file will be automatically removed
288         on close, in this case pHandle must not be 0.
289         If pustrTempFileURL is not 0 the caller receives the name of the
290         created file and is responsible for removing the file.
291 
292         @descr
293         Description of the different pHandle, ppustrTempFileURL parameter combinations.
294         pHandle is 0 and pustrTempDirURL is 0 - this combination is invalid<br>
295         pHandle is not 0 and pustrTempDirURL is 0 - a handle to the open file
296         will be returned on success and the file will be automatically removed on close<br>
297         pHandle is 0 and pustrTempDirURL is not 0 - the name of the file will be
298         returned, the caller is responsible for opening, closing and removing the file.<br>
299         pHandle is not 0 and pustrTempDirURL is not 0 - a handle to the open file as well as
300         the file name will be returned, the caller is responsible for closing and removing
301         the file.<br>
302 
303         @return
304         E_None   on success
305         E_INVAL  the format of the parameter is invalid
306         E_NOMEM  not enough memory for allocating structures
307         E_ACCES  Permission denied
308         E_NOENT  No such file or directory
309         E_NOTDIR Not a directory
310         E_ROFS   Read-only file system
311         E_NOSPC  No space left on device
312         E_DQUOT  Quota exceeded
313 
314         @see getTempDirURL()
315     */
316 
317     static inline RC createTempFile(
318         ::rtl::OUString* pustrDirectoryURL,
319         oslFileHandle*   pHandle,
320         ::rtl::OUString* pustrTempFileURL)
321     {
322         rtl_uString*  pustr_dir_url       = pustrDirectoryURL ? pustrDirectoryURL->pData : 0;
323         rtl_uString** ppustr_tmp_file_url = pustrTempFileURL  ? &pustrTempFileURL->pData : 0;
324 
325         return (RC) osl_createTempFile(pustr_dir_url, pHandle, ppustr_tmp_file_url);
326     }
327 };
328 
329 
330 // -----------------------------------------------------------------------------
331 /** The VolumeDevice class.
332 
333     @see VolumeInfo
334 */
335 #ifdef OS2
336 class VolumeInfo;
337 #endif
338 
339 class VolumeDevice : public FileBase
340 {
341 #ifdef OS2
342 public:
343 #endif
344     oslVolumeDeviceHandle   _aHandle;
345 
346 public:
347 
348     /** Constructor.
349     */
350 
351     VolumeDevice() : _aHandle( NULL )
352     {
353     }
354 
355     /** Copy constructor.
356 
357         @param rDevice
358         The other volume device.
359     */
360 
361     VolumeDevice( const VolumeDevice & rDevice )
362     {
363         _aHandle = rDevice._aHandle;
364         if ( _aHandle )
365             osl_acquireVolumeDeviceHandle( _aHandle );
366     }
367 
368     /** Destructor.
369     */
370 
371     ~VolumeDevice()
372     {
373         if ( _aHandle )
374             osl_releaseVolumeDeviceHandle( _aHandle );
375     }
376 
377     /** Assignment operator.
378 
379         @param rDevice
380         The other volume device.
381     */
382 
383     inline VolumeDevice & operator =( const VolumeDevice & rDevice )
384     {
385         oslVolumeDeviceHandle   newHandle = rDevice._aHandle;
386 
387         if ( newHandle )
388             osl_acquireVolumeDeviceHandle( newHandle );
389 
390         if ( _aHandle )
391             osl_releaseVolumeDeviceHandle( _aHandle );
392 
393         _aHandle = newHandle;
394 
395         return *this;
396     }
397 
398     /** Automount a volume device.
399 
400         @return
401         E_None on success
402 
403         @todo
404         specify all error codes that may be returned
405     */
406 
407     inline RC automount()
408     {
409         return (RC)osl_automountVolumeDevice( _aHandle );
410     }
411 
412     /** Unmount a volume device.
413 
414         @return
415         E_None on success
416 
417         @todo
418         specify all error codes that may be returned
419     */
420 
421     inline RC unmount()
422     {
423         return (RC)osl_unmountVolumeDevice( _aHandle );
424     }
425 
426     /** Get the full qualified URL where a device is mounted to.
427 
428         @return
429         The full qualified URL where the device is mounted to.
430     */
431     inline rtl::OUString getMountPath()
432     {
433         rtl::OUString   aPath;
434         osl_getVolumeDeviceMountPath( _aHandle, &aPath.pData );
435         return aPath;
436     }
437 
438     friend class VolumeInfo;
439 };
440 
441 // -----------------------------------------------------------------------------
442 
443 #define VolumeInfoMask_Attributes             osl_VolumeInfo_Mask_Attributes
444 #define VolumeInfoMask_TotalSpace             osl_VolumeInfo_Mask_TotalSpace
445 #define VolumeInfoMask_UsedSpace              osl_VolumeInfo_Mask_UsedSpace
446 #define VolumeInfoMask_FreeSpace              osl_VolumeInfo_Mask_FreeSpace
447 #define VolumeInfoMask_MaxNameLength          osl_VolumeInfo_Mask_MaxNameLength
448 #define VolumeInfoMask_MaxPathLength          osl_VolumeInfo_Mask_MaxPathLength
449 #define VolumeInfoMask_FileSystemName         osl_VolumeInfo_Mask_FileSystemName
450 #define VolumeInfoMask_FileSystemCaseHandling osl_VolumeInfo_Mask_FileSystemCaseHandling
451 
452 class Directory;
453 
454 /** The VolumeInfo class.
455 
456     Neither copy nor assignment is allowed for this class.
457 
458     @see Directory::getVolumeInfo
459 */
460 
461 
462 class VolumeInfo
463 {
464     oslVolumeInfo   _aInfo;
465     sal_uInt32      _nMask;
466     VolumeDevice    _aDevice;
467 
468     /** Copy constructor.
469     */
470 
471     VolumeInfo( VolumeInfo& );
472 
473     /** Assginment operator.
474     */
475 
476     VolumeInfo& operator = ( VolumeInfo& );
477 
478 public:
479 
480     /** Constructor.
481 
482         @param nMask
483         Set of flaggs decribing the demanded information.
484     */
485 
486     VolumeInfo( sal_uInt32 nMask ): _nMask( nMask )
487     {
488         _aInfo.uStructSize = sizeof( oslVolumeInfo );
489         rtl_fillMemory( &_aInfo.uValidFields, sizeof( oslVolumeInfo ) - sizeof( sal_uInt32 ), 0 );
490         _aInfo.pDeviceHandle = &_aDevice._aHandle;
491     }
492 
493     /** Destructor.
494     */
495 
496     ~VolumeInfo()
497     {
498         if( _aInfo.ustrFileSystemName )
499             rtl_uString_release( _aInfo.ustrFileSystemName );
500     }
501 
502     /** Check if specified fields are valid.
503 
504         @param nMask
505         Set of flags for the fields to check.
506 
507         @return sal_True if all fields are valid else sal_False.
508     */
509 
510     inline sal_Bool isValid( sal_uInt32 nMask ) const
511     {
512         return ( nMask & _aInfo.uValidFields ) == nMask;
513     }
514 
515     /** Check the remote flag.
516 
517         @return
518         sal_True if Attributes are valid and the volume is remote else sal_False.
519     */
520 
521     inline sal_Bool getRemoteFlag() const
522     {
523         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_Remote);
524     }
525 
526     /** Check the removeable flag.
527 
528         @return
529         sal_True if attributes are valid and the volume is removable else sal_False.
530     */
531 
532     inline sal_Bool getRemoveableFlag() const
533     {
534         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_Removeable);
535     }
536 
537     /** Check the compact disc flag.
538 
539         @return
540         sal_True if attributes are valid and the volume is a CDROM else sal_False.
541     */
542 
543     inline sal_Bool getCompactDiscFlag() const
544     {
545         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_CompactDisc);
546     }
547 
548     /** Check the floppy disc flag.
549 
550         @return
551         sal_True if attributes are valid and the volume is a floppy disk else sal_False.
552     */
553 
554     inline sal_Bool getFloppyDiskFlag() const
555     {
556         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_FloppyDisk);
557     }
558 
559     /** Check the fixed disk flag.
560 
561         @return
562         sal_True if attributes are valid and the volume is a fixed disk else sal_False.
563     */
564 
565     inline sal_Bool getFixedDiskFlag() const
566     {
567         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_FixedDisk);
568     }
569 
570     /** Check the RAM disk flag.
571 
572         @return
573         sal_True if attributes are valid and the volume is a RAM disk else sal_False.
574     */
575 
576     inline sal_Bool getRAMDiskFlag() const
577     {
578         return 0 != (_aInfo.uAttributes & osl_Volume_Attribute_RAMDisk);
579     }
580 
581     /** Determine the total space of a volume device.
582 
583         @return
584         The total diskspace of this volume if this information is valid,
585         0 otherwise.
586     */
587 
588     inline sal_uInt64 getTotalSpace() const
589     {
590         return _aInfo.uTotalSpace;
591     }
592 
593     /** Determine the free space of a volume device.
594 
595         @return
596         The free diskspace of this volume if this information is valid,
597         0 otherwise.
598     */
599 
600     inline sal_uInt64 getFreeSpace() const
601     {
602         return _aInfo.uFreeSpace;
603     }
604 
605     /** Determine the used space of a volume device.
606 
607         @return
608         The used diskspace of this volume if this information is valid,
609         0 otherwise.
610     */
611 
612     inline sal_uInt64 getUsedSpace() const
613     {
614         return _aInfo.uUsedSpace;
615     }
616 
617     /** Determine the maximal length of a file name.
618 
619         @return
620         The maximal length of a file name if this information is valid,
621         0 otherwise.
622     */
623 
624     inline sal_uInt32 getMaxNameLength() const
625     {
626         return _aInfo.uMaxNameLength;
627     }
628 
629     /** Determine the maximal length of a path name.
630 
631         @return
632         The maximal length of a path if this information is valid,
633         0 otherwise.
634     */
635 
636     inline sal_uInt32 getMaxPathLength() const
637     {
638         return _aInfo.uMaxPathLength;
639     }
640 
641     /** Determine the name of the volume device's File System.
642 
643         @return
644         The name of the volume's fielsystem if this information is valid,
645         otherwise an empty string.
646     */
647 
648     inline ::rtl::OUString getFileSystemName() const
649     {
650         return _aInfo.ustrFileSystemName ? ::rtl::OUString( _aInfo.ustrFileSystemName ) : ::rtl::OUString();
651     }
652 
653 
654     /** Get the volume device handle.
655 
656         @return
657         The device handle of the volume if this information is valid,
658         otherwise returns NULL;
659     */
660 
661     inline VolumeDevice getDeviceHandle() const
662     {
663         return _aDevice;
664     }
665 
666     /** Return whether the file system is case sensitive or
667         case insensitive
668 
669         @return
670         true if the file system is case sensitive false otherwise
671     */
672     bool isCaseSensitiveFileSystem() const
673     {
674         return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Sensitive);
675     }
676 
677     /** Return whether the file system preserves the case of
678         file and directory names or not
679 
680         @return
681         true if the file system preserves the case of file and
682         directory names false otherwise
683     */
684     bool isCasePreservingFileSystem() const
685     {
686         return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Is_Preserved);
687     }
688 
689     friend class Directory;
690 };
691 
692 // -----------------------------------------------------------------------------
693 
694 #define FileStatusMask_Type             osl_FileStatus_Mask_Type
695 #define FileStatusMask_Attributes       osl_FileStatus_Mask_Attributes
696 #define FileStatusMask_CreationTime     osl_FileStatus_Mask_CreationTime
697 #define FileStatusMask_AccessTime       osl_FileStatus_Mask_AccessTime
698 #define FileStatusMask_ModifyTime       osl_FileStatus_Mask_ModifyTime
699 #define FileStatusMask_FileSize         osl_FileStatus_Mask_FileSize
700 #define FileStatusMask_FileName         osl_FileStatus_Mask_FileName
701 #define FileStatusMask_FileURL          osl_FileStatus_Mask_FileURL
702 #define FileStatusMask_LinkTargetURL    osl_FileStatus_Mask_LinkTargetURL
703 #define FileStatusMask_All              osl_FileStatus_Mask_All
704 #define FileStatusMask_Validate         osl_FileStatus_Mask_Validate
705 
706 #define Attribute_ReadOnly     osl_File_Attribute_ReadOnly
707 #define Attribute_Hidden       osl_File_Attribute_Hidden
708 #define Attribute_Executable   osl_File_Attribute_Executable
709 #define Attribute_GrpWrite     osl_File_Attribute_GrpWrite
710 #define Attribute_GrpRead      osl_File_Attribute_GrpRead
711 #define Attribute_GrpExe       osl_File_Attribute_GrpExe
712 #define Attribute_OwnWrite     osl_File_Attribute_OwnWrite
713 #define Attribute_OwnRead      osl_File_Attribute_OwnRead
714 #define Attribute_OwnExe       osl_File_Attribute_OwnExe
715 #define Attribute_OthWrite     osl_File_Attribute_OthWrite
716 #define Attribute_OthRead      osl_File_Attribute_OthRead
717 #define Attribute_OthExe       osl_File_Attribute_OthExe
718 
719 class DirectoryItem;
720 
721 /** The FileStatus class.
722 
723     @see DirectoryItem::getFileStatus
724 */
725 
726 class FileStatus
727 {
728     oslFileStatus   _aStatus;
729     sal_uInt32      _nMask;
730 
731     /** Copy constructor.
732     */
733 
734     FileStatus( FileStatus& );
735 
736     /** Assignment operator.
737     */
738 
739     FileStatus& operator = ( FileStatus& );
740 
741 public:
742 
743     enum Type {
744         Directory = osl_File_Type_Directory,
745         Volume    = osl_File_Type_Volume,
746         Regular   = osl_File_Type_Regular,
747         Fifo      = osl_File_Type_Fifo,
748         Socket    = osl_File_Type_Socket,
749         Link      = osl_File_Type_Link,
750         Special   = osl_File_Type_Special,
751         Unknown   = osl_File_Type_Unknown
752     };
753 
754     /** Constructor.
755 
756         @param nMask
757         Set of flaggs decribing the demanded information.
758     */
759 
760     FileStatus( sal_uInt32 nMask ): _nMask( nMask )
761     {
762         _aStatus.uStructSize = sizeof( oslFileStatus );
763         rtl_fillMemory( &_aStatus.uValidFields, sizeof( oslFileStatus ) - sizeof( sal_uInt32 ), 0 );
764     }
765 
766     /** Destructor.
767     */
768 
769     ~FileStatus()
770     {
771         if ( _aStatus.ustrFileURL )
772             rtl_uString_release( _aStatus.ustrFileURL );
773         if ( _aStatus.ustrLinkTargetURL )
774             rtl_uString_release( _aStatus.ustrLinkTargetURL );
775         if ( _aStatus.ustrFileName )
776             rtl_uString_release( _aStatus.ustrFileName );
777     }
778 
779     /** Check if specified fields are valid.
780 
781         @param nMask
782         Set of flags for the fields to check.
783 
784         @return
785         sal_True if all fields are valid else sal_False.
786     */
787 
788     inline sal_Bool isValid( sal_uInt32 nMask ) const
789     {
790         return ( nMask & _aStatus.uValidFields ) == nMask;
791     }
792 
793     /** Get the file type.
794 
795         @return
796         The file type if this information is valid, Unknown otherwise.
797     */
798     inline Type getFileType() const
799     {
800         return (_aStatus.uValidFields & FileStatusMask_Type) ?  (Type) _aStatus.eType : Unknown;
801     }
802 
803     /** Get the file attributes.
804 
805         @return
806         The set of attribute flags of this file.
807     */
808 
809     inline sal_uInt64 getAttributes() const
810     {
811         return _aStatus.uAttributes;
812     }
813 
814     /** Get the creation time of this file.
815 
816         @return
817         The creation time if this information is valid,
818         an uninitialized TimeValue otherwise.
819     */
820 
821     inline TimeValue getCreationTime() const
822     {
823         return _aStatus.aCreationTime;
824     }
825 
826     /** Get the file access time.
827 
828         @return
829         The last access time if this information is valid,
830         an uninitialized TimeValue otherwise.
831     */
832 
833     inline TimeValue getAccessTime() const
834     {
835         return _aStatus.aAccessTime;
836     }
837 
838     /** Get the file modification time.
839 
840         @return
841         The last modified time if this information is valid,
842         an uninitialized TimeValue otherwise.
843     */
844 
845     inline TimeValue getModifyTime() const
846     {
847         return _aStatus.aModifyTime;
848     }
849 
850     /** Get the size of the file.
851 
852         @return
853         The actual file size if this information is valid, 0 otherwise.
854     */
855 
856     inline sal_uInt64 getFileSize() const
857     {
858         return _aStatus.uFileSize;
859     }
860 
861     /** Get the file name.
862 
863         @return
864         The file name if this information is valid, an empty string otherwise.
865     */
866 
867     inline ::rtl::OUString getFileName() const
868     {
869         return _aStatus.ustrFileName ? ::rtl::OUString(_aStatus.ustrFileName) : ::rtl::OUString();
870     }
871 
872 
873     /** Get the URL of the file.
874 
875         @return
876         The full qualified URL of the file if this information is valid, an empty string otherwise.
877     */
878 
879     inline ::rtl::OUString getFileURL() const
880     {
881         return _aStatus.ustrFileURL ? ::rtl::OUString(_aStatus.ustrFileURL) : ::rtl::OUString();
882     }
883 
884     /** Get the link target URL.
885 
886         @return
887         The link target URL if this information is valid, an empty string otherwise.
888     */
889 
890     inline ::rtl::OUString getLinkTargetURL() const
891     {
892         return _aStatus.ustrLinkTargetURL ? ::rtl::OUString(_aStatus.ustrLinkTargetURL) : ::rtl::OUString();
893     }
894 
895     friend class DirectoryItem;
896 };
897 
898 
899 // -----------------------------------------------------------------------------
900 /** The file class object provides access to file contents and attributes.
901 
902     @see Directory
903     @see DirectoryItem
904  */
905 
906 class File: public FileBase
907 {
908     oslFileHandle   _pData;
909     ::rtl::OUString _aPath;
910 
911     /** Copy constructor.
912     */
913 
914     File( File& );
915 
916     /** Assginment operator.
917     */
918 
919     File& operator = ( File& );
920 
921 public:
922 
923     /** Constructor.
924 
925         @param  ustrFileURL [in]
926         The full qualified URL of the file. Relative paths are not allowed.
927     */
928 
929     File( const ::rtl::OUString& ustrFileURL ): _pData( 0 ), _aPath( ustrFileURL ) {}
930 
931     /** Destructor
932     */
933 
934     inline ~File()
935     {
936         close();
937     }
938 
939     #define OpenFlag_Read   osl_File_OpenFlag_Read
940     #define OpenFlag_Write  osl_File_OpenFlag_Write
941     #define OpenFlag_Create osl_File_OpenFlag_Create
942     #define OpenFlag_NoLock osl_File_OpenFlag_NoLock
943 
944     /** Open a regular file.
945 
946         Open a file. Only regular files can be openend.
947 
948         @param uFlags [in]
949         Specifies the open mode.
950 
951         @return
952         E_None on success
953         E_NOMEM not enough memory for allocating structures
954         E_INVAL the format of the parameters was not valid
955         E_NAMETOOLONG pathname was too long
956         E_NOENT no such file or directory
957         E_ACCES permission denied
958         E_AGAIN a write lock could not be established
959         E_NOTDIR not a directory
960         E_NXIO no such device or address
961         E_NODEV no such device
962         E_ROFS read-only file system
963         E_TXTBSY text file busy
964         E_FAULT bad address
965         E_LOOP too many symbolic links encountered
966         E_NOSPC no space left on device
967         E_ISDIR is a directory
968         E_MFILE too many open files used by the process
969         E_NFILE too many open files in the system
970         E_DQUOT quota exceeded
971         E_EXIST file exists
972         E_INTR function call was interrupted
973         E_IO on I/O errors
974         E_MULTIHOP multihop attempted
975         E_NOLINK link has been severed
976         E_EOVERFLOW value too large for defined data type
977 
978         @see close()
979         @see setPos()
980         @see getPos()
981         @see read()
982         @see write()
983         @see getSize()
984         @see setSize()
985     */
986 
987     inline RC open( sal_uInt32 uFlags )
988     {
989         return (RC) osl_openFile( _aPath.pData, &_pData, uFlags );
990     }
991 
992     /** Close an open file.
993 
994         @return
995         E_None on success
996         E_INVAL the format of the parameters was not valid
997         E_BADF Bad file
998         E_INTR function call was interrupted
999         E_NOLINK link has been severed
1000         E_NOSPC no space left on device
1001         E_IO on I/O errors
1002 
1003         @see open()
1004     */
1005 
1006     inline RC close()
1007     {
1008         oslFileError Error = osl_File_E_BADF;
1009 
1010         if( _pData )
1011         {
1012             Error=osl_closeFile( _pData );
1013             _pData = NULL;
1014         }
1015 
1016         return (RC) Error;
1017     }
1018 
1019 
1020     #define Pos_Absolut osl_Pos_Absolut
1021     #define Pos_Current osl_Pos_Current
1022     #define Pos_End     osl_Pos_End
1023 
1024     /** Set the internal position pointer of an open file.
1025 
1026         @param uHow [in]
1027         Distance to move the internal position pointer (from uPos).
1028 
1029         @param uPos [in]
1030         Absolute position from the beginning of the file.
1031 
1032         @return
1033         E_None on success
1034         E_INVAL the format of the parameters was not valid
1035         E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1036 
1037         @see open()
1038         @see getPos()
1039     */
1040 
1041     inline RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
1042     {
1043         return (RC) osl_setFilePos( _pData, uHow, uPos );
1044     }
1045 
1046     /** Retrieve the current position of the internal pointer of an open file.
1047 
1048         @param uPos [out]
1049         On success receives the current position of the file pointer.
1050 
1051         @return
1052         E_None on success
1053         E_INVAL the format of the parameters was not valid
1054         E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1055 
1056         @see open()
1057         @see setPos()
1058         @see read()
1059         @see write()
1060     */
1061 
1062     inline RC getPos( sal_uInt64& uPos )
1063     {
1064         return (RC) osl_getFilePos( _pData, &uPos );
1065     }
1066 
1067     /** Test if the end of a file is reached.
1068 
1069         @param pIsEOF [out]
1070         Points to a variable that receives the end-of-file status.
1071 
1072         @return
1073         E_None on success
1074         E_INVAL the format of the parameters was not valid
1075         E_INTR function call was interrupted
1076         E_IO on I/O errors
1077         E_ISDIR is a directory
1078         E_BADF bad file
1079         E_FAULT bad address
1080         E_AGAIN operation would block
1081         E_NOLINK link has been severed
1082 
1083         @see open()
1084         @see read()
1085         @see readLine()
1086         @see setPos()
1087     */
1088 
1089     inline RC isEndOfFile( sal_Bool *pIsEOF )
1090     {
1091         return (RC) osl_isEndOfFile( _pData, pIsEOF );
1092     }
1093 
1094     /** Set the file size of an open file.
1095 
1096         Sets the file size of an open file. The file can be truncated or enlarged by the function.
1097         The position of the file pointer is not affeced by this function.
1098 
1099         @param uSize [in]
1100         New size in bytes.
1101 
1102         @return
1103         E_None on success
1104         E_INVAL the format of the parameters was not valid
1105         E_OVERFLOW the resulting file offset would be a value which cannot  be represented correctly for regular files
1106 
1107         @see open()
1108         @see setPos()
1109         @see getStatus()
1110     */
1111 
1112     inline RC setSize( sal_uInt64 uSize )
1113     {
1114         return (RC) osl_setFileSize( _pData, uSize );
1115     }
1116 
1117     /** Get the file size of an open file.
1118 
1119         Gets the file size of an open file.
1120         The position of the file pointer is not affeced by this function.
1121 
1122         @param rSize [out]
1123         Current size in bytes.
1124 
1125         @return
1126         E_None on success
1127         E_INVAL the format of the parameters was not valid
1128         E_OVERFLOW the resulting file offset would be a value which cannot  be represented correctly for regular files
1129 
1130         @see open()
1131         @see setPos()
1132         @see getSize()
1133         @see setSize()
1134         @see getStatus()
1135     */
1136 
1137     inline RC getSize( sal_uInt64 &rSize )
1138     {
1139         return (RC) osl_getFileSize( _pData, &rSize );
1140     }
1141 
1142     /** Read a number of bytes from a file.
1143 
1144         Reads a number of bytes from a file. The internal file pointer is
1145         increased by the number of bytes read.
1146 
1147         @param pBuffer [out]
1148         Points to a buffer which receives data. The buffer must be large enough
1149         to hold uBytesRequested bytes.
1150 
1151         @param uBytesRequested [in]
1152         Number of bytes which should be retrieved.
1153 
1154         @param rBytesRead [out]
1155         On success the number of bytes which have actually been retrieved.
1156 
1157         @return
1158         E_None on success
1159         E_INVAL the format of the parameters was not valid
1160         E_INTR function call was interrupted
1161         E_IO on I/O errors
1162         E_ISDIR is a directory
1163         E_BADF bad file
1164         E_FAULT bad address
1165         E_AGAIN operation would block
1166         E_NOLINK link has been severed
1167 
1168         @see open()
1169         @see write()
1170         @see readLine()
1171         @see setPos()
1172     */
1173 
1174     inline RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
1175     {
1176         return (RC) osl_readFile( _pData, pBuffer, uBytesRequested, &rBytesRead );
1177     }
1178 
1179     /** Write a number of bytes to a file.
1180 
1181         Writes a number of bytes to a file.
1182         The internal file pointer is increased by the number of bytes read.
1183 
1184         @param pBuffer [in]
1185         Points to a buffer which contains the data.
1186 
1187         @param uBytesToWrite [in]
1188         Number of bytes which should be written.
1189 
1190         @param rBytesWritten [out]
1191         On success the number of bytes which have actually been written.
1192 
1193         @return
1194         E_None on success
1195         E_INVAL the format of the parameters was not valid
1196         E_FBIG file too large
1197         E_DQUOT quota exceeded
1198         E_AGAIN operation would block
1199         E_BADF bad file
1200         E_FAULT bad address
1201         E_INTR function call was interrupted
1202         E_IO on I/O errosr
1203         E_NOLCK no record locks available
1204         E_NOLINK link has been severed
1205         E_NOSPC no space left on device
1206         E_NXIO no such device or address
1207 
1208         @see open()
1209         @see read()
1210         @see setPos()
1211     */
1212 
1213     inline RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
1214     {
1215         return (RC) osl_writeFile( _pData, pBuffer, uBytesToWrite, &rBytesWritten );
1216     }
1217 
1218 
1219     /** Read a line from a file.
1220 
1221         Reads a line from a file. The new line delimiter is NOT returned!
1222 
1223         @param  aSeq [in/out]
1224         A reference to a ::rtl::ByteSequence that will hold the line read on success.
1225 
1226         @return
1227         E_None on success
1228         E_INVAL the format of the parameters was not valid
1229         E_INTR function call was interrupted
1230         E_IO on I/O errors
1231         E_ISDIR is a directory
1232         E_BADF bad file
1233         E_FAULT bad address
1234         E_AGAIN operation would block
1235         E_NOLINK link has been severed
1236 
1237         @see open()
1238         @see read()
1239         @see write()
1240         @see setPos()
1241     */
1242 
1243     inline RC readLine( ::rtl::ByteSequence& aSeq )
1244     {
1245         return (RC) osl_readLine( _pData, reinterpret_cast<sal_Sequence**>(&aSeq) );
1246     }
1247 
1248     /** Synchronize the memory representation of a file with that on the physical medium.
1249 
1250     The function ensures that all modified data and attributes of the file associated with
1251     the given file handle have been written to the physical medium.
1252     In case the hard disk has a write cache enabled, the data may not really be on
1253     permanent storage when osl_syncFile returns.
1254 
1255     @return
1256     <dl>
1257     <dt>E_None</dt>
1258     <dd>On success</dd>
1259     <dt>E_INVAL</dt>
1260     <dd>The value of the input parameter is invalid</dd>
1261     </dl>
1262     <br><p><strong>In addition to these error codes others may occur as well, for instance:</strong></p><br>
1263     <dt>E_BADF</dt>
1264     <dd>The file is not open for writing</dd>
1265     <dt>E_IO</dt>
1266     <dd>An I/O error occurred</dd>
1267     <dt>E_NOSPC</dt>
1268     <dd>There is no enough space on the target device</dd>
1269     <dt>E_ROFS</dt>
1270     <dd>The file is located on a read only file system</dd>
1271     <dt>E_TIMEDOUT</dt>
1272     <dd>A remote connection timed out. This may happen when a file is on a remote location</dd>
1273     </dl>
1274 
1275     @see osl_syncFile()
1276     @see open()
1277     @see write()
1278     */
1279     inline RC sync() const
1280     {
1281         OSL_PRECOND(_pData, "File::sync(): File not open");
1282         return (RC)osl_syncFile(_pData);
1283     }
1284 
1285     /** Copy a file to a new destination.
1286 
1287         Copies a file to a new destination. Copies only files not directories.
1288         No assumptions should be made about preserving attributes or file time.
1289 
1290         @param ustrSourceFileURL [in]
1291         Full qualified URL of the source file.
1292 
1293         @param ustrDestFileURL [in]
1294         Full qualified URL of the destination file. A directory is NOT a valid destination file!
1295 
1296         @return
1297         E_None on success
1298         E_INVAL the format of the parameters was not valid
1299         E_NOMEM not enough memory for allocating structures
1300         E_ACCES permission denied
1301         E_PERM operation not permitted
1302         E_NAMETOOLONG file name too long
1303         E_NOENT no such file or directory
1304         E_ISDIR is a directory
1305         E_ROFS read-only file system
1306 
1307         @see move()
1308         @see remove()
1309     */
1310 
1311     inline static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1312     {
1313         return (RC) osl_copyFile( ustrSourceFileURL.pData, ustrDestFileURL.pData );
1314     }
1315 
1316     /** Move a file or directory to a new destination or renames it.
1317 
1318         Moves a file or directory to a new destination or renames it.
1319         File time and attributes are preserved.
1320 
1321         @param ustrSourceFileURL [in]
1322         Full qualified URL of the source file.
1323 
1324         @param ustrDestFileURL [in]
1325         Full qualified URL of the destination file. An existing directory is NOT a valid destination !
1326 
1327         @return
1328         E_None on success
1329         E_INVAL the format of the parameters was not valid
1330         E_NOMEM not enough memory for allocating structures
1331         E_ACCES permission denied
1332         E_PERM operation not permitted
1333         E_NAMETOOLONG file name too long
1334         E_NOENT no such file or directory
1335         E_ROFS read-only file system
1336 
1337         @see copy()
1338     */
1339 
1340     inline static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1341     {
1342         return (RC) osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData );
1343     }
1344 
1345     /** Remove a regular file.
1346 
1347         @param ustrFileURL [in]
1348         Full qualified URL of the file to remove.
1349 
1350         @return
1351         E_None on success
1352         E_INVAL the format of the parameters was not valid
1353         E_NOMEM not enough memory for allocating structures
1354         E_ACCES permission denied
1355         E_PERM operation not permitted
1356         E_NAMETOOLONG file name too long
1357         E_NOENT no such file or directory
1358         E_ISDIR is a directory
1359         E_ROFS read-only file system
1360         E_FAULT bad address
1361         E_LOOP too many symbolic links encountered
1362         E_IO on I/O errors
1363         E_BUSY device or resource busy
1364         E_INTR function call was interrupted
1365         E_LOOP too many symbolic links encountered
1366         E_MULTIHOP multihop attempted
1367         E_NOLINK link has been severed
1368         E_TXTBSY text file busy
1369 
1370         @see open()
1371     */
1372 
1373     inline static RC remove( const ::rtl::OUString& ustrFileURL )
1374     {
1375         return (RC) osl_removeFile( ustrFileURL.pData );
1376     }
1377 
1378     /** Set file attributes.
1379 
1380         @param ustrFileURL [in]
1381         The full qualified file URL.
1382 
1383         @param uAttributes [in]
1384         Attributes of the file to be set.
1385 
1386         @return
1387         E_None on success
1388         E_INVAL the format of the parameters was not valid
1389 
1390         @see FileStatus
1391     */
1392 
1393     inline static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
1394     {
1395         return (RC) osl_setFileAttributes( ustrFileURL.pData, uAttributes );
1396     }
1397 
1398     /** Set the file time.
1399 
1400         @param ustrFileURL [in]
1401         The full qualified URL of the file.
1402 
1403         @param rCreationTime [in]
1404         Creation time of the given file.
1405 
1406         @param rLastAccessTime [in]
1407         Time of the last access of the given file.
1408 
1409         @param rLastWriteTime [in]
1410         Time of the last modifying of the given file.
1411 
1412         @return
1413         E_None on success
1414         E_INVAL the format of the parameters was not valid
1415         E_NOENT no such file or directory not found
1416 
1417         @see FileStatus
1418     */
1419 
1420     inline static RC setTime(
1421         const ::rtl::OUString& ustrFileURL,
1422         const TimeValue& rCreationTime,
1423         const TimeValue& rLastAccessTime,
1424         const TimeValue& rLastWriteTime )
1425     {
1426         return (RC)  osl_setFileTime(
1427             ustrFileURL.pData,
1428             &rCreationTime,
1429             &rLastAccessTime,
1430             &rLastWriteTime );
1431     }
1432 
1433     friend class DirectoryItem;
1434 };
1435 
1436 // -----------------------------------------------------------------------------
1437 /** The directory item class object provides access to file status information.
1438 
1439     @see FileStatus
1440  */
1441 
1442 class DirectoryItem: public FileBase
1443 {
1444     oslDirectoryItem _pData;
1445 
1446 public:
1447 
1448     /** Constructor.
1449     */
1450 
1451     DirectoryItem(): _pData( NULL )
1452     {
1453     }
1454 
1455     /** Copy constructor.
1456     */
1457 
1458     DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
1459     {
1460         if( _pData )
1461             osl_acquireDirectoryItem( _pData );
1462     }
1463 
1464     /** Destructor.
1465     */
1466 
1467     ~DirectoryItem()
1468     {
1469         if( _pData )
1470             osl_releaseDirectoryItem( _pData );
1471     }
1472 
1473     /** Assignment operator.
1474     */
1475 
1476     DirectoryItem& operator=(const DirectoryItem& rItem )
1477     {
1478         if (&rItem != this)
1479         {
1480             if( _pData )
1481                 osl_releaseDirectoryItem( _pData );
1482 
1483             _pData = rItem._pData;
1484 
1485             if( _pData )
1486                 osl_acquireDirectoryItem( _pData );
1487         }
1488         return *this;
1489     }
1490 
1491     /** Check for validity of this instance.
1492 
1493         @return
1494         sal_True if object is valid directory item else sal_False.
1495      */
1496 
1497     inline sal_Bool is()
1498     {
1499         return _pData != NULL;
1500     }
1501 
1502     /** Retrieve a single directory item.
1503 
1504         Retrieves a single directory item. The returned handle has an initial refcount of 1.
1505         Due to performance issues it is not recommended to use this function while
1506         enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead.
1507 
1508         @param ustrFileURL [in]
1509         An absolute file URL.
1510 
1511         @param rItem [out]
1512         On success it receives a handle which can be used for subsequent calls to osl_getFileStatus().
1513         The handle has to be released by a call to osl_releaseDirectoryItem().
1514 
1515         @return
1516         E_None on success
1517         E_INVAL the format of the parameters was not valid
1518         E_NOMEM not enough memory for allocating structures
1519         E_ACCES permission denied
1520         E_MFILE too many open files used by the process
1521         E_NFILE too many open files in the system
1522         E_NOENT no such file or directory
1523         E_LOOP  too many symbolic links encountered
1524         E_NAMETOOLONG the file name is too long
1525         E_NOTDIR a component of the path prefix of path is not a directory
1526         E_IO on I/O errors
1527         E_MULTIHOP multihop attempted
1528         E_NOLINK link has been severed
1529         E_FAULT bad address
1530         E_INTR the function call was interrupted
1531 
1532         @see FileStatus
1533         @see Directory::getNextItem()
1534     */
1535 
1536     static inline RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
1537     {
1538         if( rItem._pData)
1539         {
1540             osl_releaseDirectoryItem( rItem._pData );
1541             rItem._pData = NULL;
1542         }
1543 
1544         return (RC) osl_getDirectoryItem( ustrFileURL.pData, &rItem._pData );
1545     }
1546 
1547     /** Retrieve information about a single file or directory.
1548 
1549         @param  rStatus [in|out]
1550         Reference to a class which receives the information of the file or directory
1551         represented by this directory item.
1552 
1553         @return
1554         E_None on success
1555         E_NOMEM not enough memory for allocating structures
1556         E_INVAL the format of the parameters was not valid
1557         E_LOOP too many symbolic links encountered
1558         E_ACCES permission denied
1559         E_NOENT no such file or directory
1560         E_NAMETOOLONG file name too long
1561         E_BADF invalid oslDirectoryItem parameter
1562         E_FAULT bad address
1563         E_OVERFLOW value too large for defined data type
1564         E_INTR function call was interrupted
1565         E_NOLINK link has been severed
1566         E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it
1567         E_MFILE too many open files used by the process
1568         E_NFILE too many open files in the system
1569         E_NOSPC no space left on device
1570         E_NXIO no such device or address
1571         E_IO on I/O errors
1572         E_NOSYS function not implemented
1573 
1574         @see get()
1575         @see Directory::getNextItem()
1576         @see FileStatus
1577     */
1578 
1579     inline RC getFileStatus( FileStatus& rStatus )
1580     {
1581         return (RC) osl_getFileStatus( _pData, &rStatus._aStatus, rStatus._nMask );
1582     }
1583 
1584     friend class Directory;
1585 };
1586 
1587 //###########################################
1588 
1589 /** Base class for observers of directory creation notifications.
1590 
1591     Clients which uses the method createDirectoryPath of the class
1592     Directory may want to be informed about the directories that
1593     have been created. This may be accomplished by deriving from
1594     this base class and overwriting the virtual function
1595     DirectoryCreated.
1596 
1597     @see Directory::createPath
1598 */
1599 class DirectoryCreationObserver
1600 {
1601 public:
1602     virtual ~DirectoryCreationObserver() {};
1603 
1604     /** This method will be called when a new directory has been
1605         created and needs to be overwritten by derived classes.
1606         You must not delete the directory that was just created
1607         otherwise you will run into an endless loop.
1608 
1609         @param aDirectoryUrl
1610         [in]The absolute file URL of the directory that was just created by
1611         ::osl::Directory::createPath.
1612     */
1613     virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) = 0;
1614 };
1615 
1616 //###########################################
1617 // This just an internal helper function for
1618 // private use.
1619 extern "C" inline void SAL_CALL onDirectoryCreated(void* pData, rtl_uString* aDirectoryUrl)
1620 {
1621     (static_cast<DirectoryCreationObserver*>(pData))->DirectoryCreated(aDirectoryUrl);
1622 }
1623 
1624 /** The directory class object provides a enumeration of DirectoryItems.
1625 
1626     @see DirectoryItem
1627     @see File
1628  */
1629 
1630 class Directory: public FileBase
1631 {
1632     oslDirectory    _pData;
1633     ::rtl::OUString _aPath;
1634 
1635     /** Copy constructor.
1636     */
1637 
1638     Directory( Directory& );
1639 
1640     /**  Assignment operator.
1641     */
1642 
1643     Directory& operator = ( Directory& );
1644 
1645 public:
1646 
1647     /** Constructor.
1648 
1649         @param strPath [in]
1650         The full qualified URL of the directory.
1651         Relative URLs are not allowed.
1652      */
1653 
1654     Directory( const ::rtl::OUString& strPath ): _pData( 0 ), _aPath( strPath )
1655     {
1656     }
1657 
1658     /** Destructor.
1659     */
1660 
1661     ~Directory()
1662     {
1663         close();
1664     }
1665 
1666     /** Open a directory for enumerating its contents.
1667 
1668         @return
1669         E_None on success
1670         E_INVAL the format of the parameters was not valid
1671         E_NOENT the specified path doesn't exist
1672         E_NOTDIR the specified path is not an directory
1673         E_NOMEM not enough memory for allocating structures
1674         E_ACCES permission denied
1675         E_MFILE too many open files used by the process
1676         E_NFILE too many open files in the system
1677         E_NAMETOOLONG File name too long
1678         E_LOOP Too many symbolic links encountered
1679 
1680         @see getNextItem()
1681         @see close()
1682     */
1683 
1684     inline RC open()
1685     {
1686         return (RC) osl_openDirectory( _aPath.pData, &_pData );
1687     }
1688 
1689     /** Query if directory is open.
1690 
1691         Query if directory is open and so item enumeration is valid.
1692 
1693         @return
1694         sal_True if the directory is open else sal_False.
1695 
1696         @see open()
1697         @see close()
1698     */
1699 
1700     inline sal_Bool isOpen() { return _pData != NULL; };
1701 
1702     /** Close a directory.
1703 
1704         @return
1705         E_None on success
1706         E_INVAL the format of the parameters was not valid
1707         E_NOMEM not enough memory for allocating structures
1708         E_BADF invalid oslDirectory parameter
1709         E_INTR the function call was interrupted
1710 
1711         @see open()
1712     */
1713 
1714     inline RC close()
1715     {
1716         oslFileError Error = osl_File_E_BADF;
1717 
1718         if( _pData )
1719         {
1720             Error=osl_closeDirectory( _pData );
1721             _pData = NULL;
1722         }
1723 
1724         return (RC) Error;
1725     }
1726 
1727 
1728     /** Resets the directory item enumeration to the beginning.
1729 
1730         @return
1731         E_None on success
1732         E_INVAL the format of the parameters was not valid
1733         E_NOENT the specified path doesn't exist
1734         E_NOTDIR the specified path is not an directory
1735         E_NOMEM not enough memory for allocating structures
1736         E_ACCES permission denied
1737         E_MFILE too many open files used by the process
1738         E_NFILE too many open files in the system
1739         E_NAMETOOLONG File name too long
1740         E_LOOP Too many symbolic links encountered
1741 
1742         @see open()
1743     */
1744 
1745     inline RC reset()
1746     {
1747         close();
1748         return open();
1749     }
1750 
1751     /** Retrieve the next item of a previously opened directory.
1752 
1753         Retrieves the next item of a previously opened directory.
1754 
1755         @param  rItem [out]
1756         On success a valid DirectoryItem.
1757 
1758         @param  nHint [in]
1759         With this parameter the caller can tell the implementation that (s)he
1760         is going to call this function uHint times afterwards. This enables the implementation to
1761         get the information for more than one file and cache it until the next calls.
1762 
1763         @return
1764         E_None on success
1765         E_INVAL the format of the parameters was not valid
1766         E_NOMEM not enough memory for allocating structures
1767         E_NOENT no more entries in this directory
1768         E_BADF invalid oslDirectory parameter
1769         E_OVERFLOW the value too large for defined data type
1770 
1771         @see DirectoryItem
1772     */
1773 
1774     inline RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
1775     {
1776         if( rItem._pData )
1777         {
1778             osl_releaseDirectoryItem( rItem._pData );
1779             rItem._pData = 0;
1780         }
1781         return ( RC) osl_getNextDirectoryItem( _pData, &rItem._pData, nHint );
1782     }
1783 
1784 
1785     /** Retrieve information about a volume.
1786 
1787         Retrieves information about a volume. A volume can either be a mount point, a network
1788         resource or a drive depending on Operating System and File System.
1789 
1790         @param ustrDirectoryURL [in]
1791         Full qualified URL of the volume
1792 
1793         @param rInfo [out]
1794         On success it receives information about the volume.
1795 
1796         @return
1797         E_None on success
1798         E_NOMEM not enough memory for allocating structures
1799         E_INVAL the format of the parameters was not valid
1800         E_NOTDIR not a directory
1801         E_NAMETOOLONG file name too long
1802         E_NOENT no such file or directory
1803         E_ACCES permission denied
1804         E_LOOP too many symbolic links encountered
1805         E_FAULT Bad address
1806         E_IO on I/O errors
1807         E_NOSYS function not implemented
1808         E_MULTIHOP multihop attempted
1809         E_NOLINK link has been severed
1810         E_INTR function call was interrupted
1811 
1812         @see FileStatus
1813         @see VolumeInfo
1814     */
1815 
1816     inline static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
1817     {
1818         return (RC) osl_getVolumeInformation( ustrDirectoryURL.pData, &rInfo._aInfo, rInfo._nMask );
1819     }
1820 
1821     /** Create a directory.
1822 
1823         @param ustrDirectoryURL [in]
1824         Full qualified URL of the directory to create.
1825 
1826         @return
1827         E_None on success
1828         E_INVAL the format of the parameters was not valid
1829         E_NOMEM not enough memory for allocating structures
1830         E_EXIST file exists
1831         E_ACCES permission denied
1832         E_NAMETOOLONG file name too long
1833         E_NOENT no such file or directory
1834         E_NOTDIR not a directory
1835         E_ROFS read-only file system
1836         E_NOSPC no space left on device
1837         E_DQUOT quota exceeded
1838         E_LOOP too many symbolic links encountered
1839         E_FAULT bad address
1840         E_IO on I/O errors
1841         E_MLINK too many links
1842         E_MULTIHOP multihop attempted
1843         E_NOLINK link has been severed
1844 
1845         @see remove()
1846     */
1847 
1848     inline static RC create( const ::rtl::OUString& ustrDirectoryURL )
1849     {
1850         return (RC) osl_createDirectory( ustrDirectoryURL.pData );
1851     }
1852 
1853     /** Remove an empty directory.
1854 
1855         @param ustrDirectoryURL [in]
1856         Full qualified URL of the directory.
1857 
1858         @return
1859         E_None on success
1860         E_INVAL the format of the parameters was not valid
1861         E_NOMEM not enough memory for allocating structures
1862         E_PERM operation not permitted
1863         E_ACCES permission denied
1864         E_NOENT no such file or directory
1865         E_NOTDIR not a directory
1866         E_NOTEMPTY directory not empty
1867         E_FAULT bad address
1868         E_NAMETOOLONG file name too long
1869         E_BUSY device or resource busy
1870         E_ROFS read-only file system
1871         E_LOOP too many symbolic links encountered
1872         E_BUSY device or resource busy
1873         E_EXIST file exists
1874         E_IO on I/O errors
1875         E_MULTIHOP multihop attempted
1876         E_NOLINK link has been severed
1877 
1878         @see create()
1879     */
1880 
1881     inline static RC remove( const ::rtl::OUString& ustrDirectoryURL )
1882     {
1883         return (RC) osl_removeDirectory( ustrDirectoryURL.pData );
1884     }
1885 
1886     /** Create a directory path.
1887 
1888         The osl_createDirectoryPath function creates a specified directory path.
1889         All nonexisting sub directories will be created.
1890         <p><strong>PLEASE NOTE:</strong> You cannot rely on getting the error code
1891         E_EXIST for existing directories. Programming against this error code is
1892         in general a strong indication of a wrong usage of osl_createDirectoryPath.</p>
1893 
1894         @param aDirectoryUrl
1895         [in] The absolute file URL of the directory path to create.
1896         A relative file URL will not be accepted.
1897 
1898         @param aDirectoryCreationObserver
1899         [in] Pointer to an instance of type DirectoryCreationObserver that will
1900         be informed about the creation of a directory. The value of this
1901         parameter may be NULL, in this case notifications will not be sent.
1902 
1903         @return
1904         <dl>
1905         <dt>E_None</dt>
1906         <dd>On success</dd>
1907         <dt>E_INVAL</dt>
1908         <dd>The format of the parameters was not valid</dd>
1909         <dt>E_ACCES</dt>
1910         <dd>Permission denied</dd>
1911         <dt>E_EXIST</dt>
1912         <dd>The final node of the specified directory path already exist</dd>
1913         <dt>E_NAMETOOLONG</dt>
1914         <dd>The name of the specified directory path exceeds the maximum allowed length</dd>
1915         <dt>E_NOTDIR</dt>
1916         <dd>A component of the specified directory path already exist as file in any part of the directory path</dd>
1917         <dt>E_ROFS</dt>
1918         <dd>Read-only file system</dd>
1919         <dt>E_NOSPC</dt>
1920         <dd>No space left on device</dd>
1921         <dt>E_DQUOT</dt>
1922         <dd>Quota exceeded</dd>
1923         <dt>E_FAULT</dt>
1924         <dd>Bad address</dd>
1925         <dt>E_IO</dt>
1926         <dd>I/O error</dd>
1927         <dt>E_LOOP</dt>
1928         <dd>Too many symbolic links encountered</dd>
1929         <dt>E_NOLINK</dt>
1930         <dd>Link has been severed</dd>
1931         <dt>E_invalidError</dt>
1932         <dd>An unknown error occurred</dd>
1933         </dl>
1934 
1935         @see DirectoryCreationObserver
1936         @see create
1937     */
1938     static RC createPath(
1939         const ::rtl::OUString& aDirectoryUrl,
1940         DirectoryCreationObserver* aDirectoryCreationObserver = NULL)
1941     {
1942         return (RC)osl_createDirectoryPath(
1943             aDirectoryUrl.pData,
1944             (aDirectoryCreationObserver) ? onDirectoryCreated : NULL,
1945             aDirectoryCreationObserver);
1946     }
1947 };
1948 
1949 } /* namespace osl */
1950 
1951 #endif  /* __cplusplus */
1952 #endif  /* _OSL_FILE_HXX_ */
1953 
1954