tdf#151073 - enable firebird for appstore build w/o experimental mode
[LibreOffice.git] / include / osl / file.hxx
blobfcbabe96d6749ff1ed07002e38d4f49e78b13375
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_OSL_FILE_HXX
25 #define INCLUDED_OSL_FILE_HXX
27 #include "sal/config.h"
29 #include <string.h>
31 #include <cstddef>
33 #include "sal/log.hxx"
34 #include "osl/time.h"
35 #include "rtl/ustring.hxx"
37 #include "osl/file.h"
38 #include "osl/diagnose.h"
40 namespace rtl { class ByteSequence; }
42 namespace osl
46 /** Base class for all File System specific objects.
48 @see Directory
49 @see DirectoryItem
50 @see File
53 class FileBase
55 public:
57 enum RC {
58 E_None = osl_File_E_None, ///< on success
59 E_PERM = osl_File_E_PERM, ///< operation not permitted
60 E_NOENT = osl_File_E_NOENT, ///< no such file or directory
61 E_SRCH = osl_File_E_SRCH, ///< no process matches the PID
62 E_INTR = osl_File_E_INTR, ///< function call was interrupted
63 E_IO = osl_File_E_IO, ///< I/O error occurred
64 E_NXIO = osl_File_E_NXIO, ///< no such device or address
65 E_2BIG = osl_File_E_2BIG, ///< argument list too long
66 E_NOEXEC = osl_File_E_NOEXEC, ///< invalid executable file format
67 E_BADF = osl_File_E_BADF, ///< bad file descriptor
68 E_CHILD = osl_File_E_CHILD, ///< there are no child processes
69 E_AGAIN = osl_File_E_AGAIN, ///< resource temp unavailable, try again later
70 E_NOMEM = osl_File_E_NOMEM, ///< no memory available
71 E_ACCES = osl_File_E_ACCES, ///< file permissions do not allow operation
72 E_FAULT = osl_File_E_FAULT, ///< bad address; an invalid pointer detected
73 E_BUSY = osl_File_E_BUSY, ///< resource busy
74 E_EXIST = osl_File_E_EXIST, ///< file exists where should only be created
75 E_XDEV = osl_File_E_XDEV, ///< improper link across file systems detected
76 E_NODEV = osl_File_E_NODEV, ///< wrong device type specified
77 E_NOTDIR = osl_File_E_NOTDIR, ///< file isn't a directory where one is needed
78 E_ISDIR = osl_File_E_ISDIR, ///< file is a directory, invalid operation
79 E_INVAL = osl_File_E_INVAL, ///< invalid argument to library function
80 E_NFILE = osl_File_E_NFILE, ///< too many distinct file openings
81 E_MFILE = osl_File_E_MFILE, ///< process has too many distinct files open
82 E_NOTTY = osl_File_E_NOTTY, ///< inappropriate I/O control operation
83 E_FBIG = osl_File_E_FBIG, ///< file too large
84 E_NOSPC = osl_File_E_NOSPC, ///< no space left on device, write failed
85 E_SPIPE = osl_File_E_SPIPE, ///< invalid seek operation (such as on pipe)
86 E_ROFS = osl_File_E_ROFS, ///< illegal modification to read-only filesystem
87 E_MLINK = osl_File_E_MLINK, ///< too many links to file
88 E_PIPE = osl_File_E_PIPE, ///< broken pipe; no process reading from other end of pipe
89 E_DOM = osl_File_E_DOM, ///< domain error (mathematical error)
90 E_RANGE = osl_File_E_RANGE, ///< range error (mathematical error)
91 E_DEADLK = osl_File_E_DEADLK, ///< deadlock avoided
92 E_NAMETOOLONG = osl_File_E_NAMETOOLONG, ///< filename too long
93 E_NOLCK = osl_File_E_NOLCK, ///< no locks available
94 E_NOSYS = osl_File_E_NOSYS, ///< function not implemented
95 E_NOTEMPTY = osl_File_E_NOTEMPTY, ///< directory not empty
96 E_LOOP = osl_File_E_LOOP, ///< too many levels of symbolic links found during name lookup
97 E_ILSEQ = osl_File_E_ILSEQ, ///< invalid or incomplete byte sequence of multibyte char found
98 E_NOLINK = osl_File_E_NOLINK, ///< link has been severed
99 E_MULTIHOP = osl_File_E_MULTIHOP, ///< remote resource is not directly available
100 E_USERS = osl_File_E_USERS, ///< file quote system is confused as there are too many users
101 E_OVERFLOW = osl_File_E_OVERFLOW, ///< value too large for defined data type
102 E_NOTREADY = osl_File_E_NOTREADY, ///< device not ready
103 E_invalidError = osl_File_E_invalidError, ///< unmapped error: always last entry in enum!
104 E_TIMEDOUT = osl_File_E_TIMEDOUT, ///< socket operation timed out
105 E_NETWORK = osl_File_E_NETWORK
109 public:
111 /** Determine a valid unused canonical name for a requested name.
113 Determines a valid unused canonical name for a requested name.
114 Depending on the Operating System and the File System the illegal characters are replaced by valid ones.
115 If a file or directory with the requested name already exists a new name is generated following
116 the common rules on the actual Operating System and File System.
118 @param[in] ustrRequestedURL
119 Requested name of a file or directory.
121 @param[out] ustrValidURL
122 On success receives a name which is unused and valid on the actual Operating System and
123 File System.
125 @retval E_None on success
126 @retval E_INVAL the format of the parameters was not valid
128 @see DirectoryItem::getFileStatus()
131 static RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
133 return static_cast< RC >( osl_getCanonicalName( ustrRequestedURL.pData, &ustrValidURL.pData ) );
136 /** Convert a path relative to a given directory into an full qualified file URL.
138 Convert a path relative to a given directory into an full qualified file URL.
139 The function resolves symbolic links if possible and path ellipses, so on success
140 the resulting absolute path is fully resolved.
142 @param[in] ustrBaseDirectoryURL
143 Base directory URL to which the relative path is related to.
145 @param[in] ustrRelativeFileURL
146 A URL of a file or directory relative to the directory path specified by ustrBaseDirectoryURL
147 or an absolute path.
148 If ustrRelativeFileURL denotes an absolute path ustrBaseDirectoryURL will be ignored.
150 @param[out] ustrAbsoluteFileURL
151 On success it receives the full qualified absolute file URL.
153 @retval E_None on success
154 @retval E_INVAL the format of the parameters was not valid
155 @retval E_NOMEM not enough memory for allocating structures
156 @retval E_NOTDIR not a directory
157 @retval E_ACCES permission denied
158 @retval E_NOENT no such file or directory
159 @retval E_NAMETOOLONG file name too long
160 @retval E_OVERFLOW value too large for defined data type
161 @retval E_FAULT bad address
162 @retval E_INTR function call was interrupted
163 @retval E_LOOP too many symbolic links encountered
164 @retval E_MULTIHOP multihop attempted
165 @retval E_NOLINK link has been severed
167 @see DirectoryItem::getFileStatus()
170 static RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, const ::rtl::OUString& ustrRelativeFileURL, ::rtl::OUString& ustrAbsoluteFileURL )
172 return static_cast< RC >( osl_getAbsoluteFileURL( ustrBaseDirectoryURL.pData, ustrRelativeFileURL.pData, &ustrAbsoluteFileURL.pData ) );
175 /** Convert a file URL into a system dependent path.
177 @param[in] ustrFileURL
178 A File URL.
180 @param[out] ustrSystemPath
181 On success it receives the system path.
183 @retval E_None on success
184 @retval E_INVAL the format of the parameters was not valid
186 @see getFileURLFromSystemPath()
189 static RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, ::rtl::OUString& ustrSystemPath )
191 return static_cast< RC >( osl_getSystemPathFromFileURL( ustrFileURL.pData, &ustrSystemPath.pData ) );
194 /** Convert a system dependent path into a file URL.
196 @param[in] ustrSystemPath
197 A System dependent path of a file or directory.
199 @param[out] ustrFileURL
200 On success it receives the file URL.
202 @retval E_None on success
203 @retval E_INVAL the format of the parameters was not valid
205 @see getSystemPathFromFileURL()
208 static RC getFileURLFromSystemPath( const ::rtl::OUString& ustrSystemPath, ::rtl::OUString& ustrFileURL )
210 return static_cast< RC >( osl_getFileURLFromSystemPath( ustrSystemPath.pData, &ustrFileURL.pData ) );
213 /** Search a full qualified system path or a file URL.
215 @param[in] ustrFileName
216 A system dependent path, a file URL, a file or relative directory
218 @param[in] ustrSearchPath
219 A list of system paths, in which a given file has to be searched. The Notation of a path list is
220 system dependent, e.g. on UNIX system "/usr/bin:/bin" and on Windows "C:\BIN;C:\BATCH".
221 These paths are only for the search of a file or a relative path, otherwise it will be ignored.
222 If ustrSearchPath is NULL or while using the search path the search failed, the function searches for
223 a matching file in all system directories and in the directories listed in the PATH environment
224 variable.
225 The value of an environment variable should be used (e.g. LD_LIBRARY_PATH) if the caller is not
226 aware of the Operating System and so doesn't know which path list delimiter to use.
228 @param[out] ustrFileURL
229 On success it receives the full qualified file URL.
231 @retval E_None on success
232 @retval E_INVAL the format of the parameters was not valid
233 @retval E_NOTDIR not a directory
234 @retval E_NOENT no such file or directory not found
236 @see getFileURLFromSystemPath()
237 @see getSystemPathFromFileURL()
240 static RC searchFileURL( const ::rtl::OUString& ustrFileName, const ::rtl::OUString& ustrSearchPath, ::rtl::OUString& ustrFileURL )
242 return static_cast< RC >( osl_searchFileURL( ustrFileName.pData, ustrSearchPath.pData, &ustrFileURL.pData ) );
245 /** Retrieves the file URL of the system's temporary directory path.
247 @param[out] ustrTempDirURL
248 On success receives the URL of system's temporary directory path.
250 @retval E_None on success
251 @retval E_NOENT no such file or directory not found
254 static RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
256 return static_cast< RC >( osl_getTempDirURL( &ustrTempDirURL.pData ) );
259 /** Creates a temporary file in the directory provided by the caller or the
260 directory returned by getTempDirURL.
261 Under UNIX Operating Systems the file will be created with read and write
262 access for the user exclusively.
263 If the caller requests only a handle to the open file but not the name of
264 it, the file will be automatically removed on close else the caller is
265 responsible for removing the file on success.<br><br>
267 @param[in] pustrDirectoryURL
268 Specifies the full qualified URL where the temporary file should be created.
269 If pustrDirectoryURL is 0 the path returned by osl_getTempDirURL will be used.
271 @param[out] pHandle
272 On success receives a handle to the open file.
273 If pHandle is 0 the file will be closed on return, in this case
274 pustrTempFileURL must not be 0.
276 @param[out] pustrTempFileURL
277 On success receives the full qualified URL of the temporary file.
278 If pustrTempFileURL is 0 the file will be automatically removed
279 on close, in this case pHandle must not be 0.
280 If pustrTempFileURL is not 0 the caller receives the name of the
281 created file and is responsible for removing the file.
283 Description of the different pHandle, ppustrTempFileURL parameter combinations.
284 pHandle is 0 and pustrTempDirURL is 0 - this combination is invalid<br>
285 pHandle is not 0 and pustrTempDirURL is 0 - a handle to the open file
286 will be returned on success and the file will be automatically removed on close<br>
287 pHandle is 0 and pustrTempDirURL is not 0 - the name of the file will be
288 returned, the caller is responsible for opening, closing and removing the file.<br>
289 pHandle is not 0 and pustrTempDirURL is not 0 - a handle to the open file as well as
290 the file name will be returned, the caller is responsible for closing and removing
291 the file.<br>
293 @retval E_None on success
294 @retval E_INVAL the format of the parameter is invalid
295 @retval E_NOMEM not enough memory for allocating structures
296 @retval E_ACCES Permission denied
297 @retval E_NOENT No such file or directory
298 @retval E_NOTDIR Not a directory
299 @retval E_ROFS Read-only file system
300 @retval E_NOSPC No space left on device
301 @retval E_DQUOT Quota exceeded
303 @see getTempDirURL()
306 static RC createTempFile(
307 ::rtl::OUString* pustrDirectoryURL,
308 oslFileHandle* pHandle,
309 ::rtl::OUString* pustrTempFileURL)
311 rtl_uString* pustr_dir_url = pustrDirectoryURL ? pustrDirectoryURL->pData : NULL;
312 rtl_uString** ppustr_tmp_file_url = pustrTempFileURL ? &pustrTempFileURL->pData : NULL;
314 return static_cast< RC >( osl_createTempFile(pustr_dir_url, pHandle, ppustr_tmp_file_url) );
319 /** The VolumeDevice class.
321 @see VolumeInfo
324 class VolumeDevice : public FileBase
326 oslVolumeDeviceHandle _aHandle;
328 public:
330 /** Constructor.
333 VolumeDevice() : _aHandle( NULL )
337 /** Copy constructor.
339 @param rDevice
340 The other volume device.
343 VolumeDevice( const VolumeDevice & rDevice )
345 _aHandle = rDevice._aHandle;
346 if ( _aHandle )
347 osl_acquireVolumeDeviceHandle( _aHandle );
350 /** Destructor.
353 ~VolumeDevice()
355 if ( _aHandle )
356 osl_releaseVolumeDeviceHandle( _aHandle );
359 /** Assignment operator.
361 @param rDevice
362 The other volume device.
365 VolumeDevice & operator =( const VolumeDevice & rDevice )
367 oslVolumeDeviceHandle newHandle = rDevice._aHandle;
369 if ( newHandle )
370 osl_acquireVolumeDeviceHandle( newHandle );
372 if ( _aHandle )
373 osl_releaseVolumeDeviceHandle( _aHandle );
375 _aHandle = newHandle;
377 return *this;
380 /** Get the full qualified URL where a device is mounted to.
382 @return
383 The full qualified URL where the device is mounted to.
385 rtl::OUString getMountPath()
387 rtl::OUString aPath;
388 osl_getVolumeDeviceMountPath( _aHandle, &aPath.pData );
389 return aPath;
392 friend class VolumeInfo;
396 class Directory;
398 /** The VolumeInfo class.
400 Neither copy nor assignment is allowed for this class.
402 @see Directory::getVolumeInfo
406 class VolumeInfo
408 oslVolumeInfo _aInfo;
409 sal_uInt32 _nMask;
410 VolumeDevice _aDevice;
412 /** Copy constructor.
415 VolumeInfo( VolumeInfo& ) SAL_DELETED_FUNCTION;
417 /** Assignment operator.
420 VolumeInfo& operator = ( VolumeInfo& ) SAL_DELETED_FUNCTION;
422 public:
424 /** Constructor.
426 @param nMask
427 Set of flags describing the demanded information.
429 VolumeInfo( sal_uInt32 nMask )
430 : _nMask( nMask )
432 memset( &_aInfo, 0, sizeof( oslVolumeInfo ));
433 _aInfo.uStructSize = sizeof( oslVolumeInfo );
434 _aInfo.pDeviceHandle = &_aDevice._aHandle;
437 ~VolumeInfo()
439 if( _aInfo.ustrFileSystemName )
440 rtl_uString_release( _aInfo.ustrFileSystemName );
443 /** Check if specified fields are valid.
445 @param nMask
446 Set of flags for the fields to check.
448 @return true if all fields are valid else false.
450 bool isValid( sal_uInt32 nMask ) const
452 return ( nMask & _aInfo.uValidFields ) == nMask;
455 /** Check the remote flag.
457 @return
458 true if Attributes are valid and the volume is remote else false.
460 bool getRemoteFlag() const
462 return (_aInfo.uAttributes & osl_Volume_Attribute_Remote) != 0;
465 /** Check the removable flag.
467 @return
468 true if attributes are valid and the volume is removable else false.
470 bool getRemoveableFlag() const
472 return (_aInfo.uAttributes & osl_Volume_Attribute_Removeable) != 0;
475 /** Check the compact disc flag.
477 @return
478 true if attributes are valid and the volume is a CDROM else false.
481 bool getCompactDiscFlag() const
483 return (_aInfo.uAttributes & osl_Volume_Attribute_CompactDisc) != 0;
486 /** Check the floppy disc flag.
488 @return
489 true if attributes are valid and the volume is a floppy disk else false.
492 bool getFloppyDiskFlag() const
494 return (_aInfo.uAttributes & osl_Volume_Attribute_FloppyDisk) != 0;
497 /** Check the fixed disk flag.
499 @return
500 true if attributes are valid and the volume is a fixed disk else false.
503 bool getFixedDiskFlag() const
505 return (_aInfo.uAttributes & osl_Volume_Attribute_FixedDisk) != 0;
508 /** Check the RAM disk flag.
510 @return
511 true if attributes are valid and the volume is a RAM disk else false.
514 bool getRAMDiskFlag() const
516 return (_aInfo.uAttributes & osl_Volume_Attribute_RAMDisk) != 0;
519 /** Determine the total space of a volume device.
521 @return
522 The total diskspace of this volume if this information is valid,
523 0 otherwise.
526 sal_uInt64 getTotalSpace() const
528 return _aInfo.uTotalSpace;
531 /** Determine the free space of a volume device.
533 @return
534 The free diskspace of this volume if this information is valid,
535 0 otherwise.
538 sal_uInt64 getFreeSpace() const
540 return _aInfo.uFreeSpace;
543 /** Determine the used space of a volume device.
545 @return
546 The used diskspace of this volume if this information is valid,
547 0 otherwise.
550 sal_uInt64 getUsedSpace() const
552 return _aInfo.uUsedSpace;
555 /** Determine the maximal length of a file name.
557 @return
558 The maximal length of a file name if this information is valid,
559 0 otherwise.
562 sal_uInt32 getMaxNameLength() const
564 return _aInfo.uMaxNameLength;
567 /** Determine the maximal length of a path name.
569 @return
570 The maximal length of a path if this information is valid,
571 0 otherwise.
574 sal_uInt32 getMaxPathLength() const
576 return _aInfo.uMaxPathLength;
579 /** Determine the name of the volume device's File System.
581 @return
582 The name of the volume's filesystem if this information is valid,
583 otherwise an empty string.
586 ::rtl::OUString getFileSystemName() const
588 return _aInfo.ustrFileSystemName ? ::rtl::OUString( _aInfo.ustrFileSystemName ) : ::rtl::OUString();
592 /** Get the volume device handle.
594 @return
595 The device handle of the volume if this information is valid,
596 otherwise returns NULL;
599 VolumeDevice getDeviceHandle() const
601 return _aDevice;
604 /** Return whether the file system is case sensitive or
605 case insensitive
607 @return
608 true if the file system is case sensitive false otherwise
610 bool isCaseSensitiveFileSystem() const
612 return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Sensitive) != 0;
615 /** Return whether the file system preserves the case of
616 file and directory names or not
618 @return
619 true if the file system preserves the case of file and
620 directory names false otherwise
622 bool isCasePreservingFileSystem() const
624 return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Is_Preserved) != 0;
627 friend class Directory;
631 class DirectoryItem;
633 /** The FileStatus class.
635 @see DirectoryItem::getFileStatus
638 class FileStatus
640 oslFileStatus _aStatus;
641 sal_uInt32 _nMask;
643 /** Copy constructor.
646 FileStatus( FileStatus& ) SAL_DELETED_FUNCTION;
648 /** Assignment operator.
651 FileStatus& operator = ( FileStatus& ) SAL_DELETED_FUNCTION;
653 public:
655 enum Type {
656 Directory = osl_File_Type_Directory,
657 Volume = osl_File_Type_Volume,
658 Regular = osl_File_Type_Regular,
659 Fifo = osl_File_Type_Fifo,
660 Socket = osl_File_Type_Socket,
661 Link = osl_File_Type_Link,
662 Special = osl_File_Type_Special,
663 Unknown = osl_File_Type_Unknown
666 /** Constructor.
668 @param nMask
669 Set of flags describing the demanded information.
671 FileStatus(sal_uInt32 nMask)
672 : _nMask(nMask)
674 memset(&_aStatus, 0, sizeof(_aStatus));
675 _aStatus.uStructSize = sizeof(_aStatus);
678 /** Destructor.
680 ~FileStatus()
682 if ( _aStatus.ustrFileURL )
683 rtl_uString_release( _aStatus.ustrFileURL );
684 if ( _aStatus.ustrLinkTargetURL )
685 rtl_uString_release( _aStatus.ustrLinkTargetURL );
686 if ( _aStatus.ustrFileName )
687 rtl_uString_release( _aStatus.ustrFileName );
690 /** Check if specified fields are valid.
692 @param nMask
693 Set of flags for the fields to check.
695 @return
696 true if all fields are valid else false.
699 bool isValid( sal_uInt32 nMask ) const
701 return ( nMask & _aStatus.uValidFields ) == nMask;
704 /** Get the file type.
706 @return
707 The file type.
709 Type getFileType() const
711 SAL_INFO_IF(
712 !isValid(osl_FileStatus_Mask_Type), "sal.osl",
713 "no FileStatus Type determined");
714 return isValid(osl_FileStatus_Mask_Type)
715 ? static_cast< Type >(_aStatus.eType) : Unknown;
718 /** Is it a directory?
719 This method returns True for both directories, and volumes.
721 @return
722 True if it's a directory, False otherwise.
724 @see getFileType
725 @since LibreOffice 3.6
727 bool isDirectory() const
729 return ( getFileType() == Directory || getFileType() == Volume );
732 /** Is it a regular file?
734 @return
735 True if it's a regular file, False otherwise.
737 @see getFileType
738 @see isFile
739 @see isLink
740 @since LibreOffice 3.6
742 bool isRegular() const
744 return ( getFileType() == Regular );
747 /** Is it a link?
749 @return
750 True if it's a link, False otherwise.
752 @see getFileType
753 @since LibreOffice 3.6
755 bool isLink() const
757 return ( getFileType() == Link );
760 /** Get the file attributes.
762 @return
763 The set of attribute flags of this file.
766 sal_uInt64 getAttributes() const
768 SAL_INFO_IF(
769 !isValid(osl_FileStatus_Mask_Attributes), "sal.osl",
770 "no FileStatus Attributes determined");
771 return _aStatus.uAttributes;
774 /** Get the creation time of this file.
776 @return
777 The creation time if this information is valid, an uninitialized
778 TimeValue otherwise.
781 TimeValue getCreationTime() const
783 SAL_INFO_IF(
784 !isValid(osl_FileStatus_Mask_CreationTime), "sal.osl",
785 "no FileStatus CreationTime determined");
786 return _aStatus.aCreationTime;
789 /** Get the file access time.
791 @return
792 The last access time if this information is valid, an uninitialized
793 TimeValue otherwise.
796 TimeValue getAccessTime() const
798 SAL_INFO_IF(
799 !isValid(osl_FileStatus_Mask_AccessTime), "sal.osl",
800 "no FileStatus AccessTime determined");
801 return _aStatus.aAccessTime;
804 /** Get the file modification time.
806 @return
807 The last modified time if this information is valid, an uninitialized
808 TimeValue otherwise.
811 TimeValue getModifyTime() const
813 SAL_INFO_IF(
814 !isValid(osl_FileStatus_Mask_ModifyTime), "sal.osl",
815 "no FileStatus ModifyTime determined");
816 return _aStatus.aModifyTime;
819 /** Get the size of the file.
821 @return
822 The actual file size if this information is valid, 0 otherwise.
825 sal_uInt64 getFileSize() const
827 SAL_INFO_IF(
828 !isValid(osl_FileStatus_Mask_FileSize), "sal.osl",
829 "no FileStatus FileSize determined");
830 return _aStatus.uFileSize;
833 /** Get the file name.
835 @return
836 The file name if this information is valid, an empty string otherwise.
839 ::rtl::OUString getFileName() const
841 SAL_INFO_IF(
842 !isValid(osl_FileStatus_Mask_FileName), "sal.osl",
843 "no FileStatus FileName determined");
844 return isValid(osl_FileStatus_Mask_FileName)
845 ? rtl::OUString(_aStatus.ustrFileName) : rtl::OUString();
849 /** Get the URL of the file.
851 @return
852 The full qualified URL of the file if this information is valid, an
853 empty string otherwise.
856 ::rtl::OUString getFileURL() const
858 SAL_INFO_IF(
859 !isValid(osl_FileStatus_Mask_FileURL), "sal.osl",
860 "no FileStatus FileURL determined");
861 return isValid(osl_FileStatus_Mask_FileURL)
862 ? rtl::OUString(_aStatus.ustrFileURL) : rtl::OUString();
865 /** Get the link target URL.
867 @return
868 The link target URL if this information is valid, an empty string
869 otherwise.
872 ::rtl::OUString getLinkTargetURL() const
874 SAL_INFO_IF(
875 !isValid(osl_FileStatus_Mask_LinkTargetURL), "sal.osl",
876 "no FileStatus LinkTargetURL determined");
877 return isValid(osl_FileStatus_Mask_LinkTargetURL)
878 ? rtl::OUString(_aStatus.ustrLinkTargetURL) : rtl::OUString();
881 friend class DirectoryItem;
885 /** The file class object provides access to file contents and attributes.
887 @see Directory
888 @see DirectoryItem
891 class File: public FileBase
893 oslFileHandle _pData;
894 ::rtl::OUString _aPath;
896 /** Copy constructor.
899 File( File& ) SAL_DELETED_FUNCTION;
901 /** Assignment operator.
904 File& operator = ( File& ) SAL_DELETED_FUNCTION;
906 public:
908 /** Constructor.
910 @param[in] ustrFileURL
911 The full qualified URL of the file. Relative paths are not allowed.
914 File( const ::rtl::OUString& ustrFileURL ): _pData( NULL ), _aPath( ustrFileURL ) {}
916 /** Destructor
919 ~File()
921 close();
924 /** Obtain the URL.
926 @return
927 the URL with which this File instance was created.
929 @since LibreOffice 4.1
931 rtl::OUString getURL() const { return _aPath; }
933 /** Open a regular file.
935 Open a file. Only regular files can be opened.
937 @param[in] uFlags
938 Specifies the open mode.
940 @retval E_None on success
941 @retval E_NOMEM not enough memory for allocating structures
942 @retval E_INVAL the format of the parameters was not valid
943 @retval E_NAMETOOLONG pathname was too long
944 @retval E_NOENT no such file or directory
945 @retval E_ACCES permission denied
946 @retval E_AGAIN a write lock could not be established
947 @retval E_NOTDIR not a directory
948 @retval E_NXIO no such device or address
949 @retval E_NODEV no such device
950 @retval E_ROFS read-only file system
951 @retval E_TXTBSY text file busy
952 @retval E_FAULT bad address
953 @retval E_LOOP too many symbolic links encountered
954 @retval E_NOSPC no space left on device
955 @retval E_ISDIR is a directory
956 @retval E_MFILE too many open files used by the process
957 @retval E_NFILE too many open files in the system
958 @retval E_DQUOT quota exceeded
959 @retval E_EXIST file exists
960 @retval E_INTR function call was interrupted
961 @retval E_IO on I/O errors
962 @retval E_MULTIHOP multihop attempted
963 @retval E_NOLINK link has been severed
964 @retval E_EOVERFLOW value too large for defined data type
966 @see close()
967 @see setPos()
968 @see getPos()
969 @see read()
970 @see write()
971 @see getSize()
972 @see setSize()
975 RC open( sal_uInt32 uFlags )
977 return static_cast< RC >( osl_openFile( _aPath.pData, &_pData, uFlags ) );
980 /** Close an open file.
982 @retval E_None on success
983 @retval E_INVAL the format of the parameters was not valid
984 @retval E_BADF Bad file
985 @retval E_INTR function call was interrupted
986 @retval E_NOLINK link has been severed
987 @retval E_NOSPC no space left on device
988 @retval E_IO on I/O errors
990 @see open()
993 RC close()
995 oslFileError Error = osl_File_E_BADF;
997 if( _pData )
999 Error=osl_closeFile( _pData );
1000 _pData = NULL;
1003 return static_cast< RC >( Error );
1006 /** Set the internal position pointer of an open file.
1008 @param[in] uHow
1009 Distance to move the internal position pointer (from uPos).
1011 @param[in] uPos
1012 Absolute position from the beginning of the file.
1014 @retval E_None on success
1015 @retval E_INVAL the format of the parameters was not valid
1016 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1018 @see open()
1019 @see getPos()
1022 SAL_WARN_UNUSED_RESULT RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
1024 return static_cast< RC >( osl_setFilePos( _pData, uHow, uPos ) );
1027 /** Retrieve the current position of the internal pointer of an open file.
1029 @param[out] uPos
1030 On success receives the current position of the file pointer.
1032 @retval E_None on success
1033 @retval E_INVAL the format of the parameters was not valid
1034 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1036 @see open()
1037 @see setPos()
1038 @see read()
1039 @see write()
1042 RC getPos( sal_uInt64& uPos )
1044 return static_cast< RC >( osl_getFilePos( _pData, &uPos ) );
1047 /** Test if the end of a file is reached.
1049 @param[out] pIsEOF
1050 Points to a variable that receives the end-of-file status.
1052 @retval E_None on success
1053 @retval E_INVAL the format of the parameters was not valid
1054 @retval E_INTR function call was interrupted
1055 @retval E_IO on I/O errors
1056 @retval E_ISDIR is a directory
1057 @retval E_BADF bad file
1058 @retval E_FAULT bad address
1059 @retval E_AGAIN operation would block
1060 @retval E_NOLINK link has been severed
1062 @see open()
1063 @see read()
1064 @see readLine()
1065 @see setPos()
1068 RC isEndOfFile( sal_Bool *pIsEOF )
1070 return static_cast< RC >( osl_isEndOfFile( _pData, pIsEOF ) );
1073 /** Set the file size of an open file.
1075 Sets the file size of an open file. The file can be truncated or enlarged by the function.
1076 The position of the file pointer is not affeced by this function.
1078 @param[in] uSize
1079 New size in bytes.
1081 @retval E_None on success
1082 @retval E_INVAL the format of the parameters was not valid
1083 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1085 @see open()
1086 @see setPos()
1087 @see getStatus()
1090 RC setSize( sal_uInt64 uSize )
1092 return static_cast< RC >( osl_setFileSize( _pData, uSize ) );
1095 /** Get the file size of an open file.
1097 Gets the file size of an open file.
1098 The position of the file pointer is not affeced by this function.
1100 @param[out] rSize
1101 Current size in bytes.
1103 @retval E_None on success
1104 @retval E_INVAL the format of the parameters was not valid
1105 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1107 @see open()
1108 @see setPos()
1109 @see getSize()
1110 @see setSize()
1111 @see getStatus()
1114 RC getSize( sal_uInt64 &rSize )
1116 return static_cast< RC >( osl_getFileSize( _pData, &rSize ) );
1119 /** Read a number of bytes from a file.
1121 Reads a number of bytes from a file. The internal file pointer is
1122 increased by the number of bytes read.
1124 @param[out] pBuffer
1125 Points to a buffer which receives data. The buffer must be large enough
1126 to hold uBytesRequested bytes.
1128 @param[in] uBytesRequested
1129 Number of bytes which should be retrieved.
1131 @param[out] rBytesRead
1132 On success the number of bytes which have actually been retrieved.
1134 @retval E_None on success
1135 @retval E_INVAL the format of the parameters was not valid
1136 @retval E_INTR function call was interrupted
1137 @retval E_IO on I/O errors
1138 @retval E_ISDIR is a directory
1139 @retval E_BADF bad file
1140 @retval E_FAULT bad address
1141 @retval E_AGAIN operation would block
1142 @retval E_NOLINK link has been severed
1144 @see open()
1145 @see write()
1146 @see readLine()
1147 @see setPos()
1150 RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
1152 return static_cast< RC >( osl_readFile( _pData, pBuffer, uBytesRequested, &rBytesRead ) );
1155 /** Write a number of bytes to a file.
1157 Writes a number of bytes to a file.
1158 The internal file pointer is increased by the number of bytes read.
1160 @param[in] pBuffer
1161 Points to a buffer which contains the data.
1163 @param[in] uBytesToWrite
1164 Number of bytes which should be written.
1166 @param[out] rBytesWritten
1167 On success the number of bytes which have actually been written.
1169 @retval E_None on success
1170 @retval E_INVAL the format of the parameters was not valid
1171 @retval E_FBIG file too large
1172 @retval E_DQUOT quota exceeded
1173 @retval E_AGAIN operation would block
1174 @retval E_BADF bad file
1175 @retval E_FAULT bad address
1176 @retval E_INTR function call was interrupted
1177 @retval E_IO on I/O errors
1178 @retval E_NOLCK no record locks available
1179 @retval E_NOLINK link has been severed
1180 @retval E_NOSPC no space left on device
1181 @retval E_NXIO no such device or address
1183 @see open()
1184 @see read()
1185 @see setPos()
1188 RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
1190 return static_cast< RC >( osl_writeFile( _pData, pBuffer, uBytesToWrite, &rBytesWritten ) );
1194 /** Read a line from a file.
1196 Reads a line from a file. The new line delimiter is NOT returned!
1198 @param[in,out] aSeq
1199 A reference to a ::rtl::ByteSequence that will hold the line read on success.
1201 @retval E_None on success
1202 @retval E_INVAL the format of the parameters was not valid
1203 @retval E_INTR function call was interrupted
1204 @retval E_IO on I/O errors
1205 @retval E_ISDIR is a directory
1206 @retval E_BADF bad file
1207 @retval E_FAULT bad address
1208 @retval E_AGAIN operation would block
1209 @retval E_NOLINK link has been severed
1211 @see open()
1212 @see read()
1213 @see write()
1214 @see setPos()
1217 RC readLine( ::rtl::ByteSequence& aSeq )
1219 return static_cast< RC >( osl_readLine( _pData, reinterpret_cast<sal_Sequence**>(&aSeq) ) );
1222 /** Synchronize the memory representation of a file with that on the physical medium.
1224 The function ensures that all modified data and attributes of the file associated with
1225 the given file handle have been written to the physical medium.
1226 In case the hard disk has a write cache enabled, the data may not really be on
1227 permanent storage when osl_syncFile returns.
1229 @retval E_None On success
1230 @retval E_INVAL The value of the input parameter is invalid
1231 @retval E_BADF The file is not open for writing
1232 @retval E_IO An I/O error occurred
1233 @retval E_NOSPC There is no enough space on the target device
1234 @retval E_ROFS The file is located on a read only file system
1235 @retval E_TIMEDOUT A remote connection timed out. This may happen when a file is on a remote location
1237 @see osl_syncFile()
1238 @see open()
1239 @see write()
1241 RC sync() const
1243 OSL_PRECOND(_pData, "File::sync(): File not open");
1244 return static_cast< RC >(osl_syncFile(_pData));
1247 /** Copy a file to a new destination.
1249 Copies a file to a new destination. Copies only files not directories.
1250 No assumptions should be made about preserving attributes or file time.
1252 @param[in] ustrSourceFileURL
1253 Full qualified URL of the source file.
1255 @param[in] ustrDestFileURL
1256 Full qualified URL of the destination file. A directory is NOT a valid destination file!
1258 @retval E_None on success
1259 @retval E_INVAL the format of the parameters was not valid
1260 @retval E_NOMEM not enough memory for allocating structures
1261 @retval E_ACCES permission denied
1262 @retval E_PERM operation not permitted
1263 @retval E_NAMETOOLONG file name too long
1264 @retval E_NOENT no such file or directory
1265 @retval E_ISDIR is a directory
1266 @retval E_ROFS read-only file system
1268 @see move()
1269 @see remove()
1272 static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1274 return static_cast< RC >( osl_copyFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
1277 /** Move a file or directory to a new destination or renames it.
1279 Moves a file or directory to a new destination or renames it.
1280 File time and attributes are preserved.
1282 @param[in] ustrSourceFileURL
1283 Full qualified URL of the source file.
1285 @param[in] ustrDestFileURL
1286 Full qualified URL of the destination file. An existing directory is NOT a valid destination !
1288 @retval E_None on success
1289 @retval E_INVAL the format of the parameters was not valid
1290 @retval E_NOMEM not enough memory for allocating structures
1291 @retval E_ACCES permission denied
1292 @retval E_PERM operation not permitted
1293 @retval E_NAMETOOLONG file name too long
1294 @retval E_NOENT no such file or directory
1295 @retval E_ROFS read-only file system
1297 @see copy()
1300 static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1302 return static_cast< RC >( osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
1305 /** Move a file to a new destination or rename it, taking old file's identity (if exists).
1307 Moves or renames a file, replacing an existing file if exist. If the old file existed,
1308 moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or
1309 ACLs, are set to old one's (to keep the old file's identity) - currently this is only
1310 implemented fully on Windows; on other platforms, this is mostly equivalent to move().
1312 @param[in] ustrSourceFileURL
1313 Full qualified URL of the source file.
1315 @param[in] ustrDestFileURL
1316 Full qualified URL of the destination file.
1318 @retval E_None on success
1319 @retval E_INVAL the format of the parameters was not valid
1320 @retval E_NOMEM not enough memory for allocating structures
1321 @retval E_ACCES permission denied
1322 @retval E_PERM operation not permitted
1323 @retval E_NAMETOOLONG file name too long
1324 @retval E_NOENT no such file
1325 @retval E_ROFS read-only file system
1326 @retval E_BUSY device or resource busy
1328 @see move()
1330 @since LibreOffice 6.2
1332 static RC replace(const ::rtl::OUString& ustrSourceFileURL,
1333 const ::rtl::OUString& ustrDestFileURL)
1335 return static_cast<RC>(osl_replaceFile(ustrSourceFileURL.pData, ustrDestFileURL.pData));
1338 /** Remove a regular file.
1340 @param[in] ustrFileURL
1341 Full qualified URL of the file to remove.
1343 @retval E_None on success
1344 @retval E_INVAL the format of the parameters was not valid
1345 @retval E_NOMEM not enough memory for allocating structures
1346 @retval E_ACCES permission denied
1347 @retval E_PERM operation not permitted
1348 @retval E_NAMETOOLONG file name too long
1349 @retval E_NOENT no such file or directory
1350 @retval E_ISDIR is a directory
1351 @retval E_ROFS read-only file system
1352 @retval E_FAULT bad address
1353 @retval E_LOOP too many symbolic links encountered
1354 @retval E_IO on I/O errors
1355 @retval E_BUSY device or resource busy
1356 @retval E_INTR function call was interrupted
1357 @retval E_MULTIHOP multihop attempted
1358 @retval E_NOLINK link has been severed
1359 @retval E_TXTBSY text file busy
1361 @see open()
1364 static RC remove( const ::rtl::OUString& ustrFileURL )
1366 return static_cast< RC >( osl_removeFile( ustrFileURL.pData ) );
1369 /** Set file attributes.
1371 @param[in] ustrFileURL
1372 The full qualified file URL.
1374 @param[in] uAttributes
1375 Attributes of the file to be set.
1377 @return
1378 @retval E_None on success
1379 @retval E_INVAL the format of the parameters was not valid
1381 @see FileStatus
1384 static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
1386 return static_cast< RC >( osl_setFileAttributes( ustrFileURL.pData, uAttributes ) );
1389 /** Set the file time.
1391 @param[in] ustrFileURL
1392 The full qualified URL of the file.
1394 @param[in] rCreationTime
1395 Creation time of the given file.
1397 @param[in] rLastAccessTime
1398 Time of the last access of the given file.
1400 @param[in] rLastWriteTime
1401 Time of the last modifying of the given file.
1403 @retval E_None on success
1404 @retval E_INVAL the format of the parameters was not valid
1405 @retval E_NOENT no such file or directory not found
1407 @see FileStatus
1410 static RC setTime(
1411 const ::rtl::OUString& ustrFileURL,
1412 const TimeValue& rCreationTime,
1413 const TimeValue& rLastAccessTime,
1414 const TimeValue& rLastWriteTime )
1416 return static_cast< RC >( osl_setFileTime(
1417 ustrFileURL.pData,
1418 &rCreationTime,
1419 &rLastAccessTime,
1420 &rLastWriteTime ) );
1423 friend class DirectoryItem;
1427 /** The directory item class object provides access to file status information.
1429 @see FileStatus
1432 class DirectoryItem: public FileBase
1434 oslDirectoryItem _pData;
1436 public:
1438 /** Constructor.
1441 DirectoryItem(): _pData( NULL )
1445 /** Copy constructor.
1448 DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
1450 if( _pData )
1451 osl_acquireDirectoryItem( _pData );
1454 /** Destructor.
1457 ~DirectoryItem()
1459 if( _pData )
1460 osl_releaseDirectoryItem( _pData );
1463 /** Assignment operator.
1466 DirectoryItem& operator=(const DirectoryItem& rItem )
1468 if (&rItem != this)
1470 if( _pData )
1471 osl_releaseDirectoryItem( _pData );
1473 _pData = rItem._pData;
1475 if( _pData )
1476 osl_acquireDirectoryItem( _pData );
1478 return *this;
1481 /** Check for validity of this instance.
1483 @return
1484 true if object is valid directory item else false.
1487 bool is()
1489 return _pData != NULL;
1492 /** Retrieve a single directory item.
1494 Retrieves a single directory item. The returned handle has an initial refcount of 1.
1495 Due to performance issues it is not recommended to use this function while
1496 enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead.
1498 @param[in] ustrFileURL
1499 An absolute file URL.
1501 @param[out] rItem
1502 On success it receives a handle which can be used for subsequent calls to osl_getFileStatus().
1503 The handle has to be released by a call to osl_releaseDirectoryItem().
1505 @retval E_None on success
1506 @retval E_INVAL the format of the parameters was not valid
1507 @retval E_NOMEM not enough memory for allocating structures
1508 @retval E_ACCES permission denied
1509 @retval E_MFILE too many open files used by the process
1510 @retval E_NFILE too many open files in the system
1511 @retval E_NOENT no such file or directory
1512 @retval E_LOOP too many symbolic links encountered
1513 @retval E_NAMETOOLONG the file name is too long
1514 @retval E_NOTDIR a component of the path prefix of path is not a directory
1515 @retval E_IO on I/O errors
1516 @retval E_MULTIHOP multihop attempted
1517 @retval E_NOLINK link has been severed
1518 @retval E_FAULT bad address
1519 @retval E_INTR the function call was interrupted
1521 @see FileStatus
1522 @see Directory::getNextItem()
1525 static RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
1527 if( rItem._pData)
1529 osl_releaseDirectoryItem( rItem._pData );
1530 rItem._pData = NULL;
1533 return static_cast< RC >( osl_getDirectoryItem( ustrFileURL.pData, &rItem._pData ) );
1536 /** Retrieve information about a single file or directory.
1538 @param[in,out] rStatus
1539 Reference to a class which receives the information of the file or directory
1540 represented by this directory item.
1542 @retval E_None on success
1543 @retval E_NOMEM not enough memory for allocating structures
1544 @retval E_INVAL the format of the parameters was not valid
1545 @retval E_LOOP too many symbolic links encountered
1546 @retval E_ACCES permission denied
1547 @retval E_NOENT no such file or directory
1548 @retval E_NAMETOOLONG file name too long
1549 @retval E_BADF invalid oslDirectoryItem parameter
1550 @retval E_FAULT bad address
1551 @retval E_OVERFLOW value too large for defined data type
1552 @retval E_INTR function call was interrupted
1553 @retval E_NOLINK link has been severed
1554 @retval E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it
1555 @retval E_MFILE too many open files used by the process
1556 @retval E_NFILE too many open files in the system
1557 @retval E_NOSPC no space left on device
1558 @retval E_NXIO no such device or address
1559 @retval E_IO on I/O errors
1560 @retval E_NOSYS function not implemented
1562 @see get()
1563 @see Directory::getNextItem()
1564 @see FileStatus
1567 RC getFileStatus( FileStatus& rStatus )
1569 return static_cast< RC >( osl_getFileStatus( _pData, &rStatus._aStatus, rStatus._nMask ) );
1572 /** Determine if a directory item point the same underlying file
1574 The comparison is done first by URL, and then by resolving links to
1575 find the target, and finally by comparing inodes on unix.
1577 @param[in] pOther
1578 A directory handle to compare with the underlying object's item
1580 @retval true if the items point to an identical resource<br>
1581 @retval false if the items point to a different resource, or a fatal error occurred<br>
1583 @see osl_getDirectoryItem()
1585 @since LibreOffice 3.6
1587 bool isIdenticalTo( const DirectoryItem &pOther )
1589 return osl_identicalDirectoryItem( _pData, pOther._pData );
1592 friend class Directory;
1596 /** Base class for observers of directory creation notifications.
1598 Clients which uses the method createDirectoryPath of the class
1599 Directory may want to be informed about the directories that
1600 have been created. This may be accomplished by deriving from
1601 this base class and overwriting the virtual function
1602 DirectoryCreated.
1604 @see Directory::createPath
1606 class DirectoryCreationObserver
1608 public:
1609 virtual ~DirectoryCreationObserver() {}
1611 /** This method will be called when a new directory has been
1612 created and needs to be overwritten by derived classes.
1613 You must not delete the directory that was just created
1614 otherwise you will run into an endless loop.
1616 @param aDirectoryUrl
1617 [in]The absolute file URL of the directory that was just created by
1618 ::osl::Directory::createPath.
1620 virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) = 0;
1624 // This just an internal helper function for
1625 // private use.
1626 extern "C" inline void SAL_CALL onDirectoryCreated(void* pData, rtl_uString* aDirectoryUrl)
1628 static_cast<DirectoryCreationObserver*>(pData)->DirectoryCreated(aDirectoryUrl);
1631 /** The directory class object provides an enumeration of DirectoryItems.
1633 @see DirectoryItem
1634 @see File
1637 class Directory: public FileBase
1639 oslDirectory _pData;
1640 ::rtl::OUString _aPath;
1642 /** Copy constructor.
1645 Directory( Directory& ) SAL_DELETED_FUNCTION;
1647 /** Assignment operator.
1650 Directory& operator = ( Directory& ) SAL_DELETED_FUNCTION;
1652 public:
1654 /** Constructor.
1656 @param[in] strPath
1657 The full qualified URL of the directory.
1658 Relative URLs are not allowed.
1661 Directory( const ::rtl::OUString& strPath ): _pData( NULL ), _aPath( strPath )
1665 /** Destructor.
1668 ~Directory()
1670 close();
1673 /** Obtain the URL.
1675 @return
1676 the URL with which this Directory instance was created.
1678 @since LibreOffice 4.1
1680 rtl::OUString getURL() const { return _aPath; }
1682 /** Open a directory for enumerating its contents.
1684 @retval E_None on success
1685 @retval E_INVAL the format of the parameters was not valid
1686 @retval E_NOENT the specified path doesn't exist
1687 @retval E_NOTDIR the specified path is not a directory
1688 @retval E_NOMEM not enough memory for allocating structures
1689 @retval E_ACCES permission denied
1690 @retval E_MFILE too many open files used by the process
1691 @retval E_NFILE too many open files in the system
1692 @retval E_NAMETOOLONG File name too long
1693 @retval E_LOOP Too many symbolic links encountered
1695 @see getNextItem()
1696 @see close()
1699 RC open()
1701 return static_cast< RC >( osl_openDirectory( _aPath.pData, &_pData ) );
1704 /** Query if directory is open.
1706 Query if directory is open and so item enumeration is valid.
1708 @retval true if the directory is open else false.
1710 @see open()
1711 @see close()
1714 bool isOpen() { return _pData != NULL; }
1716 /** Close a directory.
1718 @retval E_None on success
1719 @retval E_INVAL the format of the parameters was not valid
1720 @retval E_NOMEM not enough memory for allocating structures
1721 @retval E_BADF invalid oslDirectory parameter
1722 @retval E_INTR the function call was interrupted
1724 @see open()
1727 RC close()
1729 oslFileError Error = osl_File_E_BADF;
1731 if( _pData )
1733 Error=osl_closeDirectory( _pData );
1734 _pData = NULL;
1737 return static_cast< RC >( Error );
1741 /** Resets the directory item enumeration to the beginning.
1743 @retval E_None on success
1744 @retval E_INVAL the format of the parameters was not valid
1745 @retval E_NOENT the specified path doesn't exist
1746 @retval E_NOTDIR the specified path is not a directory
1747 @retval E_NOMEM not enough memory for allocating structures
1748 @retval E_ACCES permission denied
1749 @retval E_MFILE too many open files used by the process
1750 @retval E_NFILE too many open files in the system
1751 @retval E_NAMETOOLONG File name too long
1752 @retval E_LOOP Too many symbolic links encountered
1754 @see open()
1757 RC reset()
1759 close();
1760 return open();
1763 /** Retrieve the next item of a previously opened directory.
1765 Retrieves the next item of a previously opened directory.
1767 @param[out] rItem
1768 On success a valid DirectoryItem.
1770 @param[in] nHint
1771 With this parameter the caller can tell the implementation that (s)he
1772 is going to call this function uHint times afterwards. This enables the implementation to
1773 get the information for more than one file and cache it until the next calls.
1775 @retval E_None on success
1776 @retval E_INVAL the format of the parameters was not valid
1777 @retval E_NOMEM not enough memory for allocating structures
1778 @retval E_NOENT no more entries in this directory
1779 @retval E_BADF invalid oslDirectory parameter
1780 @retval E_OVERFLOW the value too large for defined data type
1782 @see DirectoryItem
1785 RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
1787 if( rItem._pData )
1789 osl_releaseDirectoryItem( rItem._pData );
1790 rItem._pData = NULL;
1792 return static_cast<RC>(osl_getNextDirectoryItem( _pData, &rItem._pData, nHint ));
1796 /** Retrieve information about a volume.
1798 Retrieves information about a volume. A volume can either be a mount point, a network
1799 resource or a drive depending on Operating System and File System.
1801 @param[in] ustrDirectoryURL
1802 Full qualified URL of the volume
1804 @param[out] rInfo
1805 On success it receives information about the volume.
1807 @retval E_None on success
1808 @retval E_NOMEM not enough memory for allocating structures
1809 @retval E_INVAL the format of the parameters was not valid
1810 @retval E_NOTDIR not a directory
1811 @retval E_NAMETOOLONG file name too long
1812 @retval E_NOENT no such file or directory
1813 @retval E_ACCES permission denied
1814 @retval E_LOOP too many symbolic links encountered
1815 @retval E_FAULT Bad address
1816 @retval E_IO on I/O errors
1817 @retval E_NOSYS function not implemented
1818 @retval E_MULTIHOP multihop attempted
1819 @retval E_NOLINK link has been severed
1820 @retval E_INTR function call was interrupted
1822 @see FileStatus
1823 @see VolumeInfo
1826 static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
1828 return static_cast< RC >( osl_getVolumeInformation( ustrDirectoryURL.pData, &rInfo._aInfo, rInfo._nMask ) );
1831 /** Create a directory.
1833 @param[in] ustrDirectoryURL
1834 Full qualified URL of the directory to create.
1836 @param[in] flags
1837 Optional flags, see osl_createDirectoryWithFlags for details. This
1838 defaulted parameter is new since LibreOffice 4.3.
1840 @retval E_None on success
1841 @retval E_INVAL the format of the parameters was not valid
1842 @retval E_NOMEM not enough memory for allocating structures
1843 @retval E_EXIST file exists
1844 @retval E_ACCES permission denied
1845 @retval E_NAMETOOLONG file name too long
1846 @retval E_NOENT no such file or directory
1847 @retval E_NOTDIR not a directory
1848 @retval E_ROFS read-only file system
1849 @retval E_NOSPC no space left on device
1850 @retval E_DQUOT quota exceeded
1851 @retval E_LOOP too many symbolic links encountered
1852 @retval E_FAULT bad address
1853 @retval E_IO on I/O errors
1854 @retval E_MLINK too many links
1855 @retval E_MULTIHOP multihop attempted
1856 @retval E_NOLINK link has been severed
1858 @see remove()
1861 static RC create(
1862 const ::rtl::OUString& ustrDirectoryURL,
1863 sal_uInt32 flags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write )
1865 return static_cast< RC >(
1866 osl_createDirectoryWithFlags( ustrDirectoryURL.pData, flags ) );
1869 /** Remove an empty directory.
1871 @param[in] ustrDirectoryURL
1872 Full qualified URL of the directory.
1874 @retval E_None on success
1875 @retval E_INVAL the format of the parameters was not valid
1876 @retval E_NOMEM not enough memory for allocating structures
1877 @retval E_PERM operation not permitted
1878 @retval E_ACCES permission denied
1879 @retval E_NOENT no such file or directory
1880 @retval E_NOTDIR not a directory
1881 @retval E_NOTEMPTY directory not empty
1882 @retval E_FAULT bad address
1883 @retval E_NAMETOOLONG file name too long
1884 @retval E_BUSY device or resource busy
1885 @retval E_ROFS read-only file system
1886 @retval E_LOOP too many symbolic links encountered
1887 @retval E_EXIST file exists
1888 @retval E_IO on I/O errors
1889 @retval E_MULTIHOP multihop attempted
1890 @retval E_NOLINK link has been severed
1892 @see create()
1895 static RC remove( const ::rtl::OUString& ustrDirectoryURL )
1897 return static_cast< RC >( osl_removeDirectory( ustrDirectoryURL.pData ) );
1900 /** Create a directory path.
1902 The osl_createDirectoryPath function creates a specified directory path.
1903 All nonexisting sub directories will be created.
1905 @attention You cannot rely on getting the error code E_EXIST for existing
1906 directories. Programming against this error code is in general a strong
1907 indication of a wrong usage of osl_createDirectoryPath.
1909 @param aDirectoryUrl
1910 [in] The absolute file URL of the directory path to create.
1911 A relative file URL will not be accepted.
1913 @param aDirectoryCreationObserver
1914 [in] Pointer to an instance of type DirectoryCreationObserver that will
1915 be informed about the creation of a directory. The value of this
1916 parameter may be NULL, in this case notifications will not be sent.
1918 @retval E_None On success
1919 @retval E_INVAL The format of the parameters was not valid
1920 @retval E_ACCES Permission denied
1921 @retval E_EXIST The final node of the specified directory path already exist
1922 @retval E_NAMETOOLONG The name of the specified directory path exceeds the maximum allowed length
1923 @retval E_NOTDIR A component of the specified directory path already exist as file in any part of the directory path
1924 @retval E_ROFS Read-only file system
1925 @retval E_NOSPC No space left on device
1926 @retval E_DQUOT Quota exceeded
1927 @retval E_FAULT Bad address
1928 @retval E_IO I/O error
1929 @retval E_LOOP Too many symbolic links encountered
1930 @retval E_NOLINK Link has been severed
1931 @retval E_invalidError An unknown error occurred
1933 @see DirectoryCreationObserver
1934 @see create
1936 static RC createPath(
1937 const ::rtl::OUString& aDirectoryUrl,
1938 DirectoryCreationObserver* aDirectoryCreationObserver = NULL)
1940 return static_cast< RC >(osl_createDirectoryPath(
1941 aDirectoryUrl.pData,
1942 aDirectoryCreationObserver ? onDirectoryCreated : NULL,
1943 aDirectoryCreationObserver));
1947 } /* namespace osl */
1949 #endif // INCLUDED_OSL_FILE_HXX
1951 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */