1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
33 #include "sal/log.hxx"
35 #include "rtl/ustring.hxx"
38 #include "osl/diagnose.h"
40 namespace rtl
{ class ByteSequence
; }
46 /** Base class for all File System specific objects.
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
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
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
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
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
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.
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
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
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
) );
318 /** Resets the list of paths and associated permissions for osl
321 Contains a ':' delimited list of control strings and paths.
322 Control segments are a short path that refers to the following
323 segments and contain either:
325 r: read-only paths follow (the default)
326 w: read & write paths follow
327 x: executable paths follow
329 Any real paths (ie. having resolved all symlinks)
330 accessed outside of these paths will cause an
331 osl_File_E_ACCESS error in the relevant method calls.
333 This method is Unix specific.
335 @see osl_isForbiddenPath
337 @since LibreOffice 7.7
340 static void setAllowedPaths(const ::rtl::OUString
& rPaths
)
342 osl_setAllowedPaths(rPaths
.pData
);
346 Determine if the passed in path is not contained inside
347 the allowed paths, or if no allowed paths are set it
348 will not forbid any access.
350 @param[in] pustrFileURL
351 A URL (or path) that we want to check if it is forbidden
355 Flags to determine what type of access is requested,
356 osl_File_OpenFlag_Read | Write, or 0x80 for 'execute'.
358 This method is Unix specific.
360 @see osl_setAllowedPaths
362 @since LibreOffice 7.7
364 static bool isForbidden(const ::rtl::OUString
& rPath
, int nFlags
)
366 return osl_isForbiddenPath(rPath
.pData
, nFlags
);
371 /** The VolumeDevice class.
376 class VolumeDevice
: public FileBase
378 oslVolumeDeviceHandle _aHandle
;
385 VolumeDevice() : _aHandle( NULL
)
389 /** Copy constructor.
392 The other volume device.
395 VolumeDevice( const VolumeDevice
& rDevice
)
397 _aHandle
= rDevice
._aHandle
;
399 osl_acquireVolumeDeviceHandle( _aHandle
);
408 osl_releaseVolumeDeviceHandle( _aHandle
);
411 /** Assignment operator.
414 The other volume device.
417 VolumeDevice
& operator =( const VolumeDevice
& rDevice
)
419 oslVolumeDeviceHandle newHandle
= rDevice
._aHandle
;
422 osl_acquireVolumeDeviceHandle( newHandle
);
425 osl_releaseVolumeDeviceHandle( _aHandle
);
427 _aHandle
= newHandle
;
432 /** Get the full qualified URL where a device is mounted to.
435 The full qualified URL where the device is mounted to.
437 rtl::OUString
getMountPath()
440 osl_getVolumeDeviceMountPath( _aHandle
, &aPath
.pData
);
444 friend class VolumeInfo
;
450 /** The VolumeInfo class.
452 Neither copy nor assignment is allowed for this class.
454 @see Directory::getVolumeInfo
460 oslVolumeInfo _aInfo
;
462 VolumeDevice _aDevice
;
464 /** Copy constructor.
467 VolumeInfo( VolumeInfo
& ) SAL_DELETED_FUNCTION
;
469 /** Assignment operator.
472 VolumeInfo
& operator = ( VolumeInfo
& ) SAL_DELETED_FUNCTION
;
479 Set of flags describing the demanded information.
481 VolumeInfo( sal_uInt32 nMask
)
484 memset( &_aInfo
, 0, sizeof( oslVolumeInfo
));
485 _aInfo
.uStructSize
= sizeof( oslVolumeInfo
);
486 _aInfo
.pDeviceHandle
= &_aDevice
._aHandle
;
491 if( _aInfo
.ustrFileSystemName
)
492 rtl_uString_release( _aInfo
.ustrFileSystemName
);
495 /** Check if specified fields are valid.
498 Set of flags for the fields to check.
500 @return true if all fields are valid else false.
502 bool isValid( sal_uInt32 nMask
) const
504 return ( nMask
& _aInfo
.uValidFields
) == nMask
;
507 /** Check the remote flag.
510 true if Attributes are valid and the volume is remote else false.
512 bool getRemoteFlag() const
514 return (_aInfo
.uAttributes
& osl_Volume_Attribute_Remote
) != 0;
517 /** Check the removable flag.
520 true if attributes are valid and the volume is removable else false.
522 bool getRemoveableFlag() const
524 return (_aInfo
.uAttributes
& osl_Volume_Attribute_Removeable
) != 0;
527 /** Check the compact disc flag.
530 true if attributes are valid and the volume is a CDROM else false.
533 bool getCompactDiscFlag() const
535 return (_aInfo
.uAttributes
& osl_Volume_Attribute_CompactDisc
) != 0;
538 /** Check the floppy disc flag.
541 true if attributes are valid and the volume is a floppy disk else false.
544 bool getFloppyDiskFlag() const
546 return (_aInfo
.uAttributes
& osl_Volume_Attribute_FloppyDisk
) != 0;
549 /** Check the fixed disk flag.
552 true if attributes are valid and the volume is a fixed disk else false.
555 bool getFixedDiskFlag() const
557 return (_aInfo
.uAttributes
& osl_Volume_Attribute_FixedDisk
) != 0;
560 /** Check the RAM disk flag.
563 true if attributes are valid and the volume is a RAM disk else false.
566 bool getRAMDiskFlag() const
568 return (_aInfo
.uAttributes
& osl_Volume_Attribute_RAMDisk
) != 0;
571 /** Determine the total space of a volume device.
574 The total diskspace of this volume if this information is valid,
578 sal_uInt64
getTotalSpace() const
580 return _aInfo
.uTotalSpace
;
583 /** Determine the free space of a volume device.
586 The free diskspace of this volume if this information is valid,
590 sal_uInt64
getFreeSpace() const
592 return _aInfo
.uFreeSpace
;
595 /** Determine the used space of a volume device.
598 The used diskspace of this volume if this information is valid,
602 sal_uInt64
getUsedSpace() const
604 return _aInfo
.uUsedSpace
;
607 /** Determine the maximal length of a file name.
610 The maximal length of a file name if this information is valid,
614 sal_uInt32
getMaxNameLength() const
616 return _aInfo
.uMaxNameLength
;
619 /** Determine the maximal length of a path name.
622 The maximal length of a path if this information is valid,
626 sal_uInt32
getMaxPathLength() const
628 return _aInfo
.uMaxPathLength
;
631 /** Determine the name of the volume device's File System.
634 The name of the volume's filesystem if this information is valid,
635 otherwise an empty string.
638 ::rtl::OUString
getFileSystemName() const
640 return _aInfo
.ustrFileSystemName
? ::rtl::OUString( _aInfo
.ustrFileSystemName
) : ::rtl::OUString();
644 /** Get the volume device handle.
647 The device handle of the volume if this information is valid,
648 otherwise returns NULL;
651 VolumeDevice
getDeviceHandle() const
656 /** Return whether the file system is case sensitive or
660 true if the file system is case sensitive false otherwise
662 bool isCaseSensitiveFileSystem() const
664 return (_aInfo
.uAttributes
& osl_Volume_Attribute_Case_Sensitive
) != 0;
667 /** Return whether the file system preserves the case of
668 file and directory names or not
671 true if the file system preserves the case of file and
672 directory names false otherwise
674 bool isCasePreservingFileSystem() const
676 return (_aInfo
.uAttributes
& osl_Volume_Attribute_Case_Is_Preserved
) != 0;
679 friend class Directory
;
685 /** The FileStatus class.
687 @see DirectoryItem::getFileStatus
692 oslFileStatus _aStatus
;
695 /** Copy constructor.
698 FileStatus( FileStatus
& ) SAL_DELETED_FUNCTION
;
700 /** Assignment operator.
703 FileStatus
& operator = ( FileStatus
& ) SAL_DELETED_FUNCTION
;
708 Directory
= osl_File_Type_Directory
,
709 Volume
= osl_File_Type_Volume
,
710 Regular
= osl_File_Type_Regular
,
711 Fifo
= osl_File_Type_Fifo
,
712 Socket
= osl_File_Type_Socket
,
713 Link
= osl_File_Type_Link
,
714 Special
= osl_File_Type_Special
,
715 Unknown
= osl_File_Type_Unknown
721 Set of flags describing the demanded information.
723 FileStatus(sal_uInt32 nMask
)
726 memset(&_aStatus
, 0, sizeof(_aStatus
));
727 _aStatus
.uStructSize
= sizeof(_aStatus
);
734 if ( _aStatus
.ustrFileURL
)
735 rtl_uString_release( _aStatus
.ustrFileURL
);
736 if ( _aStatus
.ustrLinkTargetURL
)
737 rtl_uString_release( _aStatus
.ustrLinkTargetURL
);
738 if ( _aStatus
.ustrFileName
)
739 rtl_uString_release( _aStatus
.ustrFileName
);
742 /** Check if specified fields are valid.
745 Set of flags for the fields to check.
748 true if all fields are valid else false.
751 bool isValid( sal_uInt32 nMask
) const
753 return ( nMask
& _aStatus
.uValidFields
) == nMask
;
756 /** Get the file type.
761 Type
getFileType() const
764 !isValid(osl_FileStatus_Mask_Type
), "sal.osl",
765 "no FileStatus Type determined");
766 return isValid(osl_FileStatus_Mask_Type
)
767 ? static_cast< Type
>(_aStatus
.eType
) : Unknown
;
770 /** Is it a directory?
771 This method returns True for both directories, and volumes.
774 True if it's a directory, False otherwise.
777 @since LibreOffice 3.6
779 bool isDirectory() const
781 return ( getFileType() == Directory
|| getFileType() == Volume
);
784 /** Is it a regular file?
787 True if it's a regular file, False otherwise.
792 @since LibreOffice 3.6
794 bool isRegular() const
796 return ( getFileType() == Regular
);
802 True if it's a link, False otherwise.
805 @since LibreOffice 3.6
809 return ( getFileType() == Link
);
812 /** Get the file attributes.
815 The set of attribute flags of this file.
818 sal_uInt64
getAttributes() const
821 !isValid(osl_FileStatus_Mask_Attributes
), "sal.osl",
822 "no FileStatus Attributes determined");
823 return _aStatus
.uAttributes
;
826 /** Get the creation time of this file.
829 The creation time if this information is valid, an uninitialized
833 TimeValue
getCreationTime() const
836 !isValid(osl_FileStatus_Mask_CreationTime
), "sal.osl",
837 "no FileStatus CreationTime determined");
838 return _aStatus
.aCreationTime
;
841 /** Get the file access time.
844 The last access time if this information is valid, an uninitialized
848 TimeValue
getAccessTime() const
851 !isValid(osl_FileStatus_Mask_AccessTime
), "sal.osl",
852 "no FileStatus AccessTime determined");
853 return _aStatus
.aAccessTime
;
856 /** Get the file modification time.
859 The last modified time if this information is valid, an uninitialized
863 TimeValue
getModifyTime() const
866 !isValid(osl_FileStatus_Mask_ModifyTime
), "sal.osl",
867 "no FileStatus ModifyTime determined");
868 return _aStatus
.aModifyTime
;
871 /** Get the size of the file.
874 The actual file size if this information is valid, 0 otherwise.
877 sal_uInt64
getFileSize() const
880 !isValid(osl_FileStatus_Mask_FileSize
), "sal.osl",
881 "no FileStatus FileSize determined");
882 return _aStatus
.uFileSize
;
885 /** Get the file name.
888 The file name if this information is valid, an empty string otherwise.
891 ::rtl::OUString
getFileName() const
894 !isValid(osl_FileStatus_Mask_FileName
), "sal.osl",
895 "no FileStatus FileName determined");
896 return isValid(osl_FileStatus_Mask_FileName
)
897 ? rtl::OUString(_aStatus
.ustrFileName
) : rtl::OUString();
901 /** Get the URL of the file.
904 The full qualified URL of the file if this information is valid, an
905 empty string otherwise.
908 ::rtl::OUString
getFileURL() const
911 !isValid(osl_FileStatus_Mask_FileURL
), "sal.osl",
912 "no FileStatus FileURL determined");
913 return isValid(osl_FileStatus_Mask_FileURL
)
914 ? rtl::OUString(_aStatus
.ustrFileURL
) : rtl::OUString();
917 /** Get the link target URL.
920 The link target URL if this information is valid, an empty string
924 ::rtl::OUString
getLinkTargetURL() const
927 !isValid(osl_FileStatus_Mask_LinkTargetURL
), "sal.osl",
928 "no FileStatus LinkTargetURL determined");
929 return isValid(osl_FileStatus_Mask_LinkTargetURL
)
930 ? rtl::OUString(_aStatus
.ustrLinkTargetURL
) : rtl::OUString();
933 friend class DirectoryItem
;
937 /** The file class object provides access to file contents and attributes.
943 class File
: public FileBase
945 oslFileHandle _pData
;
946 ::rtl::OUString _aPath
;
948 /** Copy constructor.
951 File( File
& ) SAL_DELETED_FUNCTION
;
953 /** Assignment operator.
956 File
& operator = ( File
& ) SAL_DELETED_FUNCTION
;
962 @param[in] ustrFileURL
963 The full qualified URL of the file. Relative paths are not allowed.
966 File( const ::rtl::OUString
& ustrFileURL
): _pData( NULL
), _aPath( ustrFileURL
) {}
979 the URL with which this File instance was created.
981 @since LibreOffice 4.1
983 rtl::OUString
getURL() const { return _aPath
; }
985 /** Open a regular file.
987 Open a file. Only regular files can be opened.
990 Specifies the open mode.
992 @retval E_None on success
993 @retval E_NOMEM not enough memory for allocating structures
994 @retval E_INVAL the format of the parameters was not valid
995 @retval E_NAMETOOLONG pathname was too long
996 @retval E_NOENT no such file or directory
997 @retval E_ACCES permission denied
998 @retval E_AGAIN a write lock could not be established
999 @retval E_NOTDIR not a directory
1000 @retval E_NXIO no such device or address
1001 @retval E_NODEV no such device
1002 @retval E_ROFS read-only file system
1003 @retval E_TXTBSY text file busy
1004 @retval E_FAULT bad address
1005 @retval E_LOOP too many symbolic links encountered
1006 @retval E_NOSPC no space left on device
1007 @retval E_ISDIR is a directory
1008 @retval E_MFILE too many open files used by the process
1009 @retval E_NFILE too many open files in the system
1010 @retval E_DQUOT quota exceeded
1011 @retval E_EXIST file exists
1012 @retval E_INTR function call was interrupted
1013 @retval E_IO on I/O errors
1014 @retval E_MULTIHOP multihop attempted
1015 @retval E_NOLINK link has been severed
1016 @retval E_EOVERFLOW value too large for defined data type
1027 RC
open( sal_uInt32 uFlags
)
1029 return static_cast< RC
>( osl_openFile( _aPath
.pData
, &_pData
, uFlags
) );
1032 /** Close an open file.
1034 @retval E_None on success
1035 @retval E_INVAL the format of the parameters was not valid
1036 @retval E_BADF Bad file
1037 @retval E_INTR function call was interrupted
1038 @retval E_NOLINK link has been severed
1039 @retval E_NOSPC no space left on device
1040 @retval E_IO on I/O errors
1047 oslFileError Error
= osl_File_E_BADF
;
1051 Error
=osl_closeFile( _pData
);
1055 return static_cast< RC
>( Error
);
1058 /** Set the internal position pointer of an open file.
1061 Distance to move the internal position pointer (from uPos).
1064 Absolute position from the beginning of the file.
1066 @retval E_None on success
1067 @retval E_INVAL the format of the parameters was not valid
1068 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1074 SAL_WARN_UNUSED_RESULT RC
setPos( sal_uInt32 uHow
, sal_Int64 uPos
)
1076 return static_cast< RC
>( osl_setFilePos( _pData
, uHow
, uPos
) );
1079 /** Retrieve the current position of the internal pointer of an open file.
1082 On success receives the current position of the file pointer.
1084 @retval E_None on success
1085 @retval E_INVAL the format of the parameters was not valid
1086 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1094 RC
getPos( sal_uInt64
& uPos
)
1096 return static_cast< RC
>( osl_getFilePos( _pData
, &uPos
) );
1099 /** Test if the end of a file is reached.
1102 Points to a variable that receives the end-of-file status.
1104 @retval E_None on success
1105 @retval E_INVAL the format of the parameters was not valid
1106 @retval E_INTR function call was interrupted
1107 @retval E_IO on I/O errors
1108 @retval E_ISDIR is a directory
1109 @retval E_BADF bad file
1110 @retval E_FAULT bad address
1111 @retval E_AGAIN operation would block
1112 @retval E_NOLINK link has been severed
1120 RC
isEndOfFile( sal_Bool
*pIsEOF
)
1122 return static_cast< RC
>( osl_isEndOfFile( _pData
, pIsEOF
) );
1125 /** Set the file size of an open file.
1127 Sets the file size of an open file. The file can be truncated or enlarged by the function.
1128 The position of the file pointer is not affeced by this function.
1133 @retval E_None on success
1134 @retval E_INVAL the format of the parameters was not valid
1135 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1142 RC
setSize( sal_uInt64 uSize
)
1144 return static_cast< RC
>( osl_setFileSize( _pData
, uSize
) );
1147 /** Get the file size of an open file.
1149 Gets the file size of an open file.
1150 The position of the file pointer is not affeced by this function.
1153 Current size in bytes.
1155 @retval E_None on success
1156 @retval E_INVAL the format of the parameters was not valid
1157 @retval E_OVERFLOW the resulting file offset would be a value which cannot be represented correctly for regular files
1166 RC
getSize( sal_uInt64
&rSize
)
1168 return static_cast< RC
>( osl_getFileSize( _pData
, &rSize
) );
1171 /** Read a number of bytes from a file.
1173 Reads a number of bytes from a file. The internal file pointer is
1174 increased by the number of bytes read.
1177 Points to a buffer which receives data. The buffer must be large enough
1178 to hold uBytesRequested bytes.
1180 @param[in] uBytesRequested
1181 Number of bytes which should be retrieved.
1183 @param[out] rBytesRead
1184 On success the number of bytes which have actually been retrieved.
1186 @retval E_None on success
1187 @retval E_INVAL the format of the parameters was not valid
1188 @retval E_INTR function call was interrupted
1189 @retval E_IO on I/O errors
1190 @retval E_ISDIR is a directory
1191 @retval E_BADF bad file
1192 @retval E_FAULT bad address
1193 @retval E_AGAIN operation would block
1194 @retval E_NOLINK link has been severed
1202 RC
read( void *pBuffer
, sal_uInt64 uBytesRequested
, sal_uInt64
& rBytesRead
)
1204 return static_cast< RC
>( osl_readFile( _pData
, pBuffer
, uBytesRequested
, &rBytesRead
) );
1207 /** Write a number of bytes to a file.
1209 Writes a number of bytes to a file.
1210 The internal file pointer is increased by the number of bytes read.
1213 Points to a buffer which contains the data.
1215 @param[in] uBytesToWrite
1216 Number of bytes which should be written.
1218 @param[out] rBytesWritten
1219 On success the number of bytes which have actually been written.
1221 @retval E_None on success
1222 @retval E_INVAL the format of the parameters was not valid
1223 @retval E_FBIG file too large
1224 @retval E_DQUOT quota exceeded
1225 @retval E_AGAIN operation would block
1226 @retval E_BADF bad file
1227 @retval E_FAULT bad address
1228 @retval E_INTR function call was interrupted
1229 @retval E_IO on I/O errors
1230 @retval E_NOLCK no record locks available
1231 @retval E_NOLINK link has been severed
1232 @retval E_NOSPC no space left on device
1233 @retval E_NXIO no such device or address
1240 RC
write(const void *pBuffer
, sal_uInt64 uBytesToWrite
, sal_uInt64
& rBytesWritten
)
1242 return static_cast< RC
>( osl_writeFile( _pData
, pBuffer
, uBytesToWrite
, &rBytesWritten
) );
1246 /** Read a line from a file.
1248 Reads a line from a file. The new line delimiter is NOT returned!
1251 A reference to a ::rtl::ByteSequence that will hold the line read on success.
1253 @retval E_None on success
1254 @retval E_INVAL the format of the parameters was not valid
1255 @retval E_INTR function call was interrupted
1256 @retval E_IO on I/O errors
1257 @retval E_ISDIR is a directory
1258 @retval E_BADF bad file
1259 @retval E_FAULT bad address
1260 @retval E_AGAIN operation would block
1261 @retval E_NOLINK link has been severed
1269 RC
readLine( ::rtl::ByteSequence
& aSeq
)
1271 return static_cast< RC
>( osl_readLine( _pData
, reinterpret_cast<sal_Sequence
**>(&aSeq
) ) );
1274 /** Synchronize the memory representation of a file with that on the physical medium.
1276 The function ensures that all modified data and attributes of the file associated with
1277 the given file handle have been written to the physical medium.
1278 In case the hard disk has a write cache enabled, the data may not really be on
1279 permanent storage when osl_syncFile returns.
1281 @retval E_None On success
1282 @retval E_INVAL The value of the input parameter is invalid
1283 @retval E_BADF The file is not open for writing
1284 @retval E_IO An I/O error occurred
1285 @retval E_NOSPC There is no enough space on the target device
1286 @retval E_ROFS The file is located on a read only file system
1287 @retval E_TIMEDOUT A remote connection timed out. This may happen when a file is on a remote location
1295 OSL_PRECOND(_pData
, "File::sync(): File not open");
1296 return static_cast< RC
>(osl_syncFile(_pData
));
1299 /** Copy a file to a new destination.
1301 Copies a file to a new destination. Copies only files not directories.
1302 No assumptions should be made about preserving attributes or file time.
1304 @param[in] ustrSourceFileURL
1305 Full qualified URL of the source file.
1307 @param[in] ustrDestFileURL
1308 Full qualified URL of the destination file. A directory is NOT a valid destination file!
1310 @retval E_None on success
1311 @retval E_INVAL the format of the parameters was not valid
1312 @retval E_NOMEM not enough memory for allocating structures
1313 @retval E_ACCES permission denied
1314 @retval E_PERM operation not permitted
1315 @retval E_NAMETOOLONG file name too long
1316 @retval E_NOENT no such file or directory
1317 @retval E_ISDIR is a directory
1318 @retval E_ROFS read-only file system
1324 static RC
copy( const ::rtl::OUString
& ustrSourceFileURL
, const ::rtl::OUString
& ustrDestFileURL
)
1326 return static_cast< RC
>( osl_copyFile( ustrSourceFileURL
.pData
, ustrDestFileURL
.pData
) );
1329 /** Move a file or directory to a new destination or renames it.
1331 Moves a file or directory to a new destination or renames it.
1332 File time and attributes are preserved.
1334 @param[in] ustrSourceFileURL
1335 Full qualified URL of the source file.
1337 @param[in] ustrDestFileURL
1338 Full qualified URL of the destination file. An existing directory is NOT a valid destination !
1340 @retval E_None on success
1341 @retval E_INVAL the format of the parameters was not valid
1342 @retval E_NOMEM not enough memory for allocating structures
1343 @retval E_ACCES permission denied
1344 @retval E_PERM operation not permitted
1345 @retval E_NAMETOOLONG file name too long
1346 @retval E_NOENT no such file or directory
1347 @retval E_ROFS read-only file system
1352 static RC
move( const ::rtl::OUString
& ustrSourceFileURL
, const ::rtl::OUString
& ustrDestFileURL
)
1354 return static_cast< RC
>( osl_moveFile( ustrSourceFileURL
.pData
, ustrDestFileURL
.pData
) );
1357 /** Move a file to a new destination or rename it, taking old file's identity (if exists).
1359 Moves or renames a file, replacing an existing file if exist. If the old file existed,
1360 moved file's metadata, e.g. creation time (on FSes which keep files' creation time) or
1361 ACLs, are set to old one's (to keep the old file's identity) - currently this is only
1362 implemented fully on Windows; on other platforms, this is mostly equivalent to move().
1364 @param[in] ustrSourceFileURL
1365 Full qualified URL of the source file.
1367 @param[in] ustrDestFileURL
1368 Full qualified URL of the destination file.
1370 @retval E_None on success
1371 @retval E_INVAL the format of the parameters was not valid
1372 @retval E_NOMEM not enough memory for allocating structures
1373 @retval E_ACCES permission denied
1374 @retval E_PERM operation not permitted
1375 @retval E_NAMETOOLONG file name too long
1376 @retval E_NOENT no such file
1377 @retval E_ROFS read-only file system
1378 @retval E_BUSY device or resource busy
1382 @since LibreOffice 6.2
1384 static RC
replace(const ::rtl::OUString
& ustrSourceFileURL
,
1385 const ::rtl::OUString
& ustrDestFileURL
)
1387 return static_cast<RC
>(osl_replaceFile(ustrSourceFileURL
.pData
, ustrDestFileURL
.pData
));
1390 /** Remove a regular file.
1392 @param[in] ustrFileURL
1393 Full qualified URL of the file to remove.
1395 @retval E_None on success
1396 @retval E_INVAL the format of the parameters was not valid
1397 @retval E_NOMEM not enough memory for allocating structures
1398 @retval E_ACCES permission denied
1399 @retval E_PERM operation not permitted
1400 @retval E_NAMETOOLONG file name too long
1401 @retval E_NOENT no such file or directory
1402 @retval E_ISDIR is a directory
1403 @retval E_ROFS read-only file system
1404 @retval E_FAULT bad address
1405 @retval E_LOOP too many symbolic links encountered
1406 @retval E_IO on I/O errors
1407 @retval E_BUSY device or resource busy
1408 @retval E_INTR function call was interrupted
1409 @retval E_MULTIHOP multihop attempted
1410 @retval E_NOLINK link has been severed
1411 @retval E_TXTBSY text file busy
1416 static RC
remove( const ::rtl::OUString
& ustrFileURL
)
1418 return static_cast< RC
>( osl_removeFile( ustrFileURL
.pData
) );
1421 /** Set file attributes.
1423 @param[in] ustrFileURL
1424 The full qualified file URL.
1426 @param[in] uAttributes
1427 Attributes of the file to be set.
1430 @retval E_None on success
1431 @retval E_INVAL the format of the parameters was not valid
1436 static RC
setAttributes( const ::rtl::OUString
& ustrFileURL
, sal_uInt64 uAttributes
)
1438 return static_cast< RC
>( osl_setFileAttributes( ustrFileURL
.pData
, uAttributes
) );
1441 /** Set the file time.
1443 @param[in] ustrFileURL
1444 The full qualified URL of the file.
1446 @param[in] rCreationTime
1447 Creation time of the given file.
1449 @param[in] rLastAccessTime
1450 Time of the last access of the given file.
1452 @param[in] rLastWriteTime
1453 Time of the last modifying of the given file.
1455 @retval E_None on success
1456 @retval E_INVAL the format of the parameters was not valid
1457 @retval E_NOENT no such file or directory not found
1463 const ::rtl::OUString
& ustrFileURL
,
1464 const TimeValue
& rCreationTime
,
1465 const TimeValue
& rLastAccessTime
,
1466 const TimeValue
& rLastWriteTime
)
1468 return static_cast< RC
>( osl_setFileTime(
1472 &rLastWriteTime
) );
1475 friend class DirectoryItem
;
1479 /** The directory item class object provides access to file status information.
1484 class DirectoryItem
: public FileBase
1486 oslDirectoryItem _pData
;
1493 DirectoryItem(): _pData( NULL
)
1497 /** Copy constructor.
1500 DirectoryItem( const DirectoryItem
& rItem
): _pData( rItem
._pData
)
1503 osl_acquireDirectoryItem( _pData
);
1512 osl_releaseDirectoryItem( _pData
);
1515 /** Assignment operator.
1518 DirectoryItem
& operator=(const DirectoryItem
& rItem
)
1523 osl_releaseDirectoryItem( _pData
);
1525 _pData
= rItem
._pData
;
1528 osl_acquireDirectoryItem( _pData
);
1533 /** Check for validity of this instance.
1536 true if object is valid directory item else false.
1541 return _pData
!= NULL
;
1544 /** Retrieve a single directory item.
1546 Retrieves a single directory item. The returned handle has an initial refcount of 1.
1547 Due to performance issues it is not recommended to use this function while
1548 enumerating the contents of a directory. In this case use osl_getNextDirectoryItem() instead.
1550 @param[in] ustrFileURL
1551 An absolute file URL.
1554 On success it receives a handle which can be used for subsequent calls to osl_getFileStatus().
1555 The handle has to be released by a call to osl_releaseDirectoryItem().
1557 @retval E_None on success
1558 @retval E_INVAL the format of the parameters was not valid
1559 @retval E_NOMEM not enough memory for allocating structures
1560 @retval E_ACCES permission denied
1561 @retval E_MFILE too many open files used by the process
1562 @retval E_NFILE too many open files in the system
1563 @retval E_NOENT no such file or directory
1564 @retval E_LOOP too many symbolic links encountered
1565 @retval E_NAMETOOLONG the file name is too long
1566 @retval E_NOTDIR a component of the path prefix of path is not a directory
1567 @retval E_IO on I/O errors
1568 @retval E_MULTIHOP multihop attempted
1569 @retval E_NOLINK link has been severed
1570 @retval E_FAULT bad address
1571 @retval E_INTR the function call was interrupted
1574 @see Directory::getNextItem()
1577 static RC
get( const ::rtl::OUString
& ustrFileURL
, DirectoryItem
& rItem
)
1581 osl_releaseDirectoryItem( rItem
._pData
);
1582 rItem
._pData
= NULL
;
1585 return static_cast< RC
>( osl_getDirectoryItem( ustrFileURL
.pData
, &rItem
._pData
) );
1588 /** Retrieve information about a single file or directory.
1590 @param[in,out] rStatus
1591 Reference to a class which receives the information of the file or directory
1592 represented by this directory item.
1594 @retval E_None on success
1595 @retval E_NOMEM not enough memory for allocating structures
1596 @retval E_INVAL the format of the parameters was not valid
1597 @retval E_LOOP too many symbolic links encountered
1598 @retval E_ACCES permission denied
1599 @retval E_NOENT no such file or directory
1600 @retval E_NAMETOOLONG file name too long
1601 @retval E_BADF invalid oslDirectoryItem parameter
1602 @retval E_FAULT bad address
1603 @retval E_OVERFLOW value too large for defined data type
1604 @retval E_INTR function call was interrupted
1605 @retval E_NOLINK link has been severed
1606 @retval E_MULTIHOP components of path require hopping to multiple remote machines and the file system does not allow it
1607 @retval E_MFILE too many open files used by the process
1608 @retval E_NFILE too many open files in the system
1609 @retval E_NOSPC no space left on device
1610 @retval E_NXIO no such device or address
1611 @retval E_IO on I/O errors
1612 @retval E_NOSYS function not implemented
1615 @see Directory::getNextItem()
1619 RC
getFileStatus( FileStatus
& rStatus
)
1621 return static_cast< RC
>( osl_getFileStatus( _pData
, &rStatus
._aStatus
, rStatus
._nMask
) );
1624 /** Determine if a directory item point the same underlying file
1626 The comparison is done first by URL, and then by resolving links to
1627 find the target, and finally by comparing inodes on unix.
1630 A directory handle to compare with the underlying object's item
1632 @retval true if the items point to an identical resource<br>
1633 @retval false if the items point to a different resource, or a fatal error occurred<br>
1635 @see osl_getDirectoryItem()
1637 @since LibreOffice 3.6
1639 bool isIdenticalTo( const DirectoryItem
&pOther
)
1641 return osl_identicalDirectoryItem( _pData
, pOther
._pData
);
1644 friend class Directory
;
1648 /** Base class for observers of directory creation notifications.
1650 Clients which uses the method createDirectoryPath of the class
1651 Directory may want to be informed about the directories that
1652 have been created. This may be accomplished by deriving from
1653 this base class and overwriting the virtual function
1656 @see Directory::createPath
1658 class DirectoryCreationObserver
1661 virtual ~DirectoryCreationObserver() {}
1663 /** This method will be called when a new directory has been
1664 created and needs to be overwritten by derived classes.
1665 You must not delete the directory that was just created
1666 otherwise you will run into an endless loop.
1668 @param aDirectoryUrl
1669 [in]The absolute file URL of the directory that was just created by
1670 ::osl::Directory::createPath.
1672 virtual void DirectoryCreated(const rtl::OUString
& aDirectoryUrl
) = 0;
1676 // This just an internal helper function for
1678 extern "C" inline void SAL_CALL
onDirectoryCreated(void* pData
, rtl_uString
* aDirectoryUrl
)
1680 static_cast<DirectoryCreationObserver
*>(pData
)->DirectoryCreated(aDirectoryUrl
);
1683 /** The directory class object provides an enumeration of DirectoryItems.
1689 class Directory
: public FileBase
1691 oslDirectory _pData
;
1692 ::rtl::OUString _aPath
;
1694 /** Copy constructor.
1697 Directory( Directory
& ) SAL_DELETED_FUNCTION
;
1699 /** Assignment operator.
1702 Directory
& operator = ( Directory
& ) SAL_DELETED_FUNCTION
;
1709 The full qualified URL of the directory.
1710 Relative URLs are not allowed.
1713 Directory( const ::rtl::OUString
& strPath
): _pData( NULL
), _aPath( strPath
)
1728 the URL with which this Directory instance was created.
1730 @since LibreOffice 4.1
1732 rtl::OUString
getURL() const { return _aPath
; }
1734 /** Open a directory for enumerating its contents.
1736 @retval E_None on success
1737 @retval E_INVAL the format of the parameters was not valid
1738 @retval E_NOENT the specified path doesn't exist
1739 @retval E_NOTDIR the specified path is not a directory
1740 @retval E_NOMEM not enough memory for allocating structures
1741 @retval E_ACCES permission denied
1742 @retval E_MFILE too many open files used by the process
1743 @retval E_NFILE too many open files in the system
1744 @retval E_NAMETOOLONG File name too long
1745 @retval E_LOOP Too many symbolic links encountered
1753 return static_cast< RC
>( osl_openDirectory( _aPath
.pData
, &_pData
) );
1756 /** Query if directory is open.
1758 Query if directory is open and so item enumeration is valid.
1760 @retval true if the directory is open else false.
1766 bool isOpen() { return _pData
!= NULL
; }
1768 /** Close a directory.
1770 @retval E_None on success
1771 @retval E_INVAL the format of the parameters was not valid
1772 @retval E_NOMEM not enough memory for allocating structures
1773 @retval E_BADF invalid oslDirectory parameter
1774 @retval E_INTR the function call was interrupted
1781 oslFileError Error
= osl_File_E_BADF
;
1785 Error
=osl_closeDirectory( _pData
);
1789 return static_cast< RC
>( Error
);
1793 /** Resets the directory item enumeration to the beginning.
1795 @retval E_None on success
1796 @retval E_INVAL the format of the parameters was not valid
1797 @retval E_NOENT the specified path doesn't exist
1798 @retval E_NOTDIR the specified path is not a directory
1799 @retval E_NOMEM not enough memory for allocating structures
1800 @retval E_ACCES permission denied
1801 @retval E_MFILE too many open files used by the process
1802 @retval E_NFILE too many open files in the system
1803 @retval E_NAMETOOLONG File name too long
1804 @retval E_LOOP Too many symbolic links encountered
1815 /** Retrieve the next item of a previously opened directory.
1817 Retrieves the next item of a previously opened directory.
1820 On success a valid DirectoryItem.
1823 With this parameter the caller can tell the implementation that (s)he
1824 is going to call this function uHint times afterwards. This enables the implementation to
1825 get the information for more than one file and cache it until the next calls.
1827 @retval E_None on success
1828 @retval E_INVAL the format of the parameters was not valid
1829 @retval E_NOMEM not enough memory for allocating structures
1830 @retval E_NOENT no more entries in this directory
1831 @retval E_BADF invalid oslDirectory parameter
1832 @retval E_OVERFLOW the value too large for defined data type
1837 RC
getNextItem( DirectoryItem
& rItem
, sal_uInt32 nHint
= 0 )
1841 osl_releaseDirectoryItem( rItem
._pData
);
1842 rItem
._pData
= NULL
;
1844 return static_cast<RC
>(osl_getNextDirectoryItem( _pData
, &rItem
._pData
, nHint
));
1848 /** Retrieve information about a volume.
1850 Retrieves information about a volume. A volume can either be a mount point, a network
1851 resource or a drive depending on Operating System and File System.
1853 @param[in] ustrDirectoryURL
1854 Full qualified URL of the volume
1857 On success it receives information about the volume.
1859 @retval E_None on success
1860 @retval E_NOMEM not enough memory for allocating structures
1861 @retval E_INVAL the format of the parameters was not valid
1862 @retval E_NOTDIR not a directory
1863 @retval E_NAMETOOLONG file name too long
1864 @retval E_NOENT no such file or directory
1865 @retval E_ACCES permission denied
1866 @retval E_LOOP too many symbolic links encountered
1867 @retval E_FAULT Bad address
1868 @retval E_IO on I/O errors
1869 @retval E_NOSYS function not implemented
1870 @retval E_MULTIHOP multihop attempted
1871 @retval E_NOLINK link has been severed
1872 @retval E_INTR function call was interrupted
1878 static RC
getVolumeInfo( const ::rtl::OUString
& ustrDirectoryURL
, VolumeInfo
& rInfo
)
1880 return static_cast< RC
>( osl_getVolumeInformation( ustrDirectoryURL
.pData
, &rInfo
._aInfo
, rInfo
._nMask
) );
1883 /** Create a directory.
1885 @param[in] ustrDirectoryURL
1886 Full qualified URL of the directory to create.
1889 Optional flags, see osl_createDirectoryWithFlags for details. This
1890 defaulted parameter is new since LibreOffice 4.3.
1892 @retval E_None on success
1893 @retval E_INVAL the format of the parameters was not valid
1894 @retval E_NOMEM not enough memory for allocating structures
1895 @retval E_EXIST file exists
1896 @retval E_ACCES permission denied
1897 @retval E_NAMETOOLONG file name too long
1898 @retval E_NOENT no such file or directory
1899 @retval E_NOTDIR not a directory
1900 @retval E_ROFS read-only file system
1901 @retval E_NOSPC no space left on device
1902 @retval E_DQUOT quota exceeded
1903 @retval E_LOOP too many symbolic links encountered
1904 @retval E_FAULT bad address
1905 @retval E_IO on I/O errors
1906 @retval E_MLINK too many links
1907 @retval E_MULTIHOP multihop attempted
1908 @retval E_NOLINK link has been severed
1914 const ::rtl::OUString
& ustrDirectoryURL
,
1915 sal_uInt32 flags
= osl_File_OpenFlag_Read
| osl_File_OpenFlag_Write
)
1917 return static_cast< RC
>(
1918 osl_createDirectoryWithFlags( ustrDirectoryURL
.pData
, flags
) );
1921 /** Remove an empty directory.
1923 @param[in] ustrDirectoryURL
1924 Full qualified URL of the directory.
1926 @retval E_None on success
1927 @retval E_INVAL the format of the parameters was not valid
1928 @retval E_NOMEM not enough memory for allocating structures
1929 @retval E_PERM operation not permitted
1930 @retval E_ACCES permission denied
1931 @retval E_NOENT no such file or directory
1932 @retval E_NOTDIR not a directory
1933 @retval E_NOTEMPTY directory not empty
1934 @retval E_FAULT bad address
1935 @retval E_NAMETOOLONG file name too long
1936 @retval E_BUSY device or resource busy
1937 @retval E_ROFS read-only file system
1938 @retval E_LOOP too many symbolic links encountered
1939 @retval E_EXIST file exists
1940 @retval E_IO on I/O errors
1941 @retval E_MULTIHOP multihop attempted
1942 @retval E_NOLINK link has been severed
1947 static RC
remove( const ::rtl::OUString
& ustrDirectoryURL
)
1949 return static_cast< RC
>( osl_removeDirectory( ustrDirectoryURL
.pData
) );
1952 /** Create a directory path.
1954 The osl_createDirectoryPath function creates a specified directory path.
1955 All nonexisting sub directories will be created.
1957 @attention You cannot rely on getting the error code E_EXIST for existing
1958 directories. Programming against this error code is in general a strong
1959 indication of a wrong usage of osl_createDirectoryPath.
1961 @param aDirectoryUrl
1962 [in] The absolute file URL of the directory path to create.
1963 A relative file URL will not be accepted.
1965 @param aDirectoryCreationObserver
1966 [in] Pointer to an instance of type DirectoryCreationObserver that will
1967 be informed about the creation of a directory. The value of this
1968 parameter may be NULL, in this case notifications will not be sent.
1970 @retval E_None On success
1971 @retval E_INVAL The format of the parameters was not valid
1972 @retval E_ACCES Permission denied
1973 @retval E_EXIST The final node of the specified directory path already exist
1974 @retval E_NAMETOOLONG The name of the specified directory path exceeds the maximum allowed length
1975 @retval E_NOTDIR A component of the specified directory path already exist as file in any part of the directory path
1976 @retval E_ROFS Read-only file system
1977 @retval E_NOSPC No space left on device
1978 @retval E_DQUOT Quota exceeded
1979 @retval E_FAULT Bad address
1980 @retval E_IO I/O error
1981 @retval E_LOOP Too many symbolic links encountered
1982 @retval E_NOLINK Link has been severed
1983 @retval E_invalidError An unknown error occurred
1985 @see DirectoryCreationObserver
1988 static RC
createPath(
1989 const ::rtl::OUString
& aDirectoryUrl
,
1990 DirectoryCreationObserver
* aDirectoryCreationObserver
= NULL
)
1992 return static_cast< RC
>(osl_createDirectoryPath(
1993 aDirectoryUrl
.pData
,
1994 aDirectoryCreationObserver
? onDirectoryCreated
: NULL
,
1995 aDirectoryCreationObserver
));
1999 } /* namespace osl */
2001 #endif // INCLUDED_OSL_FILE_HXX
2003 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */