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

  1 mike  1.2 //%2006////////////////////////////////////////////////////////////////////////
  2           //
  3           // 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           // IBM Corp.; EMC Corporation, The Open Group.
  7           // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11           // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12           // EMC Corporation; Symantec Corporation; The Open Group.
 13           //
 14           // Permission is hereby granted, free of charge, to any person obtaining a copy
 15           // of this software and associated documentation files (the "Software"), to
 16           // deal in the Software without restriction, including without limitation the
 17           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18           // sell copies of the Software, and to permit persons to whom the Software is
 19           // furnished to do so, subject to the following conditions:
 20           // 
 21           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29           //
 30           //==============================================================================
 31           //
 32           // Author: Mike Brasher (mbrasher@bmc.com)
 33           //
 34           // Modified By: Amit K Arora, IBM (amita@in.ibm.com)
 35           //
 36           //%/////////////////////////////////////////////////////////////////////////////
 37           
 38           #include "Dir.h"
 39           #include "InternalException.h"
 40           
 41           #include <iostream>
 42           
 43 mike  1.2 #ifdef PEGASUS_OS_OS400
 44           typedef struct os400_pnstruct
 45           {
 46             Qlg_Path_Name_T qlg_struct;
 47             char * pn;
 48           } OS400_PNSTRUCT;
 49           #endif
 50           
 51           
 52           PEGASUS_NAMESPACE_BEGIN
 53           
 54           // Clone the string to a plain old C-String and null out
 55           // trailing slash (if any).
 56           
 57           static CString _clonePath(const String& path)
 58           {
 59               String clone = path;
 60           
 61               if (clone.size() && clone[clone.size()-1] == '/')
 62                   clone.remove(clone.size()-1);
 63           
 64 mike  1.2     return clone.getCString();
 65           }
 66           
 67           Dir::Dir(const String& path)
 68               : _path(path)
 69           {
 70           
 71           #ifdef PEGASUS_OS_OS400
 72               CString tmpPathclone = _clonePath(_path);
 73               const char* tmpPath = tmpPathclone;
 74               OS400_PNSTRUCT pathname;
 75               memset((void*)&pathname, 0x00, sizeof(OS400_PNSTRUCT));
 76               pathname.qlg_struct.CCSID = 1208;
 77           #pragma convert(37)
 78               memcpy(pathname.qlg_struct.Country_ID,"US",2);
 79               memcpy(pathname.qlg_struct.Language_ID,"ENU",3);
 80           #pragma convert(0)
 81               pathname.qlg_struct.Path_Type = QLG_PTR_SINGLE;
 82               pathname.qlg_struct.Path_Length = strlen(tmpPath);
 83               pathname.qlg_struct.Path_Name_Delimiter[0] = '/';
 84               pathname.pn = (char *)tmpPath;
 85 mike  1.2     _dirRep.dir = QlgOpendir((Qlg_Path_Name_T *)&pathname);
 86           #else
 87               _dirRep.dir = opendir(_clonePath(_path));
 88           #endif
 89               if (_dirRep.dir)
 90               {
 91           #ifdef PEGASUS_HAS_READDIR_R
 92           	// Need to use readdir_r since we are multithreaded
 93           #ifdef PEGASUS_OS_OS400
 94           	if (QlgReaddir_r(_dirRep.dir, &_dirRep.buffer, &_dirRep.entry) != 0)
 95           #else
 96           	if (readdir_r(_dirRep.dir, &_dirRep.buffer, &_dirRep.entry) != 0)
 97           #endif
 98                   {
 99           	    _more = false;
100                       closedir(_dirRep.dir);
101           	    throw CannotOpenDirectory(_path);
102                   }
103           #else
104           	_dirRep.entry = readdir(_dirRep.dir);
105           #endif
106 mike  1.2 	_more = _dirRep.entry != NULL;
107               }
108               else
109               {
110           	_more = false;
111           	throw CannotOpenDirectory(_path);
112               }
113           }
114           
115           Dir::~Dir()
116           {
117               if (_dirRep.dir)
118           	closedir(_dirRep.dir);
119           
120           }
121           
122           
123           const char* Dir::getName() const
124           {
125           #ifdef PEGASUS_OS_OS400
126               _dirRep.entry->d_lg_name[_dirRep.entry->d_lg_qlg.Path_Length] = 0x00;
127 mike  1.2     return _more ? _dirRep.entry->d_lg_name : "";
128           #else
129               return _more ? _dirRep.entry->d_name : "";
130           #endif
131           }
132           
133           void Dir::next()
134           {
135               if (_more)
136               {
137           #ifdef PEGASUS_HAS_READDIR_R
138           	// Need to use readdir_r since we are multithreaded
139           #ifdef PEGASUS_OS_OS400
140           	if (QlgReaddir_r(_dirRep.dir, &_dirRep.buffer, &_dirRep.entry) != 0)
141           #else
142           #ifdef PEGASUS_OS_ZOS
143               errno=0;
144           #endif
145               if (readdir_r(_dirRep.dir, &_dirRep.buffer, &_dirRep.entry) != 0)
146           #endif
147                   {
148 mike  1.2 	    _more = false;
149           	    throw CannotOpenDirectory(_path);
150                   }
151           #else
152           	_dirRep.entry = readdir(_dirRep.dir);
153           #endif
154           	_more = _dirRep.entry != NULL;
155               }
156           }
157           
158           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2