tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / include / osl / file.hxx
blob1f1121d547e26dca2f9785115655054faec708b9
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"
39 namespace rtl { class ByteSequence; }
41 namespace osl
45 /** Base class for all File System specific objects.
47 @see Directory
48 @see DirectoryItem
49 @see File
52 class FileBase
54 public:
56 enum RC {
57 E_None = osl_File_E_None, ///< on success
58 E_PERM = osl_File_E_PERM, ///< operation not permitted
59 E_NOENT = osl_File_E_NOENT, ///< no such file or directory
60 E_SRCH = osl_File_E_SRCH, ///< no process matches the PID
61 E_INTR = osl_File_E_INTR, ///< function call was interrupted
62 E_IO = osl_File_E_IO, ///< I/O error occurred
63 E_NXIO = osl_File_E_NXIO, ///< no such device or address
64 E_2BIG = osl_File_E_2BIG, ///< argument list too long
65 E_NOEXEC = osl_File_E_NOEXEC, ///< invalid executable file format
66 E_BADF = osl_File_E_BADF, ///< bad file descriptor
67 E_CHILD = osl_File_E_CHILD, ///< there are no child processes
68 E_AGAIN = osl_File_E_AGAIN, ///< resource temp unavailable, try again later
69 E_NOMEM = osl_File_E_NOMEM, ///< no memory available
70 E_ACCES = osl_File_E_ACCES, ///< file permissions do not allow operation
71 E_FAULT = osl_File_E_FAULT, ///< bad address; an invalid pointer detected
72 E_BUSY = osl_File_E_BUSY, ///< resource busy
73 E_EXIST = osl_File_E_EXIST, ///< file exists where should only be created
74 E_XDEV = osl_File_E_XDEV, ///< improper link across file systems detected
75 E_NODEV = osl_File_E_NODEV, ///< wrong device type specified
76 E_NOTDIR = osl_File_E_NOTDIR, ///< file isn't a directory where one is needed
77 E_ISDIR = osl_File_E_ISDIR, ///< file is a directory, invalid operation
78 E_INVAL = osl_File_E_INVAL, ///< invalid argument to library function
79 E_NFILE = osl_File_E_NFILE, ///< too many distinct file openings
80 E_MFILE = osl_File_E_MFILE, ///< process has too many distinct files open
81 E_NOTTY = osl_File_E_NOTTY, ///< inappropriate I/O control operation
82 E_FBIG = osl_File_E_FBIG, ///< file too large
83 E_NOSPC = osl_File_E_NOSPC, ///< no space left on device, write failed
84 E_SPIPE = osl_File_E_SPIPE, ///< invalid seek operation (such as on pipe)
85 E_ROFS = osl_File_E_ROFS, ///< illegal modification to read-only filesystem
86 E_MLINK = osl_File_E_MLINK, ///< too many links to file
87 E_PIPE = osl_File_E_PIPE, ///< broken pipe; no process reading from other end of pipe
88 E_DOM = osl_File_E_DOM, ///< domain error (mathematical error)
89 E_RANGE = osl_File_E_RANGE, ///< range error (mathematical error)
90 E_DEADLK = osl_File_E_DEADLK, ///< deadlock avoided
91 E_NAMETOOLONG = osl_File_E_NAMETOOLONG, ///< filename too long
92 E_NOLCK = osl_File_E_NOLCK, ///< no locks available
93 E_NOSYS = osl_File_E_NOSYS, ///< function not implemented
94 E_NOTEMPTY = osl_File_E_NOTEMPTY, ///< directory not empty
95 E_LOOP = osl_File_E_LOOP, ///< too many levels of symbolic links found during name lookup
96 E_ILSEQ = osl_File_E_ILSEQ, ///< invalid or incomplete byte sequence of multibyte char found
97 E_NOLINK = osl_File_E_NOLINK, ///< link has been severed
98 E_MULTIHOP = osl_File_E_MULTIHOP, ///< remote resource is not directly available
99 E_USERS = osl_File_E_USERS, ///< file quote system is confused as there are too many users
100 E_OVERFLOW = osl_File_E_OVERFLOW, ///< value too large for defined data type
101 E_NOTREADY = osl_File_E_NOTREADY, ///< device not ready
102 E_invalidError = osl_File_E_invalidError, ///< unmapped error: always last entry in enum!
103 E_TIMEDOUT = osl_File_E_TIMEDOUT, ///< socket operation timed out
104 E_NETWORK = osl_File_E_NETWORK
108 public:
110 /** Determine a valid unused canonical name for a requested name.
112 Determines a valid unused canonical name for a requested name.
113 Depending on the Operating System and the File System the illegal characters are replaced by valid ones.
114 If a file or directory with the requested name already exists a new name is generated following
115 the common rules on the actual Operating System and File System.
117 @param[in] ustrRequestedURL
118 Requested name of a file or directory.
120 @param[out] ustrValidURL
121 On success receives a name which is unused and valid on the actual Operating System and
122 File System.
124 @retval E_None on success
125 @retval E_INVAL the format of the parameters was not valid
127 @see DirectoryItem::getFileStatus()
130 static RC getCanonicalName( const ::rtl::OUString& ustrRequestedURL, ::rtl::OUString& ustrValidURL )
132 return static_cast< RC >( osl_getCanonicalName( ustrRequestedURL.pData, &ustrValidURL.pData ) );
135 /** Convert a path relative to a given directory into an full qualified file URL.
137 Convert a path relative to a given directory into an full qualified file URL.
138 The function resolves symbolic links if possible and path ellipses, so on success
139 the resulting absolute path is fully resolved.
141 @param[in] ustrBaseDirectoryURL
142 Base directory URL to which the relative path is related to.
144 @param[in] ustrRelativeFileURL
145 A URL of a file or directory relative to the directory path specified by ustrBaseDirectoryURL
146 or an absolute path.
147 If ustrRelativeFileURL denotes an absolute path ustrBaseDirectoryURL will be ignored.
149 @param[out] ustrAbsoluteFileURL
150 On success it receives the full qualified absolute file URL.
152 @retval E_None on success
153 @retval E_INVAL the format of the parameters was not valid
154 @retval E_NOMEM not enough memory for allocating structures
155 @retval E_NOTDIR not a directory
156 @retval E_ACCES permission denied
157 @retval E_NOENT no such file or directory
158 @retval E_NAMETOOLONG file name too long
159 @retval E_OVERFLOW value too large for defined data type
160 @retval E_FAULT bad address
161 @retval E_INTR function call was interrupted
162 @retval E_LOOP too many symbolic links encountered
163 @retval E_MULTIHOP multihop attempted
164 @retval E_NOLINK link has been severed
166 @see DirectoryItem::getFileStatus()
169 static RC getAbsoluteFileURL( const ::rtl::OUString& ustrBaseDirectoryURL, const ::rtl::OUString& ustrRelativeFileURL, ::rtl::OUString& ustrAbsoluteFileURL )
171 return static_cast< RC >( osl_getAbsoluteFileURL( ustrBaseDirectoryURL.pData, ustrRelativeFileURL.pData, &ustrAbsoluteFileURL.pData ) );
174 /** Convert a file URL into a system dependent path.
176 @param[in] ustrFileURL
177 A File URL.
179 @param[out] ustrSystemPath
180 On success it receives the system path.
182 @retval E_None on success
183 @retval E_INVAL the format of the parameters was not valid
185 @see getFileURLFromSystemPath()
188 static RC getSystemPathFromFileURL( const ::rtl::OUString& ustrFileURL, ::rtl::OUString& ustrSystemPath )
190 return static_cast< RC >( osl_getSystemPathFromFileURL( ustrFileURL.pData, &ustrSystemPath.pData ) );
193 /** Convert a system dependent path into a file URL.
195 @param[in] ustrSystemPath
196 A System dependent path of a file or directory.
198 @param[out] ustrFileURL
199 On success it receives the file URL.
201 @retval E_None on success
202 @retval E_INVAL the format of the parameters was not valid
204 @see getSystemPathFromFileURL()
207 static RC getFileURLFromSystemPath( const ::rtl::OUString& ustrSystemPath, ::rtl::OUString& ustrFileURL )
209 return static_cast< RC >( osl_getFileURLFromSystemPath( ustrSystemPath.pData, &ustrFileURL.pData ) );
212 /** Search a full qualified system path or a file URL.
214 @param[in] ustrFileName
215 A system dependent path, a file URL, a file or relative directory
217 @param[in] ustrSearchPath
218 A list of system paths, in which a given file has to be searched. The Notation of a path list is
219 system dependent, e.g. on UNIX system "/usr/bin:/bin" and on Windows "C:\BIN;C:\BATCH".
220 These paths are only for the search of a file or a relative path, otherwise it will be ignored.
221 If ustrSearchPath is NULL or while using the search path the search failed, the function searches for
222 a matching file in all system directories and in the directories listed in the PATH environment
223 variable.
224 The value of an environment variable should be used (e.g. LD_LIBRARY_PATH) if the caller is not
225 aware of the Operating System and so doesn't know which path list delimiter to use.
227 @param[out] ustrFileURL
228 On success it receives the full qualified file URL.
230 @retval E_None on success
231 @retval E_INVAL the format of the parameters was not valid
232 @retval E_NOTDIR not a directory
233 @retval E_NOENT no such file or directory not found
235 @see getFileURLFromSystemPath()
236 @see getSystemPathFromFileURL()
239 static RC searchFileURL( const ::rtl::OUString& ustrFileName, const ::rtl::OUString& ustrSearchPath, ::rtl::OUString& ustrFileURL )
241 return static_cast< RC >( osl_searchFileURL( ustrFileName.pData, ustrSearchPath.pData, &ustrFileURL.pData ) );
244 /** Retrieves the file URL of the system's temporary directory path.
246 @param[out] ustrTempDirURL
247 On success receives the URL of system's temporary directory path.
249 @retval E_None on success
250 @retval E_NOENT no such file or directory not found
253 static RC getTempDirURL( ::rtl::OUString& ustrTempDirURL )
255 return static_cast< RC >( osl_getTempDirURL( &ustrTempDirURL.pData ) );
258 /** Creates a temporary file in the directory provided by the caller or the
259 directory returned by getTempDirURL.
260 Under UNIX Operating Systems the file will be created with read and write
261 access for the user exclusively.
262 If the caller requests only a handle to the open file but not the name of
263 it, the file will be automatically removed on close else the caller is
264 responsible for removing the file on success.<br><br>
266 @param[in] pustrDirectoryURL
267 Specifies the full qualified URL where the temporary file should be created.
268 If pustrDirectoryURL is 0 the path returned by osl_getTempDirURL will be used.
270 @param[out] pHandle
271 On success receives a handle to the open file.
272 If pHandle is 0 the file will be closed on return, in this case
273 pustrTempFileURL must not be 0.
275 @param[out] pustrTempFileURL
276 On success receives the full qualified URL of the temporary file.
277 If pustrTempFileURL is 0 the file will be automatically removed
278 on close, in this case pHandle must not be 0.
279 If pustrTempFileURL is not 0 the caller receives the name of the
280 created file and is responsible for removing the file.
282 Description of the different pHandle, ppustrTempFileURL parameter combinations.
283 pHandle is 0 and pustrTempDirURL is 0 - this combination is invalid<br>
284 pHandle is not 0 and pustrTempDirURL is 0 - a handle to the open file
285 will be returned on success and the file will be automatically removed on close<br>
286 pHandle is 0 and pustrTempDirURL is not 0 - the name of the file will be
287 returned, the caller is responsible for opening, closing and removing the file.<br>
288 pHandle is not 0 and pustrTempDirURL is not 0 - a handle to the open file as well as
289 the file name will be returned, the caller is responsible for closing and removing
290 the file.<br>
292 @retval E_None on success
293 @retval E_INVAL the format of the parameter is invalid
294 @retval E_NOMEM not enough memory for allocating structures
295 @retval E_ACCES Permission denied
296 @retval E_NOENT No such file or directory
297 @retval E_NOTDIR Not a directory
298 @retval E_ROFS Read-only file system
299 @retval E_NOSPC No space left on device
300 @retval E_DQUOT Quota exceeded
302 @see getTempDirURL()
305 static RC createTempFile(
306 ::rtl::OUString* pustrDirectoryURL,
307 oslFileHandle* pHandle,
308 ::rtl::OUString* pustrTempFileURL)
310 rtl_uString* pustr_dir_url = pustrDirectoryURL ? pustrDirectoryURL->pData : NULL;
311 rtl_uString** ppustr_tmp_file_url = pustrTempFileURL ? &pustrTempFileURL->pData : NULL;
313 return static_cast< RC >( osl_createTempFile(pustr_dir_url, pHandle, ppustr_tmp_file_url) );
318 /** The VolumeDevice class.
320 @see VolumeInfo
323 class VolumeDevice : public FileBase
325 oslVolumeDeviceHandle _aHandle;
327 public:
329 /** Constructor.
332 VolumeDevice() : _aHandle( NULL )
336 /** Copy constructor.
338 @param rDevice
339 The other volume device.
342 VolumeDevice( const VolumeDevice & rDevice )
344 _aHandle = rDevice._aHandle;
345 if ( _aHandle )
346 osl_acquireVolumeDeviceHandle( _aHandle );
349 /** Destructor.
352 ~VolumeDevice()
354 if ( _aHandle )
355 osl_releaseVolumeDeviceHandle( _aHandle );
358 /** Assignment operator.
360 @param rDevice
361 The other volume device.
364 VolumeDevice & operator =( const VolumeDevice & rDevice )
366 oslVolumeDeviceHandle newHandle = rDevice._aHandle;
368 if ( newHandle )
369 osl_acquireVolumeDeviceHandle( newHandle );
371 if ( _aHandle )
372 osl_releaseVolumeDeviceHandle( _aHandle );
374 _aHandle = newHandle;
376 return *this;
379 /** Get the full qualified URL where a device is mounted to.
381 @return
382 The full qualified URL where the device is mounted to.
384 rtl::OUString getMountPath()
386 rtl::OUString aPath;
387 osl_getVolumeDeviceMountPath( _aHandle, &aPath.pData );
388 return aPath;
391 friend class VolumeInfo;
395 class Directory;
397 /** The VolumeInfo class.
399 Neither copy nor assignment is allowed for this class.
401 @see Directory::getVolumeInfo
405 class VolumeInfo
407 oslVolumeInfo _aInfo;
408 sal_uInt32 _nMask;
409 VolumeDevice _aDevice;
411 /** Copy constructor.
414 VolumeInfo( VolumeInfo& ) SAL_DELETED_FUNCTION;
416 /** Assignment operator.
419 VolumeInfo& operator = ( VolumeInfo& ) SAL_DELETED_FUNCTION;
421 public:
423 /** Constructor.
425 @param nMask
426 Set of flags describing the demanded information.
428 VolumeInfo( sal_uInt32 nMask )
429 : _nMask( nMask )
431 memset( &_aInfo, 0, sizeof( oslVolumeInfo ));
432 _aInfo.uStructSize = sizeof( oslVolumeInfo );
433 _aInfo.pDeviceHandle = &_aDevice._aHandle;
436 ~VolumeInfo()
438 if( _aInfo.ustrFileSystemName )
439 rtl_uString_release( _aInfo.ustrFileSystemName );
442 /** Check if specified fields are valid.
444 @param nMask
445 Set of flags for the fields to check.
447 @return true if all fields are valid else false.
449 bool isValid( sal_uInt32 nMask ) const
451 return ( nMask & _aInfo.uValidFields ) == nMask;
454 /** Check the remote flag.
456 @return
457 true if Attributes are valid and the volume is remote else false.
459 bool getRemoteFlag() const
461 return (_aInfo.uAttributes & osl_Volume_Attribute_Remote) != 0;
464 /** Check the removable flag.
466 @return
467 true if attributes are valid and the volume is removable else false.
469 bool getRemoveableFlag() const
471 return (_aInfo.uAttributes & osl_Volume_Attribute_Removeable) != 0;
474 /** Check the compact disc flag.
476 @return
477 true if attributes are valid and the volume is a CDROM else false.
480 bool getCompactDiscFlag() const
482 return (_aInfo.uAttributes & osl_Volume_Attribute_CompactDisc) != 0;
485 /** Check the floppy disc flag.
487 @return
488 true if attributes are valid and the volume is a floppy disk else false.
491 bool getFloppyDiskFlag() const
493 return (_aInfo.uAttributes & osl_Volume_Attribute_FloppyDisk) != 0;
496 /** Check the fixed disk flag.
498 @return
499 true if attributes are valid and the volume is a fixed disk else false.
502 bool getFixedDiskFlag() const
504 return (_aInfo.uAttributes & osl_Volume_Attribute_FixedDisk) != 0;
507 /** Check the RAM disk flag.
509 @return
510 true if attributes are valid and the volume is a RAM disk else false.
513 bool getRAMDiskFlag() const
515 return (_aInfo.uAttributes & osl_Volume_Attribute_RAMDisk) != 0;
518 /** Determine the total space of a volume device.
520 @return
521 The total diskspace of this volume if this information is valid,
522 0 otherwise.
525 sal_uInt64 getTotalSpace() const
527 return _aInfo.uTotalSpace;
530 /** Determine the free space of a volume device.
532 @return
533 The free diskspace of this volume if this information is valid,
534 0 otherwise.
537 sal_uInt64 getFreeSpace() const
539 return _aInfo.uFreeSpace;
542 /** Determine the used space of a volume device.
544 @return
545 The used diskspace of this volume if this information is valid,
546 0 otherwise.
549 sal_uInt64 getUsedSpace() const
551 return _aInfo.uUsedSpace;
554 /** Determine the maximal length of a file name.
556 @return
557 The maximal length of a file name if this information is valid,
558 0 otherwise.
561 sal_uInt32 getMaxNameLength() const
563 return _aInfo.uMaxNameLength;
566 /** Determine the maximal length of a path name.
568 @return
569 The maximal length of a path if this information is valid,
570 0 otherwise.
573 sal_uInt32 getMaxPathLength() const
575 return _aInfo.uMaxPathLength;
578 /** Determine the name of the volume device's File System.
580 @return
581 The name of the volume's filesystem if this information is valid,
582 otherwise an empty string.
585 ::rtl::OUString getFileSystemName() const
587 return _aInfo.ustrFileSystemName ? ::rtl::OUString( _aInfo.ustrFileSystemName ) : ::rtl::OUString();
591 /** Get the volume device handle.
593 @return
594 The device handle of the volume if this information is valid,
595 otherwise returns NULL;
598 VolumeDevice getDeviceHandle() const
600 return _aDevice;
603 /** Return whether the file system is case sensitive or
604 case insensitive
606 @return
607 true if the file system is case sensitive false otherwise
609 bool isCaseSensitiveFileSystem() const
611 return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Sensitive) != 0;
614 /** Return whether the file system preserves the case of
615 file and directory names or not
617 @return
618 true if the file system preserves the case of file and
619 directory names false otherwise
621 bool isCasePreservingFileSystem() const
623 return (_aInfo.uAttributes & osl_Volume_Attribute_Case_Is_Preserved) != 0;
626 friend class Directory;
630 class DirectoryItem;
632 /** The FileStatus class.
634 @see DirectoryItem::getFileStatus
637 class FileStatus
639 oslFileStatus _aStatus;
640 sal_uInt32 _nMask;
642 /** Copy constructor.
645 FileStatus( FileStatus& ) SAL_DELETED_FUNCTION;
647 /** Assignment operator.
650 FileStatus& operator = ( FileStatus& ) SAL_DELETED_FUNCTION;
652 public:
654 enum Type {
655 Directory = osl_File_Type_Directory,
656 Volume = osl_File_Type_Volume,
657 Regular = osl_File_Type_Regular,
658 Fifo = osl_File_Type_Fifo,
659 Socket = osl_File_Type_Socket,
660 Link = osl_File_Type_Link,
661 Special = osl_File_Type_Special,
662 Unknown = osl_File_Type_Unknown
665 /** Constructor.
667 @param nMask
668 Set of flags describing the demanded information.
670 FileStatus(sal_uInt32 nMask)
671 : _nMask(nMask)
673 memset(&_aStatus, 0, sizeof(_aStatus));
674 _aStatus.uStructSize = sizeof(_aStatus);
677 /** Destructor.
679 ~FileStatus()
681 if ( _aStatus.ustrFileURL )
682 rtl_uString_release( _aStatus.ustrFileURL );
683 if ( _aStatus.ustrLinkTargetURL )
684 rtl_uString_release( _aStatus.ustrLinkTargetURL );
685 if ( _aStatus.ustrFileName )
686 rtl_uString_release( _aStatus.ustrFileName );
689 /** Check if specified fields are valid.
691 @param nMask
692 Set of flags for the fields to check.
694 @return
695 true if all fields are valid else false.
698 bool isValid( sal_uInt32 nMask ) const
700 return ( nMask & _aStatus.uValidFields ) == nMask;
703 /** Get the file type.
705 @return
706 The file type.
708 Type getFileType() const
710 SAL_INFO_IF(
711 !isValid(osl_FileStatus_Mask_Type), "sal.osl",
712 "no FileStatus Type determined");
713 return isValid(osl_FileStatus_Mask_Type)
714 ? static_cast< Type >(_aStatus.eType) : Unknown;
717 /** Is it a directory?
718 This method returns True for both directories, and volumes.
720 @return
721 True if it's a directory, False otherwise.
723 @see getFileType
724 @since LibreOffice 3.6
726 bool isDirectory() const
728 return ( getFileType() == Directory || getFileType() == Volume );
731 /** Is it a regular file?
733 @return
734 True if it's a regular file, False otherwise.
736 @see getFileType
737 @see isFile
738 @see isLink
739 @since LibreOffice 3.6
741 bool isRegular() const
743 return ( getFileType() == Regular );
746 /** Is it a link?
748 @return
749 True if it's a link, False otherwise.
751 @see getFileType
752 @since LibreOffice 3.6
754 bool isLink() const
756 return ( getFileType() == Link );
759 /** Get the file attributes.
761 @return
762 The set of attribute flags of this file.
765 sal_uInt64 getAttributes() const
767 SAL_INFO_IF(
768 !isValid(osl_FileStatus_Mask_Attributes), "sal.osl",
769 "no FileStatus Attributes determined");
770 return _aStatus.uAttributes;
773 /** Get the creation time of this file.
775 @return
776 The creation time if this information is valid, an uninitialized
777 TimeValue otherwise.
780 TimeValue getCreationTime() const
782 SAL_INFO_IF(
783 !isValid(osl_FileStatus_Mask_CreationTime), "sal.osl",
784 "no FileStatus CreationTime determined");
785 return _aStatus.aCreationTime;
788 /** Get the file access time.
790 @return
791 The last access time if this information is valid, an uninitialized
792 TimeValue otherwise.
795 TimeValue getAccessTime() const
797 SAL_INFO_IF(
798 !isValid(osl_FileStatus_Mask_AccessTime), "sal.osl",
799 "no FileStatus AccessTime determined");
800 return _aStatus.aAccessTime;
803 /** Get the file modification time.
805 @return
806 The last modified time if this information is valid, an uninitialized
807 TimeValue otherwise.
810 TimeValue getModifyTime() const
812 SAL_INFO_IF(
813 !isValid(osl_FileStatus_Mask_ModifyTime), "sal.osl",
814 "no FileStatus ModifyTime determined");
815 return _aStatus.aModifyTime;
818 /** Get the size of the file.
820 @return
821 The actual file size if this information is valid, 0 otherwise.
824 sal_uInt64 getFileSize() const
826 SAL_INFO_IF(
827 !isValid(osl_FileStatus_Mask_FileSize), "sal.osl",
828 "no FileStatus FileSize determined");
829 return _aStatus.uFileSize;
832 /** Get the file name.
834 @return
835 The file name if this information is valid, an empty string otherwise.
838 ::rtl::OUString getFileName() const
840 SAL_INFO_IF(
841 !isValid(osl_FileStatus_Mask_FileName), "sal.osl",
842 "no FileStatus FileName determined");
843 return isValid(osl_FileStatus_Mask_FileName)
844 ? rtl::OUString(_aStatus.ustrFileName) : rtl::OUString();
848 /** Get the URL of the file.
850 @return
851 The full qualified URL of the file if this information is valid, an
852 empty string otherwise.
855 ::rtl::OUString getFileURL() const
857 SAL_INFO_IF(
858 !isValid(osl_FileStatus_Mask_FileURL), "sal.osl",
859 "no FileStatus FileURL determined");
860 return isValid(osl_FileStatus_Mask_FileURL)
861 ? rtl::OUString(_aStatus.ustrFileURL) : rtl::OUString();
864 /** Get the link target URL.
866 @return
867 The link target URL if this information is valid, an empty string
868 otherwise.
871 ::rtl::OUString getLinkTargetURL() const
873 SAL_INFO_IF(
874 !isValid(osl_FileStatus_Mask_LinkTargetURL), "sal.osl",
875 "no FileStatus LinkTargetURL determined");
876 return isValid(osl_FileStatus_Mask_LinkTargetURL)
877 ? rtl::OUString(_aStatus.ustrLinkTargetURL) : rtl::OUString();
880 friend class DirectoryItem;
884 /** The file class object provides access to file contents and attributes.
886 @see Directory
887 @see DirectoryItem
890 class File: public FileBase
892 oslFileHandle _pData;
893 ::rtl::OUString _aPath;
895 /** Copy constructor.
898 File( File& ) SAL_DELETED_FUNCTION;
900 /** Assignment operator.
903 File& operator = ( File& ) SAL_DELETED_FUNCTION;
905 public:
907 /** Constructor.
909 @param[in] ustrFileURL
910 The full qualified URL of the file. Relative paths are not allowed.
913 File( const ::rtl::OUString& ustrFileURL ): _pData( NULL ), _aPath( ustrFileURL ) {}
915 /** Destructor
918 ~File()
920 close();
923 /** Obtain the URL.
925 @return
926 the URL with which this File instance was created.
928 @since LibreOffice 4.1
930 rtl::OUString getURL() const { return _aPath; }
932 /** Open a regular file.
934 Open a file. Only regular files can be opened.
936 @param[in] uFlags
937 Specifies the open mode.
939 @retval E_None on success
940 @retval E_NOMEM not enough memory for allocating structures
941 @retval E_INVAL the format of the parameters was not valid
942 @retval E_NAMETOOLONG pathname was too long
943 @retval E_NOENT no such file or directory
944 @retval E_ACCES permission denied
945 @retval E_AGAIN a write lock could not be established
946 @retval E_NOTDIR not a directory
947 @retval E_NXIO no such device or address
948 @retval E_NODEV no such device
949 @retval E_ROFS read-only file system
950 @retval E_TXTBSY text file busy
951 @retval E_FAULT bad address
952 @retval E_LOOP too many symbolic links encountered
953 @retval E_NOSPC no space left on device
954 @retval E_ISDIR is a directory
955 @retval E_MFILE too many open files used by the process
956 @retval E_NFILE too many open files in the system
957 @retval E_DQUOT quota exceeded
958 @retval E_EXIST file exists
959 @retval E_INTR function call was interrupted
960 @retval E_IO on I/O errors
961 @retval E_MULTIHOP multihop attempted
962 @retval E_NOLINK link has been severed
963 @retval E_EOVERFLOW value too large for defined data type
965 @see close()
966 @see setPos()
967 @see getPos()
968 @see read()
969 @see write()
970 @see getSize()
971 @see setSize()
974 RC open( sal_uInt32 uFlags )
976 return static_cast< RC >( osl_openFile( _aPath.pData, &_pData, uFlags ) );
979 /** Close an open file.
981 @retval E_None on success
982 @retval E_INVAL the format of the parameters was not valid
983 @retval E_BADF Bad file
984 @retval E_INTR function call was interrupted
985 @retval E_NOLINK link has been severed
986 @retval E_NOSPC no space left on device
987 @retval E_IO on I/O errors
989 @see open()
992 RC close()
994 oslFileError Error = osl_File_E_BADF;
996 if( _pData )
998 Error=osl_closeFile( _pData );
999 _pData = NULL;
1002 return static_cast< RC >( Error );
1005 /** Set the internal position pointer of an open file.
1007 @param[in] uHow
1008 Distance to move the internal position pointer (from uPos).
1010 @param[in] uPos
1011 Absolute position from the beginning of the file.
1013 @retval E_None on success
1014 @retval E_INVAL the format of the parameters was not valid
1015 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1017 @see open()
1018 @see getPos()
1021 SAL_WARN_UNUSED_RESULT RC setPos( sal_uInt32 uHow, sal_Int64 uPos )
1023 return static_cast< RC >( osl_setFilePos( _pData, uHow, uPos ) );
1026 /** Retrieve the current position of the internal pointer of an open file.
1028 @param[out] uPos
1029 On success receives the current position of the file pointer.
1031 @retval E_None on success
1032 @retval E_INVAL the format of the parameters was not valid
1033 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1035 @see open()
1036 @see setPos()
1037 @see read()
1038 @see write()
1041 RC getPos( sal_uInt64& uPos )
1043 return static_cast< RC >( osl_getFilePos( _pData, &uPos ) );
1046 /** Test if the end of a file is reached.
1048 @param[out] pIsEOF
1049 Points to a variable that receives the end-of-file status.
1051 @retval E_None on success
1052 @retval E_INVAL the format of the parameters was not valid
1053 @retval E_INTR function call was interrupted
1054 @retval E_IO on I/O errors
1055 @retval E_ISDIR is a directory
1056 @retval E_BADF bad file
1057 @retval E_FAULT bad address
1058 @retval E_AGAIN operation would block
1059 @retval E_NOLINK link has been severed
1061 @see open()
1062 @see read()
1063 @see readLine()
1064 @see setPos()
1067 RC isEndOfFile( sal_Bool *pIsEOF )
1069 return static_cast< RC >( osl_isEndOfFile( _pData, pIsEOF ) );
1072 /** Set the file size of an open file.
1074 Sets the file size of an open file. The file can be truncated or enlarged by the function.
1075 The position of the file pointer is not affeced by this function.
1077 @param[in] uSize
1078 New size in bytes.
1080 @retval E_None on success
1081 @retval E_INVAL the format of the parameters was not valid
1082 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1084 @see open()
1085 @see setPos()
1086 @see getStatus()
1089 RC setSize( sal_uInt64 uSize )
1091 return static_cast< RC >( osl_setFileSize( _pData, uSize ) );
1094 /** Get the file size of an open file.
1096 Gets the file size of an open file.
1097 The position of the file pointer is not affeced by this function.
1099 @param[out] rSize
1100 Current size in bytes.
1102 @retval E_None on success
1103 @retval E_INVAL the format of the parameters was not valid
1104 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1106 @see open()
1107 @see setPos()
1108 @see getSize()
1109 @see setSize()
1110 @see getStatus()
1113 RC getSize( sal_uInt64 &rSize )
1115 return static_cast< RC >( osl_getFileSize( _pData, &rSize ) );
1118 /** Read a number of bytes from a file.
1120 Reads a number of bytes from a file. The internal file pointer is
1121 increased by the number of bytes read.
1123 @param[out] pBuffer
1124 Points to a buffer which receives data. The buffer must be large enough
1125 to hold uBytesRequested bytes.
1127 @param[in] uBytesRequested
1128 Number of bytes which should be retrieved.
1130 @param[out] rBytesRead
1131 On success the number of bytes which have actually been retrieved.
1133 @retval E_None on success
1134 @retval E_INVAL the format of the parameters was not valid
1135 @retval E_INTR function call was interrupted
1136 @retval E_IO on I/O errors
1137 @retval E_ISDIR is a directory
1138 @retval E_BADF bad file
1139 @retval E_FAULT bad address
1140 @retval E_AGAIN operation would block
1141 @retval E_NOLINK link has been severed
1143 @see open()
1144 @see write()
1145 @see readLine()
1146 @see setPos()
1149 RC read( void *pBuffer, sal_uInt64 uBytesRequested, sal_uInt64& rBytesRead )
1151 return static_cast< RC >( osl_readFile( _pData, pBuffer, uBytesRequested, &rBytesRead ) );
1154 /** Write a number of bytes to a file.
1156 Writes a number of bytes to a file.
1157 The internal file pointer is increased by the number of bytes read.
1159 @param[in] pBuffer
1160 Points to a buffer which contains the data.
1162 @param[in] uBytesToWrite
1163 Number of bytes which should be written.
1165 @param[out] rBytesWritten
1166 On success the number of bytes which have actually been written.
1168 @retval E_None on success
1169 @retval E_INVAL the format of the parameters was not valid
1170 @retval E_FBIG file too large
1171 @retval E_DQUOT quota exceeded
1172 @retval E_AGAIN operation would block
1173 @retval E_BADF bad file
1174 @retval E_FAULT bad address
1175 @retval E_INTR function call was interrupted
1176 @retval E_IO on I/O errors
1177 @retval E_NOLCK no record locks available
1178 @retval E_NOLINK link has been severed
1179 @retval E_NOSPC no space left on device
1180 @retval E_NXIO no such device or address
1182 @see open()
1183 @see read()
1184 @see setPos()
1187 RC write(const void *pBuffer, sal_uInt64 uBytesToWrite, sal_uInt64& rBytesWritten)
1189 return static_cast< RC >( osl_writeFile( _pData, pBuffer, uBytesToWrite, &rBytesWritten ) );
1193 /** Read a line from a file.
1195 Reads a line from a file. The new line delimiter is NOT returned!
1197 @param[in,out] aSeq
1198 A reference to a ::rtl::ByteSequence that will hold the line read on success.
1200 @retval E_None on success
1201 @retval E_INVAL the format of the parameters was not valid
1202 @retval E_INTR function call was interrupted
1203 @retval E_IO on I/O errors
1204 @retval E_ISDIR is a directory
1205 @retval E_BADF bad file
1206 @retval E_FAULT bad address
1207 @retval E_AGAIN operation would block
1208 @retval E_NOLINK link has been severed
1210 @see open()
1211 @see read()
1212 @see write()
1213 @see setPos()
1216 RC readLine( ::rtl::ByteSequence& aSeq )
1218 return static_cast< RC >( osl_readLine( _pData, reinterpret_cast<sal_Sequence**>(&aSeq) ) );
1221 /** Synchronize the memory representation of a file with that on the physical medium.
1223 The function ensures that all modified data and attributes of the file associated with
1224 the given file handle have been written to the physical medium.
1225 In case the hard disk has a write cache enabled, the data may not really be on
1226 permanent storage when osl_syncFile returns.
1228 @retval E_None On success
1229 @retval E_INVAL The value of the input parameter is invalid
1230 @retval E_BADF The file is not open for writing
1231 @retval E_IO An I/O error occurred
1232 @retval E_NOSPC There is no enough space on the target device
1233 @retval E_ROFS The file is located on a read only file system
1234 @retval E_TIMEDOUT A remote connection timed out. This may happen when a file is on a remote location
1236 @see osl_syncFile()
1237 @see open()
1238 @see write()
1240 RC sync() const
1242 SAL_WARN_IF(!_pData, "sal.osl", "File::sync(): File not open");
1243 return static_cast< RC >(osl_syncFile(_pData));
1246 /** Copy a file to a new destination.
1248 Copies a file to a new destination. Copies only files not directories.
1249 No assumptions should be made about preserving attributes or file time.
1251 @param[in] ustrSourceFileURL
1252 Full qualified URL of the source file.
1254 @param[in] ustrDestFileURL
1255 Full qualified URL of the destination file. A directory is NOT a valid destination file!
1257 @retval E_None on success
1258 @retval E_INVAL the format of the parameters was not valid
1259 @retval E_NOMEM not enough memory for allocating structures
1260 @retval E_ACCES permission denied
1261 @retval E_PERM operation not permitted
1262 @retval E_NAMETOOLONG file name too long
1263 @retval E_NOENT no such file or directory
1264 @retval E_ISDIR is a directory
1265 @retval E_ROFS read-only file system
1267 @see move()
1268 @see remove()
1271 static RC copy( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1273 return static_cast< RC >( osl_copyFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
1276 /** Move a file or directory to a new destination or renames it.
1278 Moves a file or directory to a new destination or renames it.
1279 File time and attributes are preserved.
1281 @param[in] ustrSourceFileURL
1282 Full qualified URL of the source file.
1284 @param[in] ustrDestFileURL
1285 Full qualified URL of the destination file. An existing directory is NOT a valid destination !
1287 @retval E_None on success
1288 @retval E_INVAL the format of the parameters was not valid
1289 @retval E_NOMEM not enough memory for allocating structures
1290 @retval E_ACCES permission denied
1291 @retval E_PERM operation not permitted
1292 @retval E_NAMETOOLONG file name too long
1293 @retval E_NOENT no such file or directory
1294 @retval E_ROFS read-only file system
1296 @see copy()
1299 static RC move( const ::rtl::OUString& ustrSourceFileURL, const ::rtl::OUString& ustrDestFileURL )
1301 return static_cast< RC >( osl_moveFile( ustrSourceFileURL.pData, ustrDestFileURL.pData ) );
1304 /** Move a file to a new destination or rename it, taking old file's identity (if exists).
1306 Moves or renames a file, replacing an existing file if exist. If the old file existed,
1307 moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or
1308 ACLs, are set to old one's (to keep the old file's identity) - currently this is only
1309 implemented fully on Windows; on other platforms, this is mostly equivalent to move().
1311 @param[in] ustrSourceFileURL
1312 Full qualified URL of the source file.
1314 @param[in] ustrDestFileURL
1315 Full qualified URL of the destination file.
1317 @retval E_None on success
1318 @retval E_INVAL the format of the parameters was not valid
1319 @retval E_NOMEM not enough memory for allocating structures
1320 @retval E_ACCES permission denied
1321 @retval E_PERM operation not permitted
1322 @retval E_NAMETOOLONG file name too long
1323 @retval E_NOENT no such file
1324 @retval E_ROFS read-only file system
1325 @retval E_BUSY device or resource busy
1327 @see move()
1329 @since LibreOffice 6.2
1331 static RC replace(const ::rtl::OUString& ustrSourceFileURL,
1332 const ::rtl::OUString& ustrDestFileURL)
1334 return static_cast<RC>(osl_replaceFile(ustrSourceFileURL.pData, ustrDestFileURL.pData));
1337 /** Remove a regular file.
1339 @param[in] ustrFileURL
1340 Full qualified URL of the file to remove.
1342 @retval E_None on success
1343 @retval E_INVAL the format of the parameters was not valid
1344 @retval E_NOMEM not enough memory for allocating structures
1345 @retval E_ACCES permission denied
1346 @retval E_PERM operation not permitted
1347 @retval E_NAMETOOLONG file name too long
1348 @retval E_NOENT no such file or directory
1349 @retval E_ISDIR is a directory
1350 @retval E_ROFS read-only file system
1351 @retval E_FAULT bad address
1352 @retval E_LOOP too many symbolic links encountered
1353 @retval E_IO on I/O errors
1354 @retval E_BUSY device or resource busy
1355 @retval E_INTR function call was interrupted
1356 @retval E_MULTIHOP multihop attempted
1357 @retval E_NOLINK link has been severed
1358 @retval E_TXTBSY text file busy
1360 @see open()
1363 static RC remove( const ::rtl::OUString& ustrFileURL )
1365 return static_cast< RC >( osl_removeFile( ustrFileURL.pData ) );
1368 /** Set file attributes.
1370 @param[in] ustrFileURL
1371 The full qualified file URL.
1373 @param[in] uAttributes
1374 Attributes of the file to be set.
1376 @return
1377 @retval E_None on success
1378 @retval E_INVAL the format of the parameters was not valid
1380 @see FileStatus
1383 static RC setAttributes( const ::rtl::OUString& ustrFileURL, sal_uInt64 uAttributes )
1385 return static_cast< RC >( osl_setFileAttributes( ustrFileURL.pData, uAttributes ) );
1388 /** Set the file time.
1390 @param[in] ustrFileURL
1391 The full qualified URL of the file.
1393 @param[in] rCreationTime
1394 Creation time of the given file.
1396 @param[in] rLastAccessTime
1397 Time of the last access of the given file.
1399 @param[in] rLastWriteTime
1400 Time of the last modifying of the given file.
1402 @retval E_None on success
1403 @retval E_INVAL the format of the parameters was not valid
1404 @retval E_NOENT no such file or directory not found
1406 @see FileStatus
1409 static RC setTime(
1410 const ::rtl::OUString& ustrFileURL,
1411 const TimeValue& rCreationTime,
1412 const TimeValue& rLastAccessTime,
1413 const TimeValue& rLastWriteTime )
1415 return static_cast< RC >( osl_setFileTime(
1416 ustrFileURL.pData,
1417 &rCreationTime,
1418 &rLastAccessTime,
1419 &rLastWriteTime ) );
1422 friend class DirectoryItem;
1426 /** The directory item class object provides access to file status information.
1428 @see FileStatus
1431 class DirectoryItem: public FileBase
1433 oslDirectoryItem _pData;
1435 public:
1437 /** Constructor.
1440 DirectoryItem(): _pData( NULL )
1444 /** Copy constructor.
1447 DirectoryItem( const DirectoryItem& rItem ): _pData( rItem._pData)
1449 if( _pData )
1450 osl_acquireDirectoryItem( _pData );
1453 /** Destructor.
1456 ~DirectoryItem()
1458 if( _pData )
1459 osl_releaseDirectoryItem( _pData );
1462 /** Assignment operator.
1465 DirectoryItem& operator=(const DirectoryItem& rItem )
1467 if (&rItem != this)
1469 if( _pData )
1470 osl_releaseDirectoryItem( _pData );
1472 _pData = rItem._pData;
1474 if( _pData )
1475 osl_acquireDirectoryItem( _pData );
1477 return *this;
1480 /** Check for validity of this instance.
1482 @return
1483 true if object is valid directory item else false.
1486 bool is()
1488 return _pData != NULL;
1491 /** Retrieve a single directory item.
1493 Retrieves a single directory item. The returned handle has an initial refcount of 1.
1494 Due to performance issues it is not recommended to use this function while
1495 enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead.
1497 @param[in] ustrFileURL
1498 An absolute file URL.
1500 @param[out] rItem
1501 On success it receives a handle which can be used for subsequent calls to osl_getFileStatus().
1502 The handle has to be released by a call to osl_releaseDirectoryItem().
1504 @retval E_None on success
1505 @retval E_INVAL the format of the parameters was not valid
1506 @retval E_NOMEM not enough memory for allocating structures
1507 @retval E_ACCES permission denied
1508 @retval E_MFILE too many open files used by the process
1509 @retval E_NFILE too many open files in the system
1510 @retval E_NOENT no such file or directory
1511 @retval E_LOOP too many symbolic links encountered
1512 @retval E_NAMETOOLONG the file name is too long
1513 @retval E_NOTDIR a component of the path prefix of path is not a directory
1514 @retval E_IO on I/O errors
1515 @retval E_MULTIHOP multihop attempted
1516 @retval E_NOLINK link has been severed
1517 @retval E_FAULT bad address
1518 @retval E_INTR the function call was interrupted
1520 @see FileStatus
1521 @see Directory::getNextItem()
1524 static RC get( const ::rtl::OUString& ustrFileURL, DirectoryItem& rItem )
1526 if( rItem._pData)
1528 osl_releaseDirectoryItem( rItem._pData );
1529 rItem._pData = NULL;
1532 return static_cast< RC >( osl_getDirectoryItem( ustrFileURL.pData, &rItem._pData ) );
1535 /** Retrieve information about a single file or directory.
1537 @param[in,out] rStatus
1538 Reference to a class which receives the information of the file or directory
1539 represented by this directory item.
1541 @retval E_None on success
1542 @retval E_NOMEM not enough memory for allocating structures
1543 @retval E_INVAL the format of the parameters was not valid
1544 @retval E_LOOP too many symbolic links encountered
1545 @retval E_ACCES permission denied
1546 @retval E_NOENT no such file or directory
1547 @retval E_NAMETOOLONG file name too long
1548 @retval E_BADF invalid oslDirectoryItem parameter
1549 @retval E_FAULT bad address
1550 @retval E_OVERFLOW value too large for defined data type
1551 @retval E_INTR function call was interrupted
1552 @retval E_NOLINK link has been severed
1553 @retval E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it
1554 @retval E_MFILE too many open files used by the process
1555 @retval E_NFILE too many open files in the system
1556 @retval E_NOSPC no space left on device
1557 @retval E_NXIO no such device or address
1558 @retval E_IO on I/O errors
1559 @retval E_NOSYS function not implemented
1561 @see get()
1562 @see Directory::getNextItem()
1563 @see FileStatus
1566 RC getFileStatus( FileStatus& rStatus )
1568 return static_cast< RC >( osl_getFileStatus( _pData, &rStatus._aStatus, rStatus._nMask ) );
1571 /** Determine if a directory item point the same underlying file
1573 The comparison is done first by URL, and then by resolving links to
1574 find the target, and finally by comparing inodes on unix.
1576 @param[in] pOther
1577 A directory handle to compare with the underlying object's item
1579 @retval true if the items point to an identical resource<br>
1580 @retval false if the items point to a different resource, or a fatal error occurred<br>
1582 @see osl_getDirectoryItem()
1584 @since LibreOffice 3.6
1586 bool isIdenticalTo( const DirectoryItem &pOther )
1588 return osl_identicalDirectoryItem( _pData, pOther._pData );
1591 friend class Directory;
1595 /** Base class for observers of directory creation notifications.
1597 Clients which uses the method createDirectoryPath of the class
1598 Directory may want to be informed about the directories that
1599 have been created. This may be accomplished by deriving from
1600 this base class and overwriting the virtual function
1601 DirectoryCreated.
1603 @see Directory::createPath
1605 class DirectoryCreationObserver
1607 public:
1608 virtual ~DirectoryCreationObserver() {}
1610 /** This method will be called when a new directory has been
1611 created and needs to be overwritten by derived classes.
1612 You must not delete the directory that was just created
1613 otherwise you will run into an endless loop.
1615 @param aDirectoryUrl
1616 [in]The absolute file URL of the directory that was just created by
1617 ::osl::Directory::createPath.
1619 virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) = 0;
1623 // This just an internal helper function for
1624 // private use.
1625 extern "C" inline void SAL_CALL onDirectoryCreated(void* pData, rtl_uString* aDirectoryUrl)
1627 static_cast<DirectoryCreationObserver*>(pData)->DirectoryCreated(aDirectoryUrl);
1630 /** The directory class object provides an enumeration of DirectoryItems.
1632 @see DirectoryItem
1633 @see File
1636 class Directory: public FileBase
1638 oslDirectory _pData;
1639 ::rtl::OUString _aPath;
1641 /** Copy constructor.
1644 Directory( Directory& ) SAL_DELETED_FUNCTION;
1646 /** Assignment operator.
1649 Directory& operator = ( Directory& ) SAL_DELETED_FUNCTION;
1651 public:
1653 /** Constructor.
1655 @param[in] strPath
1656 The full qualified URL of the directory.
1657 Relative URLs are not allowed.
1660 Directory( const ::rtl::OUString& strPath ): _pData( NULL ), _aPath( strPath )
1664 /** Destructor.
1667 ~Directory()
1669 close();
1672 /** Obtain the URL.
1674 @return
1675 the URL with which this Directory instance was created.
1677 @since LibreOffice 4.1
1679 rtl::OUString getURL() const { return _aPath; }
1681 /** Open a directory for enumerating its contents.
1683 @retval E_None on success
1684 @retval E_INVAL the format of the parameters was not valid
1685 @retval E_NOENT the specified path doesn't exist
1686 @retval E_NOTDIR the specified path is not a directory
1687 @retval E_NOMEM not enough memory for allocating structures
1688 @retval E_ACCES permission denied
1689 @retval E_MFILE too many open files used by the process
1690 @retval E_NFILE too many open files in the system
1691 @retval E_NAMETOOLONG File name too long
1692 @retval E_LOOP Too many symbolic links encountered
1694 @see getNextItem()
1695 @see close()
1698 RC open()
1700 return static_cast< RC >( osl_openDirectory( _aPath.pData, &_pData ) );
1703 /** Query if directory is open.
1705 Query if directory is open and so item enumeration is valid.
1707 @retval true if the directory is open else false.
1709 @see open()
1710 @see close()
1713 bool isOpen() { return _pData != NULL; }
1715 /** Close a directory.
1717 @retval E_None on success
1718 @retval E_INVAL the format of the parameters was not valid
1719 @retval E_NOMEM not enough memory for allocating structures
1720 @retval E_BADF invalid oslDirectory parameter
1721 @retval E_INTR the function call was interrupted
1723 @see open()
1726 RC close()
1728 oslFileError Error = osl_File_E_BADF;
1730 if( _pData )
1732 Error=osl_closeDirectory( _pData );
1733 _pData = NULL;
1736 return static_cast< RC >( Error );
1740 /** Resets the directory item enumeration to the beginning.
1742 @retval E_None on success
1743 @retval E_INVAL the format of the parameters was not valid
1744 @retval E_NOENT the specified path doesn't exist
1745 @retval E_NOTDIR the specified path is not a directory
1746 @retval E_NOMEM not enough memory for allocating structures
1747 @retval E_ACCES permission denied
1748 @retval E_MFILE too many open files used by the process
1749 @retval E_NFILE too many open files in the system
1750 @retval E_NAMETOOLONG File name too long
1751 @retval E_LOOP Too many symbolic links encountered
1753 @see open()
1756 RC reset()
1758 close();
1759 return open();
1762 /** Retrieve the next item of a previously opened directory.
1764 Retrieves the next item of a previously opened directory.
1766 @param[out] rItem
1767 On success a valid DirectoryItem.
1769 @param[in] nHint
1770 With this parameter the caller can tell the implementation that (s)he
1771 is going to call this function uHint times afterwards. This enables the implementation to
1772 get the information for more than one file and cache it until the next calls.
1774 @retval E_None on success
1775 @retval E_INVAL the format of the parameters was not valid
1776 @retval E_NOMEM not enough memory for allocating structures
1777 @retval E_NOENT no more entries in this directory
1778 @retval E_BADF invalid oslDirectory parameter
1779 @retval E_OVERFLOW the value too large for defined data type
1781 @see DirectoryItem
1784 RC getNextItem( DirectoryItem& rItem, sal_uInt32 nHint = 0 )
1786 if( rItem._pData )
1788 osl_releaseDirectoryItem( rItem._pData );
1789 rItem._pData = NULL;
1791 return static_cast<RC>(osl_getNextDirectoryItem( _pData, &rItem._pData, nHint ));
1795 /** Retrieve information about a volume.
1797 Retrieves information about a volume. A volume can either be a mount point, a network
1798 resource or a drive depending on Operating System and File System.
1800 @param[in] ustrDirectoryURL
1801 Full qualified URL of the volume
1803 @param[out] rInfo
1804 On success it receives information about the volume.
1806 @retval E_None on success
1807 @retval E_NOMEM not enough memory for allocating structures
1808 @retval E_INVAL the format of the parameters was not valid
1809 @retval E_NOTDIR not a directory
1810 @retval E_NAMETOOLONG file name too long
1811 @retval E_NOENT no such file or directory
1812 @retval E_ACCES permission denied
1813 @retval E_LOOP too many symbolic links encountered
1814 @retval E_FAULT Bad address
1815 @retval E_IO on I/O errors
1816 @retval E_NOSYS function not implemented
1817 @retval E_MULTIHOP multihop attempted
1818 @retval E_NOLINK link has been severed
1819 @retval E_INTR function call was interrupted
1821 @see FileStatus
1822 @see VolumeInfo
1825 static RC getVolumeInfo( const ::rtl::OUString& ustrDirectoryURL, VolumeInfo& rInfo )
1827 return static_cast< RC >( osl_getVolumeInformation( ustrDirectoryURL.pData, &rInfo._aInfo, rInfo._nMask ) );
1830 /** Create a directory.
1832 @param[in] ustrDirectoryURL
1833 Full qualified URL of the directory to create.
1835 @param[in] flags
1836 Optional flags, see osl_createDirectoryWithFlags for details. This
1837 defaulted parameter is new since LibreOffice 4.3.
1839 @retval E_None on success
1840 @retval E_INVAL the format of the parameters was not valid
1841 @retval E_NOMEM not enough memory for allocating structures
1842 @retval E_EXIST file exists
1843 @retval E_ACCES permission denied
1844 @retval E_NAMETOOLONG file name too long
1845 @retval E_NOENT no such file or directory
1846 @retval E_NOTDIR not a directory
1847 @retval E_ROFS read-only file system
1848 @retval E_NOSPC no space left on device
1849 @retval E_DQUOT quota exceeded
1850 @retval E_LOOP too many symbolic links encountered
1851 @retval E_FAULT bad address
1852 @retval E_IO on I/O errors
1853 @retval E_MLINK too many links
1854 @retval E_MULTIHOP multihop attempted
1855 @retval E_NOLINK link has been severed
1857 @see remove()
1860 static RC create(
1861 const ::rtl::OUString& ustrDirectoryURL,
1862 sal_uInt32 flags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write )
1864 return static_cast< RC >(
1865 osl_createDirectoryWithFlags( ustrDirectoryURL.pData, flags ) );
1868 /** Remove an empty directory.
1870 @param[in] ustrDirectoryURL
1871 Full qualified URL of the directory.
1873 @retval E_None on success
1874 @retval E_INVAL the format of the parameters was not valid
1875 @retval E_NOMEM not enough memory for allocating structures
1876 @retval E_PERM operation not permitted
1877 @retval E_ACCES permission denied
1878 @retval E_NOENT no such file or directory
1879 @retval E_NOTDIR not a directory
1880 @retval E_NOTEMPTY directory not empty
1881 @retval E_FAULT bad address
1882 @retval E_NAMETOOLONG file name too long
1883 @retval E_BUSY device or resource busy
1884 @retval E_ROFS read-only file system
1885 @retval E_LOOP too many symbolic links encountered
1886 @retval E_EXIST file exists
1887 @retval E_IO on I/O errors
1888 @retval E_MULTIHOP multihop attempted
1889 @retval E_NOLINK link has been severed
1891 @see create()
1894 static RC remove( const ::rtl::OUString& ustrDirectoryURL )
1896 return static_cast< RC >( osl_removeDirectory( ustrDirectoryURL.pData ) );
1899 /** Create a directory path.
1901 The osl_createDirectoryPath function creates a specified directory path.
1902 All nonexisting sub directories will be created.
1904 @attention You cannot rely on getting the error code E_EXIST for existing
1905 directories. Programming against this error code is in general a strong
1906 indication of a wrong usage of osl_createDirectoryPath.
1908 @param aDirectoryUrl
1909 [in] The absolute file URL of the directory path to create.
1910 A relative file URL will not be accepted.
1912 @param aDirectoryCreationObserver
1913 [in] Pointer to an instance of type DirectoryCreationObserver that will
1914 be informed about the creation of a directory. The value of this
1915 parameter may be NULL, in this case notifications will not be sent.
1917 @retval E_None On success
1918 @retval E_INVAL The format of the parameters was not valid
1919 @retval E_ACCES Permission denied
1920 @retval E_EXIST The final node of the specified directory path already exist
1921 @retval E_NAMETOOLONG The name of the specified directory path exceeds the maximum allowed length
1922 @retval E_NOTDIR A component of the specified directory path already exist as file in any part of the directory path
1923 @retval E_ROFS Read-only file system
1924 @retval E_NOSPC No space left on device
1925 @retval E_DQUOT Quota exceeded
1926 @retval E_FAULT Bad address
1927 @retval E_IO I/O error
1928 @retval E_LOOP Too many symbolic links encountered
1929 @retval E_NOLINK Link has been severed
1930 @retval E_invalidError An unknown error occurred
1932 @see DirectoryCreationObserver
1933 @see create
1935 static RC createPath(
1936 const ::rtl::OUString& aDirectoryUrl,
1937 DirectoryCreationObserver* aDirectoryCreationObserver = NULL)
1939 return static_cast< RC >(osl_createDirectoryPath(
1940 aDirectoryUrl.pData,
1941 aDirectoryCreationObserver ? onDirectoryCreated : NULL,
1942 aDirectoryCreationObserver));
1946 } /* namespace osl */
1948 #endif // INCLUDED_OSL_FILE_HXX
1950 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */