annotate liboctave/system/dir-ops.h @ 21926:24215a16f3b2

hide dirent.h header * liboctave/wrappers/dirent-wrappers.c, liboctave/wrappers/dirent-wrappers.h: New files. * liboctave/wrappers/module.mk: Update. * dir-ops.cc, dir-ops.h: Use new wrapper functions. (dir_entry::close): Return status. (dir_entry::max_name_length): New function. * kpse.cc: Use octave::sys::dir_entry::max_name_length function instead of NAME_MAX macro.
author John W. Eaton <jwe@octave.org>
date Thu, 16 Jun 2016 10:02:49 -0400
parents 949cb46e6bdb
children bac0d6f07a3e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
1 /*
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17769
diff changeset
3 Copyright (C) 1996-2015 John W. Eaton
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
4
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
6
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
10 option) any later version.
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
11
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
15 for more details.
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
16
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6108
diff changeset
19 <http://www.gnu.org/licenses/>.
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
20
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
21 */
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
22
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 19697
diff changeset
23 #if ! defined (octave_dir_ops_h)
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
24 #define octave_dir_ops_h 1
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
25
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
26 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
27
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
28 #include <string>
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
29
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
30 #include "str-vec.h"
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
31
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
32 namespace octave
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
33 {
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
34 namespace sys
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
35 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
36 class
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
37 OCTAVE_API
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
38 dir_entry
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
39 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
40 public:
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
41
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
42 dir_entry (const std::string& n = "")
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
43 : name (n), dir (0), fail (false), errmsg ()
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
44 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
45 if (! name.empty ())
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
46 open ();
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
47 }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
48
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
49 dir_entry (const dir_entry& d)
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
50 : name (d.name), dir (d.dir), fail (d.fail), errmsg (d.errmsg) { }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
51
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
52 dir_entry& operator = (const dir_entry& d)
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
53 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
54 if (this != &d)
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
55 {
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
56 name = d.name;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
57 dir = d.dir;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
58 fail = d.fail;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
59 errmsg = d.errmsg;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
60 }
1929
908f5b6676d7 [project @ 1996-02-11 22:05:08 by jwe]
jwe
parents: 1879
diff changeset
61
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
62 return *this;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
63 }
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
64
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
65 ~dir_entry (void) { close (); }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
66
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
67 bool open (const std::string& = "");
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
68
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
69 string_vector read (void);
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
70
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21752
diff changeset
71 bool close (void);
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
72
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
73 bool ok (void) const { return dir && ! fail; }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
74
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
75 operator bool () const { return ok (); }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
76
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
77 std::string error (void) const { return ok () ? "" : errmsg; }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
78
21926
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21752
diff changeset
79 static unsigned int max_name_length (void);
24215a16f3b2 hide dirent.h header
John W. Eaton <jwe@octave.org>
parents: 21752
diff changeset
80
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
81 private:
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
82
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
83 // Name of the directory.
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
84 std::string name;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
85
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
86 // A pointer to the contents of the directory. We use void here to
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
87 // avoid possible conflicts with the way some systems declare the
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
88 // type DIR.
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
89 void *dir;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
90
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
91 // TRUE means the open for this directory failed.
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
92 bool fail;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
93
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
94 // If a failure occurs, this contains the system error text.
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
95 std::string errmsg;
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
96 };
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
97 }
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
98 }
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
99
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
100 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
101
21752
949cb46e6bdb use consistent style for deprecated function/class messages
John W. Eaton <jwe@octave.org>
parents: 21735
diff changeset
102 OCTAVE_DEPRECATED ("use 'octave::sys::dir_entry' instead")
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
103 typedef octave::sys::dir_entry dir_entry;
1782
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
104
b17d014b6926 [project @ 1996-01-24 08:09:17 by jwe]
jwe
parents:
diff changeset
105 #endif
21735
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
106
60212efcd9cb use namespace for dir_entry class
John W. Eaton <jwe@octave.org>
parents: 21244
diff changeset
107 #endif