annotate liboctave/file-ops.cc @ 10197:4d433bd2d4dc

attempt to avoid trouble with gnulib #defines in a consistent way
author John W. Eaton <jwe@octave.org>
date Tue, 26 Jan 2010 00:45:04 -0500
parents 8fa6ce1b21f2
children 025564630c8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
1 /*
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
4 2007, 2008 John W. Eaton
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
5
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
7
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
9 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: 6709
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
11 option) any later version.
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
12
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
16 for more details.
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
17
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
18 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: 6709
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
20 <http://www.gnu.org/licenses/>.
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
21
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
22 */
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
23
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
26 #endif
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
27
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
28 #include <cerrno>
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
29 #include <cstdio>
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
30 #include <cstdlib>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
31 #include <cstring>
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
32
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3074
diff changeset
33 #include <iostream>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4578
diff changeset
34 #include <vector>
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
35
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
36 #include <sys/stat.h>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
37 #include <sys/types.h>
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
38 #include <unistd.h>
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
39
10179
326746625a51 file-ops.cc cleanups
John W. Eaton <jwe@octave.org>
parents: 10178
diff changeset
40 #include <pathmax.h>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
41
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
42 #include "dir-ops.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
43 #include "file-ops.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
44 #include "file-stat.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
45 #include "oct-env.h"
2934
dddc1b5c324e [project @ 1997-05-05 22:56:37 by jwe]
jwe
parents: 2926
diff changeset
46 #include "oct-passwd.h"
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3504
diff changeset
47 #include "pathlen.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
48 #include "quit.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
49 #include "str-vec.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8327
diff changeset
50 #include "oct-locbuf.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
51
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
52 file_ops *file_ops::instance = 0;
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
53
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
54 bool
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
55 file_ops::instance_ok (void)
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
56 {
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
57 bool retval = true;
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
58
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
59 if (! instance)
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
60 {
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
61 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
62 char system_dir_sep_char = '\\';
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
63 std::string system_dir_sep_str = "\\";
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
64 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
65 char system_dir_sep_char = '/';
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
66 std::string system_dir_sep_str = "/";
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
67 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
68 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
69 std::string system_dir_sep_chars = "/\\";
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
70 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
71 std::string system_dir_sep_chars = system_dir_sep_str;
5138
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
72 #endif
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
73
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
74 instance = new file_ops (system_dir_sep_char, system_dir_sep_str,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
75 system_dir_sep_chars);
6271
6fab59e81b4e [project @ 2007-02-06 01:36:46 by jwe]
jwe
parents: 6208
diff changeset
76
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
77 if (! instance)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
78 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
79 (*current_liboctave_error_handler)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
80 ("unable to create file_ops object!");
5138
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
81
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
82 retval = false;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
83 }
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
84 }
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
85
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
86 return retval;
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
87 }
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
88
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
89 // The following tilde-expansion code was stolen and adapted from
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
90 // readline.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
91
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
92 // The default value of tilde_additional_prefixes. This is set to
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
93 // whitespace preceding a tilde so that simple programs which do not
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
94 // perform any word separation get desired behaviour.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
95 static const char *default_prefixes[] = { " ~", "\t~", ":~", 0 };
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
96
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
97 // The default value of tilde_additional_suffixes. This is set to
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
98 // whitespace or newline so that simple programs which do not perform
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
99 // any word separation get desired behaviour.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
100 static const char *default_suffixes[] = { " ", "\n", ":", 0 };
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
101
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
102 // If non-null, this contains the address of a function that the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
103 // application wants called before trying the standard tilde
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
104 // expansions. The function is called with the text sans tilde, and
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
105 // returns a malloc()'ed string which is the expansion, or a NULL
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
106 // pointer if the expansion fails.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
107 file_ops::tilde_expansion_hook file_ops::tilde_expansion_preexpansion_hook = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
108
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
109 // If non-null, this contains the address of a function to call if the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
110 // standard meaning for expanding a tilde fails. The function is
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
111 // called with the text (sans tilde, as in "foo"), and returns a
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
112 // malloc()'ed string which is the expansion, or a NULL pointer if
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
113 // there is no expansion.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
114 file_ops::tilde_expansion_hook file_ops::tilde_expansion_failure_hook = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
115
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
116 // When non-null, this is a NULL terminated array of strings which are
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
117 // duplicates for a tilde prefix. Bash uses this to expand `=~' and
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
118 // `:~'.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
119 string_vector file_ops::tilde_additional_prefixes = default_prefixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
120
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
121 // When non-null, this is a NULL terminated array of strings which
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
122 // match the end of a username, instead of just "/". Bash sets this
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
123 // to `:' and `=~'.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
124 string_vector file_ops::tilde_additional_suffixes = default_suffixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
125
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
126 // Find the start of a tilde expansion in S, and return the index
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
127 // of the tilde which starts the expansion. Place the length of the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
128 // text which identified this tilde starter in LEN, excluding the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
129 // tilde itself.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
130
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
131 static size_t
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
132 tilde_find_prefix (const std::string& s, size_t& len)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
133 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
134 len = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
135
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
136 size_t s_len = s.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
137
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
138 if (s_len == 0 || s[0] == '~')
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
139 return 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
140
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
141 string_vector prefixes = file_ops::tilde_additional_prefixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
142
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
143 if (! prefixes.empty ())
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
144 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
145 for (size_t i = 0; i < s_len; i++)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
146 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
147 for (int j = 0; j < prefixes.length (); j++)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
148 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
149 size_t pfx_len = prefixes[j].length ();
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
150
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
151 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
152 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
153 len = pfx_len - 1;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
154 return i + len;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
155 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
156 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
157 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
158 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
159
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
160 return s_len;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
161 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
162
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
163 // Find the end of a tilde expansion in S, and return the index
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
164 // of the character which ends the tilde definition.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
165
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
166 static size_t
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
167 tilde_find_suffix (const std::string& s)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
168 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
169 size_t s_len = s.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
170
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
171 string_vector suffixes = file_ops::tilde_additional_suffixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
172
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
173 size_t i = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
174
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
175 for ( ; i < s_len; i++)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
176 {
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
177 if (file_ops::is_dir_sep (s[i]))
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
178 break;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
179
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
180 if (! suffixes.empty ())
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
181 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
182 for (int j = 0; j < suffixes.length (); j++)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
183 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
184 size_t sfx_len = suffixes[j].length ();
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
185
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
186 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
187 return i;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
188 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
189 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
190 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
191
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
192 return i;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
193 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
194
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
195 // Take FNAME and return the tilde prefix we want expanded.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
196
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
197 static std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
198 isolate_tilde_prefix (const std::string& fname)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
199 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
200 size_t f_len = fname.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
201
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
202 size_t len = 1;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
203
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
204 while (len < f_len && ! file_ops::is_dir_sep (fname[len]))
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
205 len++;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
206
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
207 return fname.substr (1, len);
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
208 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
209
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
210 // Do the work of tilde expansion on FILENAME. FILENAME starts with a
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
211 // tilde.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
212
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
213 static std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
214 tilde_expand_word (const std::string& filename)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
215 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
216 size_t f_len = filename.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
217
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
218 if (f_len == 0 || filename[0] != '~')
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
219 return filename;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
220
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
221 // A leading `~/' or a bare `~' is *always* translated to the value
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
222 // of $HOME or the home directory of the current user, regardless of
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
223 // any preexpansion hook.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
224
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
225 if (f_len == 1 || file_ops::is_dir_sep (filename[1]))
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
226 return octave_env::get_home_directory () + filename.substr (1);
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
227
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
228 std::string username = isolate_tilde_prefix (filename);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
229
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
230 size_t user_len = username.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
231
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
232 std::string dirname;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
233
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
234 if (file_ops::tilde_expansion_preexpansion_hook)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
235 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
236 std::string expansion
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
237 = file_ops::tilde_expansion_preexpansion_hook (username);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
238
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
239 if (! expansion.empty ())
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
240 return expansion + filename.substr (user_len+1);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
241 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
242
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
243 // No preexpansion hook, or the preexpansion hook failed. Look in the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
244 // password database.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
245
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
246 octave_passwd pw = octave_passwd::getpwnam (username);
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
247
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
248 if (! pw)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
249 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
250 // If the calling program has a special syntax for expanding tildes,
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
251 // and we couldn't find a standard expansion, then let them try.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
252
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
253 if (file_ops::tilde_expansion_failure_hook)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
254 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
255 std::string expansion
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
256 = file_ops::tilde_expansion_failure_hook (username);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
257
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
258 if (! expansion.empty ())
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
259 dirname = expansion + filename.substr (user_len+1);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
260 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
261
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
262 // If we don't have a failure hook, or if the failure hook did not
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
263 // expand the tilde, return a copy of what we were passed.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
264
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
265 if (dirname.length () == 0)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
266 dirname = filename;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
267 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
268 else
3074
42975c59d2a0 [project @ 1997-07-24 19:33:35 by jwe]
jwe
parents: 3040
diff changeset
269 dirname = pw.dir () + filename.substr (user_len+1);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
270
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
271 return dirname;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
272 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
273
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
274 // If NAME has a leading ~ or ~user, Unix-style, expand it to the
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
275 // user's home directory. If no ~, or no <pwd.h>, just return NAME.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
276
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
277 std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
278 file_ops::tilde_expand (const std::string& name)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
279 {
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
280 if (name.find ('~') == std::string::npos)
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
281 return name;
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
282 else
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
283 {
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
284 std::string result;
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
285
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
286 size_t name_len = name.length ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
287
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
288 // Scan through S expanding tildes as we come to them.
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
289
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
290 size_t pos = 0;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
291
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
292 while (1)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
293 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
294 if (pos > name_len)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
295 break;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
296
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
297 size_t len;
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
298
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
299 // Make START point to the tilde which starts the expansion.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
300
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
301 size_t start = tilde_find_prefix (name.substr (pos), len);
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
302
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
303 result.append (name.substr (pos, start));
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
304
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
305 // Advance STRING to the starting tilde.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
306
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
307 pos += start;
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
308
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
309 // Make FINI be the index of one after the last character of the
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
310 // username.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
311
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
312 size_t fini = tilde_find_suffix (name.substr (pos));
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
313
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
314 // If both START and FINI are zero, we are all done.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
315
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
316 if (! (start || fini))
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
317 break;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
318
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
319 // Expand the entire tilde word, and copy it into RESULT.
2947
cf676ff8b702 [project @ 1997-05-09 13:32:46 by jwe]
jwe
parents: 2937
diff changeset
320
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
321 std::string tilde_word = name.substr (pos, fini);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
322
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
323 pos += fini;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
324
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
325 std::string expansion = tilde_expand_word (tilde_word);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
326
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
327 result.append (expansion);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
328 }
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
329
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
330 return result;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
331 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
332 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
333
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
334 // A vector version of the above.
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
335
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
336 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
337 file_ops::tilde_expand (const string_vector& names)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
338 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
339 string_vector retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
340
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
341 int n = names.length ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
342
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
343 retval.resize (n);
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
344
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
345 for (int i = 0; i < n; i++)
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
346 retval[i] = tilde_expand (names[i]);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
347
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
348 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
349 }
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
350
7272
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
351 std::string
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
352 file_ops::concat (const std::string& dir, const std::string& file)
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
353 {
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
354 return dir.empty ()
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
355 ? file
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
356 : (is_dir_sep (dir[dir.length()-1])
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
357 ? dir + file
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
358 : dir + dir_sep_char () + file);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
359 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
360
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
361
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
362 std::string
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
363 file_ops::canonicalize_file_name (const std::string& name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
364 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
365 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
366 return canonicalize_file_name (name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
367 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
368
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
369 std::string
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
370 file_ops::canonicalize_file_name (const std::string& name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
371 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
372 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
373
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
374 std::string retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
375
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
376 #if defined (HAVE_CANONICALIZE_FILE_NAME)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
377
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
378 char *tmp = ::canonicalize_file_name (name.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
379
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
380 if (tmp)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
381 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
382 retval = tmp;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
383 free (tmp);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
384 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
385
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
386 #elif defined (HAVE_RESOLVEPATH)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
387
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
388 #if !defined (errno)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
389 extern int errno;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
390 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
391
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
392 #if !defined (__set_errno)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
393 # define __set_errno(Val) errno = (Val)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
394 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
395
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
396 if (name.empty ())
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
397 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
398 __set_errno (ENOENT);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
399 return retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
400 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
401
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
402 // All known hosts with resolvepath (e.g. Solaris 7) don't turn
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
403 // relative names into absolute ones, so prepend the working
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
404 // directory if the path is not absolute.
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
405
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
406 std::string absolute_name
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
407 = octave_env::make_absolute (name, octave_env::getcwd ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
408
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
409 size_t resolved_size = absolute_name.length ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
410
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
411 while (true)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
412 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
413 resolved_size = 2 * resolved_size + 1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
414
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
415 OCTAVE_LOCAL_BUFFER (char, resolved, resolved_size);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
416
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
417 int resolved_len
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
418 = resolvepath (absolute_name.c_str (), resolved, resolved_size);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
419
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
420 if (resolved_len < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
421 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
422
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
423 if (resolved_len < resolved_size)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
424 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
425 retval = resolved;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
426 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
427 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
428 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
429
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
430 #elif defined (__WIN32__)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
431
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
432 int n = 1024;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
433
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
434 std::string win_path (n, '\0');
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
435
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
436 while (true)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
437 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
438 int status = GetFullPathName (name.c_str (), n, &win_path[0], 0);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
439
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
440 if (status == 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
441 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
442 else if (status < n)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
443 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
444 win_path.resize (status);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
445 retval = win_path;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
446 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
447 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
448 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
449 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
450 n *= 2;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
451 win_path.resize (n);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
452 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
453 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
454
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
455 #elif defined (HAVE_REALPATH)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
456
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
457 #if !defined (__set_errno)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
458 # define __set_errno(Val) errno = (Val)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
459 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
460
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
461 if (name.empty ())
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
462 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
463 __set_errno (ENOENT);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
464 return retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
465 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
466
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
467 OCTAVE_LOCAL_BUFFER (char, buf, PATH_MAX);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
468
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
469 if (::realpath (name.c_str (), buf))
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
470 retval = buf;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
471
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
472 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
473
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
474 // FIXME -- provide replacement here...
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
475 retval = name;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
476
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
477 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
478
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
479 if (retval.empty ())
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
480 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
481 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
482 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
483 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
484
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
485 return retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
486 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
487
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
488 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
489 octave_mkdir (const std::string& nm, mode_t md)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
490 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
491 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
492 return octave_mkdir (nm, md, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
493 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
494
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
495 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
496 octave_mkdir (const std::string& name, mode_t mode, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
497 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
498 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
499
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
500 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
501
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
502 status = mkdir (name.c_str (), mode);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
503
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
504 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
505 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
506 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
507 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
508 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
509
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
510 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
511 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
512
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
513 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
514 octave_mkfifo (const std::string& nm, mode_t md)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
515 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
516 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
517 return octave_mkfifo (nm, md, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
518 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
519
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
520 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
521 octave_mkfifo (const std::string& name, mode_t mode, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
522 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
523 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
524
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
525 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
526
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
527 // With gnulib we will always have mkfifo, but some systems like MinGW
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
528 // don't have working mkfifo functions. On those systems, mkfifo will
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
529 // always return -1 and set errno.
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
530
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
531 status = mkfifo (name.c_str (), mode);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
532
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
533 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
534 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
535 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
536 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
537 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
538
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
539 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
540 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
541
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
542 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
543 octave_link (const std::string& old_name, const std::string& new_name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
544 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
545 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
546 return octave_link (old_name, new_name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
547 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
548
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
549 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
550 octave_link (const std::string& old_name,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
551 const std::string& new_name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
552 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
553 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
554
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
555 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
556
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
557 status = link (old_name.c_str (), new_name.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
558
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
559 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
560 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
561 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
562 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
563 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
564
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
565 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
566 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
567
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
568 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
569 octave_symlink (const std::string& old_name, const std::string& new_name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
570 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
571 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
572 return octave_symlink (old_name, new_name, msg);
7272
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
573 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
574
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
575 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
576 octave_symlink (const std::string& old_name,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
577 const std::string& new_name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
578 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
579 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
580
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
581 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
582
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
583 status = symlink (old_name.c_str (), new_name.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
584
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
585 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
586 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
587 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
588 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
589 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
590
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
591 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
592 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
593
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
594 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
595 octave_readlink (const std::string& path, std::string& result)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
596 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
597 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
598 return octave_readlink (path, result, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
599 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
600
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
601 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
602 octave_readlink (const std::string& path, std::string& result,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
603 std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
604 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
605 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
606
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
607 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
608
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
609 char buf[MAXPATHLEN+1];
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
610
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
611 status = readlink (path.c_str (), buf, MAXPATHLEN);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
612
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
613 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
614 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
615 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
616 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
617 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
618 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
619 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
620 buf[status] = '\0';
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
621 result = std::string (buf);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
622 status = 0;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
623 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
624
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
625 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
626 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
627
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
628 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
629 octave_rename (const std::string& from, const std::string& to)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
630 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
631 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
632 return octave_rename (from, to, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
633 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
634
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
635 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
636 octave_rename (const std::string& from, const std::string& to,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
637 std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
638 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
639 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
640
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
641 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
642
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
643 status = rename (from.c_str (), to.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
644
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
645 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
646 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
647 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
648 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
649 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
650
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
651 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
652 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
653
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
654 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
655 octave_rmdir (const std::string& name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
656 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
657 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
658 return octave_rmdir (name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
659 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
660
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
661 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
662 octave_rmdir (const std::string& name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
663 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
664 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
665
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
666 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
667
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
668 status = rmdir (name.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
669
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
670 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
671 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
672 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
673 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
674 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
675
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
676 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
677 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
678
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
679 // And a version that works recursively.
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
680
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
681 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
682 octave_recursive_rmdir (const std::string& name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
683 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
684 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
685 return octave_recursive_rmdir (name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
686 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
687
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
688 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
689 octave_recursive_rmdir (const std::string& name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
690 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
691 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
692
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
693 int status = 0;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
694
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
695 dir_entry dir (name);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
696
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
697 if (dir)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
698 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
699 string_vector dirlist = dir.read ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
700
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
701 for (octave_idx_type i = 0; i < dirlist.length (); i++)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
702 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
703 octave_quit ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
704
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
705 std::string nm = dirlist[i];
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
706
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
707 // Skip current directory and parent.
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
708 if (nm == "." || nm == "..")
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
709 continue;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
710
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
711 std::string fullnm = name + file_ops::dir_sep_str () + nm;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
712
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
713 // Get info about the file. Don't follow links.
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
714 file_stat fs (fullnm, false);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
715
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
716 if (fs)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
717 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
718 if (fs.is_dir ())
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
719 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
720 status = octave_recursive_rmdir (fullnm, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
721
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
722 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
723 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
724 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
725 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
726 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
727 status = octave_unlink (fullnm, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
728
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
729 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
730 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
731 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
732 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
733 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
734 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
735 msg = fs.error ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
736 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
737 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
738 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
739
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
740 if (status >= 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
741 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
742 dir.close ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
743 status = octave_rmdir (name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
744 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
745 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
746 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
747 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
748 status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
749
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
750 msg = dir.error ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
751 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
752
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
753 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
754 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
755
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
756 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
757 octave_umask (mode_t mode)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
758 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
759 #if defined (HAVE_UMASK)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
760 return umask (mode);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
761 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
762 return 0;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
763 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
764 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
765
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
766 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
767 octave_unlink (const std::string& name)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
768 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
769 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
770 return octave_unlink (name, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
771 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
772
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
773 OCTAVE_API int
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
774 octave_unlink (const std::string& name, std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
775 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
776 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
777
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
778 int status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
779
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
780 status = unlink (name.c_str ());
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
781
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
782 if (status < 0)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
783 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
784 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
785 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
786 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
787
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
788 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
789 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
790
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
791 OCTAVE_API std::string
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
792 octave_tempnam (const std::string& dir, const std::string& pfx)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
793 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
794 std::string msg;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
795 return octave_tempnam (dir, pfx, msg);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
796 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
797
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
798 OCTAVE_API std::string
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
799 octave_tempnam (const std::string& dir, const std::string& pfx,
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
800 std::string& msg)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
801 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
802 msg = std::string ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
803
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
804 std::string retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
805
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
806 const char *pdir = dir.empty () ? 0 : dir.c_str ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
807
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
808 const char *ppfx = pfx.empty () ? 0 : pfx.c_str ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
809
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
810 char *tmp = tempnam (pdir, ppfx);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
811
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
812 if (tmp)
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
813 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
814 retval = tmp;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
815
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
816 free (tmp);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
817 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
818 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
819 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
820 using namespace std;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
821 msg = strerror (errno);
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
822 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
823
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
824 return retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
825 }