1 karl 1.17 //%2004////////////////////////////////////////////////////////////////////////
|
2 mike 1.8 //
|
3 karl 1.17 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.13 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 mike 1.8 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
11 kumpf 1.9 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
14 mike 1.8 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
|
17 kumpf 1.9 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
18 mike 1.8 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
19 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
20 kumpf 1.9 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
23 mike 1.8 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 //==============================================================================
27 //
28 // Author: Mike Brasher (mbrasher@bmc.com)
29 //
|
30 a.arora 1.14 // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
|
31 mike 1.8 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_Dir_h
35 #define Pegasus_Dir_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/String.h>
|
39 kumpf 1.11 #include <Pegasus/Common/InternalException.h>
|
40 kumpf 1.10 #include <Pegasus/Common/Linkage.h>
|
41 a.arora 1.14 #include <Pegasus/Common/AutoPtr.h>
|
42 mike 1.8
43 PEGASUS_NAMESPACE_BEGIN
44
|
45 a.arora 1.15 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
46 gs.keenan 1.21 #include <io.h>
|
47 a.arora 1.15 typedef struct
48 {
49 long file;
50 struct _finddata_t findData;
51 } DirRep;
|
52 gs.keenan 1.21 #elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS)
53 #if defined(PEGASUS_OS_SOLARIS)
54 #include <sys/param.h>
55 #endif /* if defined(PEGASUS_OS_SOLARIS) */
56
57 #include <dirent.h>
58
59 #ifndef PEGASUS_OS_VMS
60 #define PEGASUS_HAS_READDIR_R
61 #endif /* ifndef PEGASUS_OS_VMS */
|
62 a.arora 1.15
|
63 gs.keenan 1.20 typedef struct
|
64 a.arora 1.15 {
65 DIR* dir;
|
66 gs.keenan 1.21 #ifdef PEGASUS_OS_OS400
|
67 a.arora 1.15 struct dirent_lg* entry;
|
68 gs.keenan 1.21 #else /* ifdef PEGASUS_OS_OS400 */
|
69 a.arora 1.15 struct dirent* entry;
|
70 gs.keenan 1.21 #endif /* ifdef PEGASUS_OS_OS400 */
71 #ifdef PEGASUS_HAS_READDIR_R
72 #ifdef PEGASUS_OS_OS400
|
73 a.arora 1.15 struct dirent_lg buffer;
|
74 gs.keenan 1.21 #else /* ifdef PEGASUS_OS_OS400 */
75 #ifdef PEGASUS_OS_SOLARIS
|
76 a.arora 1.15 private:
77 char buf[sizeof(dirent) + MAXNAMELEN];
78 public:
79 struct dirent &buffer;
80 inline DirRep()
81 : buffer(*reinterpret_cast<struct dirent *>(buf))
82 { }
|
83 gs.keenan 1.21 #else /* ifdef PEGASUS_OS_SOLARIS */
|
84 a.arora 1.15 struct dirent buffer;
|
85 gs.keenan 1.21 #endif /* ifdef PEGASUS_OS_SOLARIS */
86 #endif /* ifdef PEGASUS_OS_OS400 */
87 #endif /* ifdef PEGASUS_HAS_READDIR_R */
|
88 gs.keenan 1.20 } DirRep;
|
89 gs.keenan 1.21 #endif /* elif defined(PEGASUS_OS_TYPE_UNIX) || defined (PEGASUS_OS_VMS) */
|
90 mike 1.8
91 /** The Dir class provides a platform independent way of iterating the
92 files in a directory.
93 */
94 class PEGASUS_COMMON_LINKAGE Dir
95 {
96 public:
97
98 /** Starts this iterator class on the given path.
99 @param String path is the path to the target directory
100 @return
101 @exception throws CannotOpenDirectory if invalid directory.
102
103 <pre>
104 char* path = "."
105 try
106 {
107 for (Dir dir(path); dir.more(); dir.next())
108 {
109 cout << "name: " << dir.getName() << endl;
110 }
111 mike 1.8 }
112 catch(CannotOpenDirectory&)
113 {
114 // Error!
115 }
116 </pre>
117 */
118 Dir(const String& path);
119
120 /** Release any iterator resources. */
121 ~Dir();
122
123 /** Return true if there are more file names to iterator. */
124 Boolean more() const { return _more; }
|
125 bafna.mukesh 1.18
126 #if defined(PEGASUS_PLATFORM_DARWIN_PPC_GNU)
127 /** Returns the file inode number. */
128 const Uint32 getInode() const;
129 #endif
|
130 mike 1.8
131 /** Returns the current file name. */
132 const char* getName() const;
133
134 /** Advance to next file in directory. */
135 void next();
136
137 private:
138
139 Boolean _more;
140 Boolean _isValid;
|
141 kumpf 1.12 String _path;
|
142 a.arora 1.15 DirRep _dirRep;
|
143 mike 1.8 };
144
145 PEGASUS_NAMESPACE_END
146
147 #endif /* Pegasus_Dir_h */
|