(file) Return to Dir.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2