1782
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1782
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <cerrno> |
|
28 #include <cstring> |
|
29 |
|
30 #include "sysdir.h" |
|
31 |
|
32 #include "dir-ops.h" |
|
33 #include "str-vec.h" |
|
34 |
|
35 bool |
|
36 dir_entry::open (const string& n) |
|
37 { |
|
38 fail = true; |
|
39 |
|
40 if (! n.empty ()) |
|
41 name = n; |
|
42 |
|
43 if (! name.empty ()) |
|
44 { |
|
45 close (); |
|
46 |
2800
|
47 dir = static_cast<void *> (opendir (name.c_str ())); |
1782
|
48 |
|
49 if (dir) |
|
50 fail = false; |
|
51 else |
|
52 errmsg = strerror (errno); |
|
53 } |
|
54 else |
|
55 errmsg = "dir_entry::open: empty file name"; |
|
56 |
|
57 return ! fail; |
|
58 } |
|
59 |
|
60 string_vector |
|
61 dir_entry::read (void) |
|
62 { |
|
63 string_vector dirlist; |
|
64 |
|
65 if (ok ()) |
|
66 { |
|
67 int count = 0; |
|
68 |
|
69 struct dirent *dir_ent; |
|
70 |
2800
|
71 while ((dir_ent = readdir (static_cast<DIR *> (dir)))) |
1782
|
72 count++; |
|
73 |
2800
|
74 rewinddir (static_cast<DIR *> (dir)); |
1782
|
75 |
|
76 dirlist.resize (count); |
|
77 |
|
78 for (int i = 0; i < count; i++) |
|
79 { |
2800
|
80 dir_ent = readdir (static_cast<DIR *> (dir)); |
1782
|
81 |
|
82 if (dir_ent) |
|
83 dirlist[i] = dir_ent->d_name; |
|
84 else |
|
85 break; |
|
86 } |
|
87 } |
|
88 |
|
89 return dirlist; |
|
90 } |
|
91 |
|
92 void |
|
93 dir_entry::close (void) |
|
94 { |
|
95 if (dir) |
2800
|
96 closedir (static_cast<DIR *> (dir)); |
1782
|
97 |
|
98 dir = 0; |
|
99 } |
|
100 |
|
101 void |
|
102 dir_entry::copy (const dir_entry& de) |
|
103 { |
|
104 name = de.name; |
|
105 dir = de.dir; |
|
106 fail = de.fail; |
|
107 errmsg = de.errmsg; |
|
108 } |
|
109 |
|
110 /* |
|
111 ;;; Local Variables: *** |
|
112 ;;; mode: C++ *** |
|
113 ;;; End: *** |
|
114 */ |