GNU Octave
8.1.0
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-2023 The Octave Project Developers
4
//
5
// See the file COPYRIGHT.md in the top-level directory of this
6
// distribution or <https://octave.org/copyright/>.
7
//
8
// This file is part of Octave.
9
//
10
// Octave is free software: you can redistribute it and/or modify it
11
// under the terms of the GNU General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// Octave is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with Octave; see the file COPYING. If not, see
22
// <https://www.gnu.org/licenses/>.
23
//
24
////////////////////////////////////////////////////////////////////////
25
26
#if defined (HAVE_CONFIG_H)
27
# include "config.h"
28
#endif
29
30
#include <cerrno>
31
#include <cstdlib>
32
#include <cstring>
33
34
#include <list>
35
#include <string>
36
37
#include "
dirent-wrappers.h
"
38
39
#include "
dir-ops.h
"
40
#include "
file-ops.h
"
41
#include "
lo-error.h
"
42
#include "
lo-sysdep.h
"
43
#include "
str-vec.h
"
44
45
OCTAVE_BEGIN_NAMESPACE
(
octave
)
46
47
OCTAVE_BEGIN_NAMESPACE
(sys)
48
49
bool
50
dir_entry::open
(
const
std::string&
n
)
51
{
52
if
(!
n
.empty ())
53
m_name
=
n
;
54
55
if
(!
m_name
.empty ())
56
{
57
close
();
58
59
std::string fullname =
sys::file_ops::tilde_expand
(
m_name
);
60
61
m_dir
=
octave_opendir_wrapper
(fullname.c_str ());
62
63
if
(!
m_dir
)
64
m_errmsg
= std::strerror (errno);
65
}
66
else
67
m_errmsg
=
"dir_entry::open: empty filename"
;
68
69
return
m_dir
!=
nullptr
;
70
}
71
72
string_vector
73
dir_entry::read
(
void
)
74
{
75
string_vector
retval;
76
77
if
(
ok
())
78
{
79
std::list<std::string> dirlist;
80
81
char
*fname;
82
83
while
((fname =
octave_readdir_wrapper
(
m_dir
)))
84
dirlist.push_back (fname);
85
86
retval =
string_vector
(dirlist);
87
}
88
89
return
retval;
90
}
91
92
bool
93
dir_entry::close
(
void
)
94
{
95
bool
retval =
true
;
96
97
if
(
m_dir
)
98
{
99
retval = (
octave_closedir_wrapper
(
m_dir
) == 0);
100
101
m_dir
=
nullptr
;
102
}
103
104
return
retval;
105
}
106
107
unsigned
int
108
dir_entry::max_name_length
(
void
)
109
{
110
return
octave_name_max_wrapper
();
111
}
112
113
OCTAVE_END_NAMESPACE
(sys)
114
OCTAVE_END_NAMESPACE
(
octave
)
OCTAVE_END_NAMESPACE
OCTAVE_END_NAMESPACE(octave)
dir_entry::m_dir
void * m_dir
Definition:
dir-ops.h:100
dir_entry::m_errmsg
std::string m_errmsg
Definition:
dir-ops.h:106
dir_entry::ok
bool ok(void) const
Definition:
dir-ops.h:84
dir_entry::max_name_length
static unsigned int max_name_length(void)
Definition:
dir-ops.cc:108
dir_entry::close
bool close(void)
Definition:
dir-ops.cc:93
dir_entry::read
string_vector read(void)
Definition:
dir-ops.cc:73
dir_entry::open
bool open(const std::string &="")
Definition:
dir-ops.cc:50
dir_entry::m_name
std::string m_name
Definition:
dir-ops.h:95
string_vector
Definition:
str-vec.h:40
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
dir-ops.h
octave_name_max_wrapper
unsigned int octave_name_max_wrapper(void)
Definition:
dirent-wrappers.c:83
octave_readdir_wrapper
char * octave_readdir_wrapper(void *dir)
Definition:
dirent-wrappers.c:46
octave_opendir_wrapper
void * octave_opendir_wrapper(const char *dname)
Definition:
dirent-wrappers.c:40
octave_closedir_wrapper
int octave_closedir_wrapper(void *dir)
Definition:
dirent-wrappers.c:60
dirent-wrappers.h
tilde_expand
std::string tilde_expand(const std::string &name)
Definition:
file-ops.cc:283
file-ops.h
lo-error.h
lo-sysdep.h
n
octave_idx_type n
Definition:
mx-inlines.cc:753
octave
Definition:
QTerminal.h:41
str-vec.h
liboctave
system
dir-ops.cc
Generated on Sun Mar 12 2023 22:37:22 for GNU Octave by
1.9.1