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