GNU Octave  6.2.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-2021 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 namespace octave
46 {
47  namespace sys
48  {
49  bool
50  dir_entry::open (const std::string& n)
51  {
52  if (! n.empty ())
53  name = n;
54 
55  if (! name.empty ())
56  {
57  close ();
58 
59  std::string fullname = sys::file_ops::tilde_expand (name);
60 
61  dir = octave_opendir_wrapper (fullname.c_str ());
62 
63  if (! dir)
64  errmsg = std::strerror (errno);
65  }
66  else
67  errmsg = "dir_entry::open: empty filename";
68 
69  return dir != nullptr;
70  }
71 
74  {
76 
77  if (ok ())
78  {
79  std::list<std::string> dirlist;
80 
81  char *fname;
82 
83  while ((fname = octave_readdir_wrapper (dir)))
84  dirlist.push_back (fname);
85 
86  retval = string_vector (dirlist);
87  }
88 
89  return retval;
90  }
91 
92  bool
94  {
95  bool retval = true;
96 
97  if (dir)
98  {
100 
101  dir = nullptr;
102  }
103 
104  return retval;
105  }
106 
107  unsigned int
109  {
110  return octave_name_max_wrapper ();
111  }
112  }
113 }
void * dir
Definition: dir-ops.h:98
bool close(void)
Definition: dir-ops.cc:93
bool open(const std::string &="")
Definition: dir-ops.cc:50
string_vector read(void)
Definition: dir-ops.cc:73
std::string errmsg
Definition: dir-ops.h:104
std::string name
Definition: dir-ops.h:93
static unsigned int max_name_length(void)
Definition: dir-ops.cc:108
bool ok(void) const
Definition: dir-ops.h:82
unsigned int octave_name_max_wrapper(void)
char * octave_readdir_wrapper(void *dir)
void * octave_opendir_wrapper(const char *dname)
int octave_closedir_wrapper(void *dir)
octave_idx_type n
Definition: mx-inlines.cc:753
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:286
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811