annotate liboctave/system/file-ops.cc @ 19631:db92e7e28e1f

strip trailing whitespace from most source files * NEWS, doc/interpreter/contributors.in, doc/interpreter/func.txi, doc/interpreter/genpropdoc.m, doc/interpreter/octave_logo.eps, doc/interpreter/plot.txi, doc/interpreter/stmt.txi, examples/data/Makefile.am, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/load-path.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/variables.cc, libinterp/octave-value/ov-classdef.cc, libinterp/octave-value/ov-classdef.h, libinterp/octave.cc, libinterp/parse-tree/lex.h, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/pt-classdef.h, liboctave/system/file-ops.cc, liboctave/system/oct-env.cc, m4/acinclude.m4, scripts/deprecated/finite.m, scripts/deprecated/fmod.m, scripts/deprecated/fnmatch.m, scripts/deprecated/luinc.m, scripts/deprecated/octave_tmp_file_name.m, scripts/deprecated/syl.m, scripts/deprecated/usage.m, scripts/general/inputParser.m, scripts/general/interp1.m, scripts/general/interp2.m, scripts/general/interp3.m, scripts/general/isequal.m, scripts/general/private/__isequal__.m, scripts/geometry/voronoi.m, scripts/image/image.m, scripts/image/imshow.m, scripts/image/ind2rgb.m, scripts/linear-algebra/bandwidth.m, scripts/linear-algebra/isbanded.m, scripts/miscellaneous/bzip2.m, scripts/miscellaneous/cast.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/delete.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/getappdata.m, scripts/miscellaneous/gunzip.m, scripts/miscellaneous/isappdata.m, scripts/miscellaneous/ls.m, scripts/miscellaneous/mex.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/orderfields.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/setfield.m, scripts/miscellaneous/symvar.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/ver.m, scripts/miscellaneous/what.m, scripts/miscellaneous/xor.m, scripts/miscellaneous/zip.m, scripts/optimization/fminbnd.m, scripts/optimization/sqp.m, scripts/path/private/getsavepath.m, scripts/path/savepath.m, scripts/pkg/pkg.m, scripts/pkg/private/installed_packages.m, scripts/plot/draw/plotyy.m, scripts/plot/draw/polar.m, scripts/plot/draw/private/__quiver__.m, scripts/plot/draw/private/__scatter__.m, scripts/plot/draw/private/__stem__.m, scripts/plot/draw/surface.m, scripts/plot/draw/surfnorm.m, scripts/plot/util/copyobj.m, scripts/plot/util/hgload.m, scripts/plot/util/hgsave.m, scripts/plot/util/isprop.m, scripts/plot/util/linkprop.m, scripts/plot/util/private/__go_draw_axes__.m, scripts/set/setdiff.m, scripts/set/union.m, scripts/signal/periodogram.m, scripts/sparse/eigs.m, scripts/sparse/ilu.m, scripts/sparse/qmr.m, scripts/sparse/sprand.m, scripts/sparse/sprandn.m, scripts/specfun/beta.m, scripts/specfun/ellipke.m, scripts/specfun/isprime.m, scripts/statistics/base/lscov.m, scripts/testfun/__run_test_suite__.m, scripts/testfun/test.m: Strip trailing whitespace.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Jan 2015 10:29:54 -0500
parents d8fd3842a507
children 4197fc428c7d
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
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 15467
diff changeset
3 Copyright (C) 1996-2013 John W. Eaton
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
4
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
6
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
7 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
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
10 option) any later version.
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
11
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
14 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
15 for more details.
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
16
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6709
diff changeset
19 <http://www.gnu.org/licenses/>.
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
20
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 #ifdef HAVE_CONFIG_H
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
25 #endif
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
26
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
27 #include <cerrno>
10463
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
28 #include <cstdio>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
29 #include <cstdlib>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
30 #include <cstring>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
31
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3074
diff changeset
32 #include <iostream>
4726
14dc2267c343 [project @ 2004-01-23 20:04:35 by jwe]
jwe
parents: 4578
diff changeset
33 #include <vector>
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
34
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
35 #include <sys/stat.h>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
36 #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
37 #include <unistd.h>
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
38
10279
323c9cbbd02a fix gnulib includes
John W. Eaton <jwe@octave.org>
parents: 10252
diff changeset
39 #include "pathmax.h"
15409
c898dbe14e1d build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents: 15271
diff changeset
40 #include "canonicalize.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
41
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
42 extern "C" {
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
43 #include <tempname.h>
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
44 }
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
45
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
46 #include "dir-ops.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
47 #include "file-ops.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
48 #include "file-stat.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
49 #include "oct-env.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
50 #include "oct-locbuf.h"
2934
dddc1b5c324e [project @ 1997-05-05 22:56:37 by jwe]
jwe
parents: 2926
diff changeset
51 #include "oct-passwd.h"
3710
9a77deefb8c9 [project @ 2000-08-02 20:47:44 by jwe]
jwe
parents: 3504
diff changeset
52 #include "pathlen.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
53 #include "quit.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
54 #include "singleton-cleanup.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
55 #include "str-vec.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
56
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
57 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
58
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
59 bool
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
60 file_ops::instance_ok (void)
8007
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
61 {
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
62 bool retval = true;
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
63
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
64 if (! instance)
a2ab20ba78f7 make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
65 {
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
66 #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
67 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
68 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
69 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
70 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
71 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
72 #endif
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
73 #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
74 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
75 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
76 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
77 #endif
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
78
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
79 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
80 system_dir_sep_chars);
6271
6fab59e81b4e [project @ 2007-02-06 01:36:46 by jwe]
jwe
parents: 6208
diff changeset
81
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
82 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
83 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
84 }
5138
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
85
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
86 if (! instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
87 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
88 (*current_liboctave_error_handler)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
89 ("unable to create file_ops object!");
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
90
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
91 retval = false;
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
92 }
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
93
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
94 return retval;
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
95 }
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
96
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
97 // 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
98 // readline.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
99
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
100 // 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
101 // 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
102 // perform any word separation get desired behaviour.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
103 static const char *default_prefixes[] = { " ~", "\t~", ":~", 0 };
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
104
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
105 // 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
106 // 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
107 // any word separation get desired behaviour.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
108 static const char *default_suffixes[] = { " ", "\n", ":", 0 };
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
109
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
110 // 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
111 // application wants called before trying the standard tilde
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
112 // 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
113 // 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
114 // pointer if the expansion fails.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
115 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
116
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
117 // 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
118 // 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
119 // 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
120 // 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
121 // there is no expansion.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
122 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
123
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
124 // When non-null, this is a NULL terminated array of strings which are
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
125 // duplicates for a tilde prefix. Bash uses this to expand '=~' and
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
126 // ':~'.
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
127 string_vector file_ops::tilde_additional_prefixes = default_prefixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
128
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
129 // 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
130 // match the end of a username, instead of just "/". Bash sets this
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
131 // to ':' and '=~'.
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
132 string_vector file_ops::tilde_additional_suffixes = default_suffixes;
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 // 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
135 // 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
136 // 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
137 // tilde itself.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
138
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
139 static size_t
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
140 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
141 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
142 len = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
143
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
144 size_t s_len = s.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
145
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
146 if (s_len == 0 || s[0] == '~')
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
147 return 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
148
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
149 string_vector prefixes = file_ops::tilde_additional_prefixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
150
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
151 if (! prefixes.empty ())
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
152 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
153 for (size_t i = 0; i < s_len; i++)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
154 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
155 for (int j = 0; j < prefixes.length (); j++)
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 size_t pfx_len = prefixes[j].length ();
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
158
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
159 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
160 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
161 len = pfx_len - 1;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
162 return i + len;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
163 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
164 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
165 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
166 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
167
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
168 return s_len;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
169 }
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 // 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
172 // of the character which ends the tilde definition.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
173
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
174 static size_t
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
175 tilde_find_suffix (const std::string& s)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
176 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
177 size_t s_len = s.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
178
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
179 string_vector suffixes = file_ops::tilde_additional_suffixes;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
180
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
181 size_t i = 0;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
182
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
183 for ( ; i < s_len; i++)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
184 {
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
185 if (file_ops::is_dir_sep (s[i]))
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
186 break;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
187
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
188 if (! suffixes.empty ())
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
189 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
190 for (int j = 0; j < suffixes.length (); j++)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
191 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
192 size_t sfx_len = suffixes[j].length ();
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
193
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
194 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
195 return i;
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
196 }
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
197 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
198 }
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 return i;
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
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
203 // 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
204
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
205 static std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
206 isolate_tilde_prefix (const std::string& fname)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
207 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
208 size_t f_len = fname.length ();
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 size_t len = 1;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
211
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
212 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
213 len++;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
214
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
215 return fname.substr (1, len);
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
216 }
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 // 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
219 // tilde.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
220
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
221 static std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
222 tilde_expand_word (const std::string& filename)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
223 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
224 size_t f_len = filename.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
225
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
226 if (f_len == 0 || filename[0] != '~')
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
227 return filename;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
228
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
229 // A leading '~/' or a bare '~' is *always* translated to the value
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
230 // 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
231 // any preexpansion hook.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
232
6694
3d913ba36b75 [project @ 2007-06-06 06:08:25 by jwe]
jwe
parents: 6363
diff changeset
233 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
234 return octave_env::get_home_directory () + filename.substr (1);
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 username = isolate_tilde_prefix (filename);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
237
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
238 size_t user_len = username.length ();
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
239
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
240 std::string dirname;
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 if (file_ops::tilde_expansion_preexpansion_hook)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
243 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
244 std::string expansion
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
245 = file_ops::tilde_expansion_preexpansion_hook (username);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
246
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
247 if (! expansion.empty ())
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
248 return expansion + filename.substr (user_len+1);
3040
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
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
251 // 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
252 // password database.
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
253
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
254 octave_passwd pw = octave_passwd::getpwnam (username);
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
255
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
256 if (! pw)
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
257 {
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
258 // 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
259 // 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
260
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
261 if (file_ops::tilde_expansion_failure_hook)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
262 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
263 std::string expansion
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
264 = file_ops::tilde_expansion_failure_hook (username);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
265
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
266 if (! expansion.empty ())
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
267 dirname = expansion + filename.substr (user_len+1);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
268 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
269
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
270 // 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
271 // 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
272
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
273 if (dirname.length () == 0)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
274 dirname = filename;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
275 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
276 else
3074
42975c59d2a0 [project @ 1997-07-24 19:33:35 by jwe]
jwe
parents: 3040
diff changeset
277 dirname = pw.dir () + filename.substr (user_len+1);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
278
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
279 return dirname;
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
280 }
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
281
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
282 // 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
283 // 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
284
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
285 std::string
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
286 file_ops::tilde_expand (const std::string& name)
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 if (name.find ('~') == std::string::npos)
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
289 return name;
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
290 else
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 std::string result;
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
293
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
294 size_t name_len = name.length ();
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
295
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
296 // 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
297
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
298 size_t pos = 0;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
299
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
300 while (1)
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
301 {
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
302 if (pos > name_len)
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
303 break;
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 size_t len;
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
306
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
307 // 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
308
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
309 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
310
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
311 result.append (name.substr (pos, start));
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
312
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
313 // Advance STRING to the starting tilde.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
314
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
315 pos += start;
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
316
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
317 // 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
318 // username.
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
319
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
320 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
321
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
322 // 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
323
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
324 if (! (start || fini))
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
325 break;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
326
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
327 // 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
328
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
329 std::string tilde_word = name.substr (pos, fini);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
330
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
331 pos += fini;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
332
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
333 std::string expansion = tilde_expand_word (tilde_word);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
334
10180
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
335 result.append (expansion);
be952ce74023 bootstrap.conf fixes
John W. Eaton <jwe@octave.org>
parents: 10179
diff changeset
336 }
8327
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
337
4a7a943581d0 Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents: 8009
diff changeset
338 return result;
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
339 }
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
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
342 // A vector version of the above.
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
343
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
344 string_vector
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
345 file_ops::tilde_expand (const string_vector& names)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
346 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
347 string_vector retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
348
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
349 int n = names.length ();
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
350
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
351 retval.resize (n);
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
352
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
353 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
354 retval[i] = tilde_expand (names[i]);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
355
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
356 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
357 }
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
358
7272
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
359 std::string
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
360 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
361 {
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
362 return dir.empty ()
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
363 ? file
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
364 : (is_dir_sep (dir[dir.length ()-1])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
365 ? dir + file
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
366 : dir + dir_sep_char () + file);
10197
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
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
369 std::string
18412
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
370 file_ops::native_separator_path (const std::string& path)
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
371 {
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
372 std::string retval;
18412
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
373
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
374 if (dir_sep_char () == '/')
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
375 retval = path;
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
376 else
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
377 {
18412
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
378 size_t n = path.length ();
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
379 for (size_t i = 0; i < n; i++)
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
380 {
18412
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
381 if (path[i] == '/')
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
382 retval += dir_sep_char();
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
383 else
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
384 retval += path[i];
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
385 }
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
386 }
18412
f74c6aaa6d0f Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents: 18410
diff changeset
387
18410
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
388 return retval;
073fbe7e6a3a Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents: 18066
diff changeset
389 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
390
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
391 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
392 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
393 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
394 std::string msg;
14741
0ab3dd0fad18 Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents: 14679
diff changeset
395 return octave_mkdir (nm, md, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
396 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
397
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
398 int
14741
0ab3dd0fad18 Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents: 14679
diff changeset
399 octave_mkdir (const std::string& name, mode_t mode, std::string& msg)
10197
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 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
402
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
403 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
404
14741
0ab3dd0fad18 Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents: 14679
diff changeset
405 status = gnulib::mkdir (name.c_str (), mode);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
406
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
407 if (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
408 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
409
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
410 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
411 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
412
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
413 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
414 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
415 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
416 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
417 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
418 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
419
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
420 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
421 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
422 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
423 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
424
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
425 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
426
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
427 // 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
428 // 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
429 // 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
430
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
431 status = gnulib::mkfifo (name.c_str (), mode);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
432
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
433 if (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
434 msg = gnulib::strerror (errno);
10197
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 return status;
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
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
439 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
440 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
441 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
442 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
443 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
444 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
445
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
446 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
447 octave_link (const std::string& old_name,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
448 const std::string& new_name, std::string& msg)
10197
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 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
451
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
452 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
453
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
454 status = gnulib::link (old_name.c_str (), new_name.c_str ());
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
455
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
456 if (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
457 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
458
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
459 return status;
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
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
462 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
463 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
464 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
465 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
466 return octave_symlink (old_name, new_name, msg);
7272
05ee52d7fad6 [project @ 2007-12-10 07:06:00 by jwe]
jwe
parents: 7017
diff changeset
467 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
468
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
469 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
470 octave_symlink (const std::string& old_name,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
471 const std::string& new_name, std::string& msg)
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
472 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
473 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
474
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
475 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
476
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
477 status = gnulib::symlink (old_name.c_str (), new_name.c_str ());
10197
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 (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
480 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
481
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
482 return status;
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
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
485 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
486 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
487 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
488 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
489 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
490 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
491
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
492 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
493 octave_readlink (const std::string& path, std::string& result,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
494 std::string& msg)
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
495 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
496 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
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 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
501
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
502 status = gnulib::readlink (path.c_str (), buf, MAXPATHLEN);
10197
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)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
505 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
506 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
507 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
508 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
509 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
510 status = 0;
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 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
514 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
515
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
516 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
517 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
518 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
519 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
520 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
521 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
522
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
523 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
524 octave_rename (const std::string& from, const std::string& to,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
525 std::string& msg)
10197
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 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
528
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
529 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
530
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
531 status = gnulib::rename (from.c_str (), to.c_str ());
10197
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)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
534 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
535
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
536 return status;
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
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
539 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
540 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
541 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
542 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
543 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
544 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
545
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
546 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
547 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
548 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
549 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
550
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
551 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
552
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
553 status = gnulib::rmdir (name.c_str ());
10197
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 if (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
556 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
557
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
558 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
559 }
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 // 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
562
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
563 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
564 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
565 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
566 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
567 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
568 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
569
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
570 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
571 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
572 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
573 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
574
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
575 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
576
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
577 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
578
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
579 if (dir)
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 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
582
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
583 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
584 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
585 octave_quit ();
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 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
588
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
589 // 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
590 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
591 continue;
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 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
594
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
595 // 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
596 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
597
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
598 if (fs)
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 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
601 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
602 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
603
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
604 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
605 break;
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 else
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 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
610
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
611 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
612 break;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
613 }
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 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
616 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
617 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
618 break;
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 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
621
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
622 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
623 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
624 dir.close ();
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
625 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
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 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
629 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
630 status = -1;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
631
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
632 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
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 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
636 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
637
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
638 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
639 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
640 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
641 #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
642 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
643 #else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
644 return 0;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
645 #endif
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
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
648 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
649 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
650 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
651 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
652 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
653 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
654
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
655 int
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
656 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
657 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
658 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
659
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
660 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
661
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
662 status = gnulib::unlink (name.c_str ());
10197
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 if (status < 0)
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
665 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
666
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
667 return status;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
668 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
669
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
670 std::string
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
671 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
672 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
673 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
674 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
675 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
676
10198
025564630c8d file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents: 10197
diff changeset
677 std::string
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
678 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
679 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
680 {
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
681 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
682
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
683 std::string retval;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
684
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
685 // get dir path to use for template
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
686 std::string templatename;
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
687 if (dir.empty ())
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
688 templatename = octave_env::get_temp_directory ();
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
689 else if (! file_stat (dir, false).is_dir ())
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
690 templatename = octave_env::get_temp_directory ();
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
691 else
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
692 templatename = dir;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
693
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
694 // add dir sep char if it is not there
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
695 if (*templatename.rbegin () != file_ops::dir_sep_char ())
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
696 templatename += file_ops::dir_sep_char ();
19454
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 18412
diff changeset
697
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
698 if (pfx.empty ())
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
699 templatename += "file";
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
700 else
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
701 templatename += pfx;
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
702
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
703 // add the required XXXXXX for the template
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
704 templatename += "XXXXXX";
19462
eee9f111c164 Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents: 19454
diff changeset
705
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
706 // create and copy template to char array for call to gen_tempname
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
707 char tname [templatename.length () + 1];
19462
eee9f111c164 Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents: 19454
diff changeset
708
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
709 strcpy (tname, templatename.c_str ());
19462
eee9f111c164 Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents: 19454
diff changeset
710
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
711 if (gen_tempname (tname, 0, 0, GT_NOCREATE) == -1)
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
712 msg = gnulib::strerror (errno);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
713 else
19492
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19462
diff changeset
714 retval = tname;
19631
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19492
diff changeset
715
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
716 return retval;
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
717 }
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
718
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
719 std::string
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
720 octave_canonicalize_file_name (const std::string& name)
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
721 {
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
722 std::string msg;
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
723 return octave_canonicalize_file_name (name, msg);
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
724 }
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
725
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
726 std::string
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
727 octave_canonicalize_file_name (const std::string& name, std::string& msg)
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
728 {
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
729 msg = std::string ();
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
730
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
731 std::string retval;
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
732
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
733 char *tmp = gnulib::canonicalize_file_name (name.c_str ());
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
734
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
735 if (tmp)
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
736 {
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
737 retval = tmp;
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
738 free (tmp);
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
739 }
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
740
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
741 if (retval.empty ())
10411
479cc8a0a846 use gnulib namespace
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
742 msg = gnulib::strerror (errno);
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
743
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
744 return retval;
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
745 }
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
746