Mercurial > hg > octave-lyh
annotate liboctave/dir-ops.cc @ 14444:245963d3d628 stable
pkg: bug fix - accessing non-existent variable for error message
author | Miguel Bazdresch <lmb@2pif.info> |
---|---|
date | Thu, 01 Mar 2012 14:58:59 +0000 |
parents | 583d3d6f6fde |
children |
rev | line source |
---|---|
1782 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1996-2012 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1782 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1782 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <cerrno> | |
2926 | 28 #include <cstdlib> |
1782 | 29 #include <cstring> |
30 | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
31 #include <list> |
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
32 #include <string> |
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
33 |
1782 | 34 #include "sysdir.h" |
35 | |
36 #include "dir-ops.h" | |
5871 | 37 #include "file-ops.h" |
2926 | 38 #include "lo-error.h" |
39 #include "lo-sysdep.h" | |
1782 | 40 #include "str-vec.h" |
41 | |
42 bool | |
3504 | 43 dir_entry::open (const std::string& n) |
1782 | 44 { |
45 fail = true; | |
46 | |
47 if (! n.empty ()) | |
48 name = n; | |
49 | |
50 if (! name.empty ()) | |
51 { | |
52 close (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 |
5871 | 54 std::string fullname = file_ops::tilde_expand (name); |
1782 | 55 |
10411 | 56 dir = static_cast<void *> (gnulib::opendir (fullname.c_str ())); |
1782 | 57 |
58 if (dir) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
59 fail = false; |
1782 | 60 else |
10411 | 61 errmsg = gnulib::strerror (errno); |
1782 | 62 } |
63 else | |
64 errmsg = "dir_entry::open: empty file name"; | |
65 | |
66 return ! fail; | |
67 } | |
68 | |
69 string_vector | |
70 dir_entry::read (void) | |
71 { | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
72 string_vector retval; |
1782 | 73 |
74 if (ok ()) | |
75 { | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 std::list<std::string> dirlist; |
1782 | 77 |
78 struct dirent *dir_ent; | |
79 | |
14155 | 80 while ((dir_ent = gnulib::readdir (static_cast<DIR *> (dir)))) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
81 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
82 if (dir_ent) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 dirlist.push_back (dir_ent->d_name); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
86 } |
6145 | 87 |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 retval = string_vector (dirlist); |
1782 | 89 } |
90 | |
8326
545b9f62adcf
dir-ops.cc (dir_entry::read): use std::list<std::string> to cache names before converting to string_vector
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 return retval; |
1782 | 92 } |
93 | |
94 void | |
95 dir_entry::close (void) | |
96 { | |
97 if (dir) | |
10411 | 98 gnulib::closedir (static_cast<DIR *> (dir)); |
1782 | 99 |
100 dir = 0; | |
101 } |