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