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
48  {
49  if (! n.empty ())
50  name = n;
51 
52  if (! name.empty ())
53  {
54  close ();
55 
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 
71  {
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
91  {
92  bool retval = true;
93 
94  if (dir)
95  {
97 
98  dir = nullptr;
99  }
100 
101  return retval;
102  }
103 
104  unsigned int
106  {
107  return octave_name_max_wrapper ();
108  }
109  }
110 }
unsigned int octave_name_max_wrapper(void)
fname
Definition: load-save.cc:767
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:276
void * dir
Definition: dir-ops.h:89
string_vector read(void)
Definition: dir-ops.cc:70
int octave_closedir_wrapper(void *dir)
bool ok(void) const
Definition: dir-ops.h:73
octave_value retval
Definition: data.cc:6246
void * octave_opendir_wrapper(const char *dname)
std::string errmsg
Definition: dir-ops.h:95
bool open(const std::string &="")
Definition: dir-ops.cc:47
char * octave_readdir_wrapper(void *dir)
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
static unsigned int max_name_length(void)
Definition: dir-ops.cc:105
std::string name
Definition: dir-ops.h:84
bool close(void)
Definition: dir-ops.cc:90