GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dir-ops.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://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 != 0;
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  {
96  retval = (octave_closedir_wrapper (dir) == 0);
97 
98  dir = 0;
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)
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
fname
Definition: load-save.cc:754
void * dir
Definition: dir-ops.h:89
static std::string tilde_expand(const std::string &)
Definition: file-ops.cc:301
bool ok(void) const
Definition: dir-ops.h:73
string_vector read(void)
Definition: dir-ops.cc:70
int octave_closedir_wrapper(void *dir)
octave_value retval
Definition: data.cc:6294
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:854
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