1 mike 1.1 //BEGIN_LICENSE
2 //
3 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 // DEALINGS IN THE SOFTWARE.
19 //
20 //END_LICENSE
21 //BEGIN_HISTORY
22 mike 1.1 //
23 // Author:
24 //
25 // $Log: Dir.cpp,v $
26 // Revision 1.1 2001/02/11 05:42:33 mike
27 // new
28 //
29 // Revision 1.1.1.1 2001/01/14 19:50:23 mike
30 // Pegasus import
31 //
32 //
33 //END_HISTORY
34
35 #include "Destroyer.h"
36 #include "Dir.h"
37 #include "Exception.h"
38
39 PEGASUS_NAMESPACE_BEGIN
40
41 #include <io.h>
42 #include <direct.h>
43 mike 1.1
44 struct DirRep
45 {
46 long file;
47 struct _finddata_t findData;
48 };
49
50 Dir::Dir(const String& path)
51 {
52 Destroyer<char> p(strcat(path.allocateCString(2), "/*"));
53 _rep = new DirRep;
54 _rep->file = _findfirst(p.getPointer(), &_rep->findData);
55
56 if (_rep->file == -1)
57 {
58 _more = false;
59 throw CannotOpenDirectory(path);
60 }
61 else
62 _more = true;
63 }
64 mike 1.1
65 Dir::~Dir()
66 {
67 if (_rep->file != -1)
68 _findclose(_rep->file);
69
70 delete _rep;
71 }
72
73 const char* Dir::getName() const
74 {
75 return _rep->findData.name;
76 }
77
78 void Dir::next()
79 {
80 if (!_more)
81 return;
82
83 _more = _findnext(_rep->file, &_rep->findData) == 0;
84 }
85 mike 1.1
86 PEGASUS_NAMESPACE_END
|