GNU Octave
4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
dir-ops.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1996-2018 John W. Eaton
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
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
Octave is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License 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, see
19
<https://www.gnu.org/licenses/>.
20
21
*/
22
23
#if defined (HAVE_CONFIG_H)
24
# include "config.h"
25
#endif
26
27
#include <cerrno>
28
#include <cstdlib>
29
#include <cstring>
30
31
#include <list>
32
#include <string>
33
34
#include "
dirent-wrappers.h
"
35
36
#include "
dir-ops.h
"
37
#include "
file-ops.h
"
38
#include "
lo-error.h
"
39
#include "
lo-sysdep.h
"
40
#include "
str-vec.h
"
41
42
namespace
octave
43
{
44
namespace
sys
45
{
46
bool
47
dir_entry::open
(
const
std::string
& n)
48
{
49
if
(! n.empty ())
50
name
= n;
51
52
if
(!
name
.empty ())
53
{
54
close
();
55
56
std::string
fullname =
sys::file_ops::tilde_expand
(
name
);
57
58
dir
=
octave_opendir_wrapper
(fullname.c_str ());
59
60
if
(!
dir
)
61
errmsg
= std::strerror (errno);
62
}
63
else
64
errmsg
=
"dir_entry::open: empty filename"
;
65
66
return
dir
!=
nullptr
;
67
}
68
69
string_vector
70
dir_entry::read
(
void
)
71
{
72
string_vector
retval
;
73
74
if
(
ok
())
75
{
76
std::list<std::string> dirlist;
77
78
char
*
fname
;
79
80
while
((
fname
=
octave_readdir_wrapper
(
dir
)))
81
dirlist.push_back (
fname
);
82
83
retval
=
string_vector
(dirlist);
84
}
85
86
return
retval
;
87
}
88
89
bool
90
dir_entry::close
(
void
)
91
{
92
bool
retval
=
true
;
93
94
if
(
dir
)
95
{
96
retval
= (
octave_closedir_wrapper
(
dir
) == 0);
97
98
dir
=
nullptr
;
99
}
100
101
return
retval
;
102
}
103
104
unsigned
int
105
dir_entry::max_name_length
(
void
)
106
{
107
return
octave_name_max_wrapper
();
108
}
109
}
110
}
file-ops.h
octave_name_max_wrapper
unsigned int octave_name_max_wrapper(void)
Definition:
dirent-wrappers.c:80
lo-sysdep.h
octave
Definition:
aepbalance.cc:44
fname
fname
Definition:
load-save.cc:767
octave::sys::file_ops::tilde_expand
std::string tilde_expand(const std::string &name)
Definition:
file-ops.cc:276
octave::sys::dir_entry::dir
void * dir
Definition:
dir-ops.h:89
str-vec.h
octave::sys::dir_entry::read
string_vector read(void)
Definition:
dir-ops.cc:70
octave_closedir_wrapper
int octave_closedir_wrapper(void *dir)
Definition:
dirent-wrappers.c:57
octave::sys::dir_entry::ok
bool ok(void) const
Definition:
dir-ops.h:73
lo-error.h
retval
octave_value retval
Definition:
data.cc:6246
dir-ops.h
octave_opendir_wrapper
void * octave_opendir_wrapper(const char *dname)
Definition:
dirent-wrappers.c:37
octave::sys::dir_entry::errmsg
std::string errmsg
Definition:
dir-ops.h:95
octave::sys::dir_entry::open
bool open(const std::string &="")
Definition:
dir-ops.cc:47
octave_readdir_wrapper
char * octave_readdir_wrapper(void *dir)
Definition:
dirent-wrappers.c:43
dirent-wrappers.h
string
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition:
utils.cc:888
octave::sys::dir_entry::max_name_length
static unsigned int max_name_length(void)
Definition:
dir-ops.cc:105
octave::sys::dir_entry::name
std::string name
Definition:
dir-ops.h:84
string_vector
Definition:
str-vec.h:34
octave::sys::dir_entry::close
bool close(void)
Definition:
dir-ops.cc:90
liboctave
system
dir-ops.cc
Generated on Sat Sep 1 2018 14:01:46 for GNU Octave by
1.8.14