annotate liboctave/system/file-ops.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents 6a5e4ef80a95
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30394
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21308
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 # include "config.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
28 #endif
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
29
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
30 #include <cerrno>
10463
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
31 #include <cstdio>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
32 #include <cstdlib>
bbe99b2a5ba7 undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents: 10447
diff changeset
33 #include <cstring>
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
34
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
35 #include <vector>
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
36
27496
def608acdfa9 Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27102
diff changeset
37 #if defined (OCTAVE_USE_WINDOWS_API)
31097
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
38 # include <cctype>
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
39
27496
def608acdfa9 Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27102
diff changeset
40 # include <windows.h>
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
41 # include "unwind-prot.h"
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
42 #else
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
43 # include "canonicalize-file-name-wrapper.h"
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
44 #endif
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
45
21896
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
46 #include "areadlink-wrapper.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
47 #include "dir-ops.h"
1765
a51354c34bea [project @ 1996-01-23 03:33:34 by jwe]
jwe
parents:
diff changeset
48 #include "file-ops.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
49 #include "file-stat.h"
21896
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
50 #include "gen-tempname-wrapper.h"
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25438
diff changeset
51 #include "lo-sysdep.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
52 #include "oct-env.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
53 #include "oct-locbuf.h"
30072
96a40641d86e maint: rename liboctave oct-passwd.* to oct-password.* to match class name.
Rik <rik@octave.org>
parents: 29950
diff changeset
54 #include "oct-password.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5307
diff changeset
55 #include "quit.h"
21909
d7cac41df82a provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents: 21896
diff changeset
56 #include "stat-wrappers.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
57 #include "str-vec.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21909
diff changeset
58 #include "unistd-wrappers.h"
20503
0829b6ff3ac9 Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents: 19697
diff changeset
59
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
60 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
61
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
62 // The following tilde-expansion code was stolen and adapted from
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
63 // readline.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
64
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
65 // The default value of tilde_additional_prefixes. This is set to
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
66 // whitespace preceding a tilde so that simple programs which do not
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
67 // perform any word separation get desired behavior.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
68 static const char *default_prefixes[] = { " ~", "\t~", ":~", nullptr };
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
69
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
70 // The default value of tilde_additional_suffixes. This is set to
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
71 // whitespace or newline so that simple programs which do not perform
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
72 // any word separation get desired behavior.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
73 static const char *default_suffixes[] = { " ", "\n", ":", nullptr };
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
74
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
75 static std::size_t
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
76 tilde_find_prefix (const std::string& s, std::size_t& len)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
77 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
78 len = 0;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
79
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
80 std::size_t s_len = s.length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
81
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
82 if (s_len == 0 || s[0] == '~')
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
83 return 0;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
84
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
85 string_vector prefixes = sys::file_ops::tilde_additional_prefixes;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
86
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
87 if (! prefixes.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
88 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
89 for (std::size_t i = 0; i < s_len; i++)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
90 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
91 for (int j = 0; j < prefixes.numel (); j++)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
92 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
93 std::size_t pfx_len = prefixes[j].length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
94
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
95 if (prefixes[j] == s.substr (i, pfx_len))
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
96 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
97 len = pfx_len - 1;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
98 return i + len;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
99 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
100 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
101 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
102 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
103
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
104 return s_len;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
105 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
106
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
107 // Find the end of a tilde expansion in S, and return the index
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
108 // of the character which ends the tilde definition.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
109
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
110 static std::size_t
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
111 tilde_find_suffix (const std::string& s)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
112 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
113 std::size_t s_len = s.length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
114
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
115 string_vector suffixes = sys::file_ops::tilde_additional_suffixes;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
116
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
117 std::size_t i = 0;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
118
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
119 for ( ; i < s_len; i++)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
120 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
121 if (sys::file_ops::is_dir_sep (s[i]))
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
122 break;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
123
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
124 if (! suffixes.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
125 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
126 for (int j = 0; j < suffixes.numel (); j++)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
127 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
128 std::size_t sfx_len = suffixes[j].length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
129
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
130 if (suffixes[j] == s.substr (i, sfx_len))
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
131 return i;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
132 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
133 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
134 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
135
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
136 return i;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
137 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
138
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
139 // Take FNAME and return the tilde prefix we want expanded.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
140
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
141 static std::string
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
142 isolate_tilde_prefix (const std::string& fname)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
143 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
144 std::size_t f_len = fname.length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
145
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
146 std::size_t len = 1;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
147
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
148 while (len < f_len && ! sys::file_ops::is_dir_sep (fname[len]))
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
149 len++;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
150
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
151 return fname.substr (1, len);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
152 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
153
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
154 // Do the work of tilde expansion on FILENAME. FILENAME starts with a
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
155 // tilde.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
156
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
157 static std::string
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
158 tilde_expand_word (const std::string& filename)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
159 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
160 std::size_t f_len = filename.length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
161
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
162 if (f_len == 0 || filename[0] != '~')
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
163 return std::string (filename);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
164
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
165 // A leading '~/' or a bare '~' is *always* translated to the value
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
166 // of $HOME or the home directory of the current user, regardless of
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
167 // any preexpansion hook.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
168
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
169 if (f_len == 1 || sys::file_ops::is_dir_sep (filename[1]))
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
170 return sys::env::get_home_directory () + filename.substr (1);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
171
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
172 std::string username = isolate_tilde_prefix (filename);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
173
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
174 std::size_t user_len = username.length ();
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
175
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
176 std::string dirname;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
177
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
178 if (sys::file_ops::tilde_expansion_preexpansion_hook)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
179 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
180 std::string expansion
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
181 = sys::file_ops::tilde_expansion_preexpansion_hook (username);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
182
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
183 if (! expansion.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
184 return expansion + filename.substr (user_len+1);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
185 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
186
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
187 // No preexpansion hook, or the preexpansion hook failed. Look in the
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
188 // password database.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
189
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
190 sys::password pw = sys::password::getpwnam (username);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
191
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
192 if (! pw)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
193 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
194 // If the calling program has a special syntax for expanding tildes,
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
195 // and we couldn't find a standard expansion, then let them try.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
196
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
197 if (sys::file_ops::tilde_expansion_failure_hook)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
198 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
199 std::string expansion
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
200 = sys::file_ops::tilde_expansion_failure_hook (username);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
201
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
202 if (! expansion.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
203 dirname = expansion + filename.substr (user_len+1);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
204 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
205
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
206 // If we don't have a failure hook, or if the failure hook did not
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
207 // expand the tilde, return a copy of what we were passed.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
208
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
209 if (dirname.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
210 dirname = filename;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
211 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
212 else
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
213 dirname = pw.dir () + filename.substr (user_len+1);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
214
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
215 return dirname;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
216 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
217
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
218 OCTAVE_BEGIN_NAMESPACE(sys)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
219
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
220 OCTAVE_BEGIN_NAMESPACE(file_ops)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
221
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
222 char dev_sep_char (void)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
223 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
224 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
225 return ':';
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
226 #else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
227 return 0;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
228 #endif
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
229 }
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
230
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
231 char dir_sep_char (void)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
232 {
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
233 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
234 return '\\';
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
235 #else
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
236 return '/';
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
237 #endif
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
238 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
239
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
240 std::string dir_sep_str (void)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
241 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
242 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23795
diff changeset
243 return R"(\)";
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
244 #else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
245 return "/";
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
246 #endif
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
247 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
248
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
249 std::string dir_sep_chars (void)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
250 {
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
251 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23795
diff changeset
252 return R"(/\)";
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
253 #else
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
254 return dir_sep_str ();
5138
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
255 #endif
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
256 }
6271
6fab59e81b4e [project @ 2007-02-06 01:36:46 by jwe]
jwe
parents: 6208
diff changeset
257
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23744
diff changeset
258 tilde_expansion_hook tilde_expansion_preexpansion_hook = nullptr;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
259
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23744
diff changeset
260 tilde_expansion_hook tilde_expansion_failure_hook = nullptr;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
261
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
262 string_vector tilde_additional_prefixes = default_prefixes;
5138
5fa9670b5956 [project @ 2005-02-09 23:13:03 by jwe]
jwe
parents: 4726
diff changeset
263
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
264 string_vector tilde_additional_suffixes = default_suffixes;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
265
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
266 bool is_dev_sep (char c)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
267 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
268 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
269 return c == dev_sep_char ();
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
270 #else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
271 octave_unused_parameter (c);
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1779
diff changeset
272
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
273 return false;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
274 #endif
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
275 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2847
diff changeset
276
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
277 bool is_dir_sep (char c)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
278 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
279 std::string tmp = dir_sep_chars ();
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
280 return tmp.find (c) != std::string::npos;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
281 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
282
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
283 std::string tilde_expand (const std::string& name)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
284 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
285 if (name.find ('~') == std::string::npos)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
286 return std::string (name);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
287 else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
288 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
289 std::string result;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
290
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
291 std::size_t name_len = name.length ();
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
292
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
293 // Scan through S expanding tildes as we come to them.
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
294
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
295 std::size_t pos = 0;
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
296
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
297 while (1)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
298 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
299 if (pos > name_len)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
300 break;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
301
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
302 std::size_t len;
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
303
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
304 // Make START point to the tilde which starts the expansion.
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
305
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
306 std::size_t start = tilde_find_prefix (name.substr (pos), len);
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
307
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
308 result.append (name.substr (pos, start));
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
309
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
310 // Advance STRING to the starting tilde.
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
311
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
312 pos += start;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
313
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
314 // Make FINI be the index of one after the last character of the
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
315 // username.
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
316
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
317 std::size_t fini = tilde_find_suffix (name.substr (pos));
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
318
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
319 // If both START and FINI are zero, we are all done.
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
320
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
321 if (! (start || fini))
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
322 break;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
323
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
324 // Expand the entire tilde word, and copy it into RESULT.
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
325
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
326 std::string tilde_word = name.substr (pos, fini);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
327
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
328 pos += fini;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
329
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
330 std::string expansion = tilde_expand_word (tilde_word);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
331
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
332 result.append (expansion);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
333 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
334
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
335 return result;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
336 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
337 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
338
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
339 string_vector tilde_expand (const string_vector& names)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
340 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
341 int n = names.numel ();
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
342
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23804
diff changeset
343 string_vector retval (n);
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
344
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
345 for (int i = 0; i < n; i++)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
346 retval[i] = tilde_expand (names[i]);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
347
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
348 return retval;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
349 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
350
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
351 std::string concat (const std::string& dir, const std::string& file)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
352 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
353 return dir.empty ()
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
354 ? file
23812
057a894914df Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents: 23804
diff changeset
355 : (is_dir_sep (dir.back ())
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
356 ? dir + file
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
357 : dir + dir_sep_char () + file);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
358 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
359
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
360 std::string dirname (const std::string& path)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
361 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
362 std::size_t ipos = path.find_last_of (dir_sep_chars ());
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
363
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
364 return (ipos != std::string::npos) ? path.substr (0, ipos) : "";
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
365 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
366
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
367 std::string tail (const std::string& path)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
368 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
369 std::size_t ipos = path.find_last_of (dir_sep_chars ());
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
370
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
371 if (ipos != std::string::npos)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
372 ipos++;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
373 else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
374 ipos = 0;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
375
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
376 return path.substr (ipos);
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
377 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
378
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
379 std::string native_separator_path (const std::string& path)
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
380 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
381 std::string retval;
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
382
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
383 if (dir_sep_char () == '/')
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
384 retval = path;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
385 else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
386 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
387 std::size_t n = path.length ();
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
388 for (std::size_t i = 0; i < n; i++)
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
389 {
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
390 if (path[i] == '/')
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
391 retval += dir_sep_char();
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
392 else
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
393 retval += path[i];
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
394 }
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
395 }
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
396
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
397 return retval;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
398 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
399
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
400 OCTAVE_END_NAMESPACE(file_ops)
3040
443851377f3f [project @ 1997-06-06 09:29:28 by jwe]
jwe
parents: 2947
diff changeset
401
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
402 int mkdir (const std::string& nm, mode_t md)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
403 {
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
404 std::string msg;
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
405 return mkdir (nm, md, msg);
21881
aea1bf9493c0 * file-ops.h, file-ops.cc (file_ops::file_ops): Now protected.
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
406 }
aea1bf9493c0 * file-ops.h, file-ops.cc (file_ops::file_ops): Now protected.
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
407
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
408 int mkdir (const std::string& name, mode_t mode, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
409 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
410 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
411
21909
d7cac41df82a provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents: 21896
diff changeset
412 int status = octave_mkdir_wrapper (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
413
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
414 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
415 msg = std::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
416
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
417 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
418 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
419
31320
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
420 int recursive_mkdir (const std::string& name, mode_t mode)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
421 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
422 std::string msg;
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
423 return recursive_mkdir (name, mode, msg);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
424 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
425
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
426 int recursive_mkdir (const std::string& name, mode_t mode, std::string& msg)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
427 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
428 int status;
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
429
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
430 // account for root in absolute directories
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
431 #if defined (OCTAVE_USE_WINDOWS_API)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
432 // root of current drive
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
433 std::size_t skip_root = 0;
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
434 if (name.size () > 1)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
435 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
436 if (name[1] == ':')
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
437 // drive root (e.g., C:\)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
438 skip_root = 2;
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
439 else if (file_ops::is_dir_sep (name[0])
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
440 && file_ops::is_dir_sep (name[1]))
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
441 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
442 // UNC path root (e.g., \\SERVER\share\)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
443 skip_root = name.find_first_of (file_ops::dir_sep_chars (), 2);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
444 skip_root = name.find_first_of (file_ops::dir_sep_chars (),
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
445 skip_root + 1);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
446 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
447 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
448
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
449 std::size_t delim = name.find_first_of (file_ops::dir_sep_chars (),
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
450 skip_root + 1);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
451 #else
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
452 std::size_t delim = name.find_first_of (file_ops::dir_sep_chars (), 1);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
453 #endif
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
454
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
455 // iterate over all componenents of NAME and make directories
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
456 while (delim != std::string::npos)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
457 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
458 std::string base = name.substr (0, delim);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
459 sys::file_stat fs (base);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
460 if (! fs.is_dir ())
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
461 {
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
462 status = mkdir (base, mode, msg);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
463 if (status < 0)
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
464 return status;
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
465 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
466 delim = name.find_first_of (file_ops::dir_sep_chars (), delim + 1);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
467 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
468
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
469 // finally, create requested directory
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
470 return mkdir (name, mode, msg);
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
471 }
6a5e4ef80a95 Create directory for history file recursively (bug #62365).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31216
diff changeset
472
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
473 int mkfifo (const std::string& nm, mode_t md)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
474 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
475 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
476 return mkfifo (nm, md, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
477 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
478
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
479 int mkfifo (const std::string& name, mode_t mode, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
480 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
481 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
482
21909
d7cac41df82a provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents: 21896
diff changeset
483 int status = octave_mkfifo_wrapper (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
484
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
485 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
486 msg = std::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
487
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
488 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
489 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
490
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
491 int link (const std::string& old_name, const std::string& new_name)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
492 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
493 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
494 return link (old_name, new_name, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
495 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
496
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
497 int link (const std::string& old_name, const std::string& new_name,
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
498 std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
499 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
500 msg = "";
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
501
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
502 int status = -1;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
503
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21909
diff changeset
504 status = octave_link_wrapper (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
505
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
506 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
507 msg = std::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
508
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
509 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
510 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
511
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
512 int symlink (const std::string& old_name, const std::string& new_name)
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
513 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
514 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
515 return symlink (old_name, new_name, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
516 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
517
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
518 int symlink (const std::string& old_name, const std::string& new_name,
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
519 std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
520 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
521 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
522
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
523 int status = -1;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
524
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21909
diff changeset
525 status = octave_symlink_wrapper (old_name.c_str (), new_name.c_str ());
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
526
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
527 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
528 msg = std::strerror (errno);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
529
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
530 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
531 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
532
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
533 int readlink (const std::string& path, std::string& result)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
534 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
535 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
536 return readlink (path, result, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
537 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
538
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
539 int readlink (const std::string& path, std::string& result, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
540 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
541 int status = -1;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
542
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
543 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
544
21896
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
545 char *buf = octave_areadlink_wrapper (path.c_str ());
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
546
21896
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
547 if (! buf)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
548 msg = std::strerror (errno);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
549 else
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
550 {
21896
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
551 result = buf;
83c824c727c9 hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents: 21890
diff changeset
552 ::free (buf);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
553 status = 0;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
554 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
555
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
556 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
557 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
558
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
559 int rename (const std::string& from, const std::string& to)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
560 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
561 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
562 return rename (from, to, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
563 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
564
25624
815cfd72ddf5 Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
565 int rename (const std::string& from, const std::string& to,
815cfd72ddf5 Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
566 std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
567 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
568 int status = -1;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
569
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
570 msg = "";
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
571
25624
815cfd72ddf5 Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
572 #if defined (OCTAVE_USE_WINDOWS_API)
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28053
diff changeset
573 std::wstring wfrom = u8_to_wstring (from);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28053
diff changeset
574 std::wstring wto = u8_to_wstring (to);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28053
diff changeset
575 status = _wrename (wfrom.c_str (), wto.c_str ());
25624
815cfd72ddf5 Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
576 #else
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
577 status = std::rename (from.c_str (), to.c_str ());
25624
815cfd72ddf5 Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
578 #endif
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
579
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
580 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
581 msg = std::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
582
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
583 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
584 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
585
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
586 int rmdir (const std::string& name)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
587 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
588 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
589 return rmdir (name, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
590 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
591
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
592 int rmdir (const std::string& name, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
593 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
594 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
595
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
596 int status = -1;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
597
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21909
diff changeset
598 status = octave_rmdir_wrapper (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
599
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
600 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
601 msg = std::strerror (errno);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
602
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
603 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
604 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
605
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
606 // And a version that works recursively.
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
607
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
608 int recursive_rmdir (const std::string& name)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
609 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
610 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
611 return recursive_rmdir (name, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
612 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
613
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
614 int recursive_rmdir (const std::string& 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
615 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
616 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
617
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
618 int status = 0;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
619
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25438
diff changeset
620 string_vector dirlist;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
621
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25438
diff changeset
622 if (get_dirlist (name, dirlist, msg))
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
623 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
624 for (octave_idx_type i = 0; i < dirlist.numel (); i++)
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
625 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
626 octave_quit ();
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
627
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
628 std::string nm = dirlist[i];
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
629
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
630 // Skip current directory and parent.
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
631 if (nm == "." || nm == "..")
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
632 continue;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
633
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
634 std::string fullnm = name + file_ops::dir_sep_str () + nm;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
635
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
636 // Get info about the file. Don't follow links.
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
637 file_stat fs (fullnm, false);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
638
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
639 if (fs)
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
640 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
641 if (fs.is_dir ())
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
642 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
643 status = recursive_rmdir (fullnm, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
644
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
645 if (status < 0)
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
646 break;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
647 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
648 else
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
649 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
650 status = unlink (fullnm, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
651
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
652 if (status < 0)
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
653 break;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
654 }
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
655 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
656 else
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
657 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
658 msg = fs.error ();
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
659 break;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
660 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
661 }
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
662
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
663 if (status >= 0)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25438
diff changeset
664 status = rmdir (name, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
665 }
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
666 else
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25438
diff changeset
667 status = -1;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
668
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
669 return status;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
670 }
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
671
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
672 int umask (mode_t mode)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
673 {
21909
d7cac41df82a provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents: 21896
diff changeset
674 return octave_umask_wrapper (mode);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
675 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
676
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
677 int unlink (const std::string& name)
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
678 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
679 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
680 return unlink (name, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
681 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
682
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
683 int unlink (const std::string& name, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
684 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
685 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
686
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
687 int status = -1;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
688
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21909
diff changeset
689 status = octave_unlink_wrapper (name.c_str ());
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
690
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
691 if (status < 0)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
692 msg = std::strerror (errno);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
693
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
694 return status;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
695 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
696
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
697 std::string tempnam (const std::string& dir, const std::string& pfx)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
698 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
699 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
700 return tempnam (dir, pfx, msg);
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
701 }
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
702
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
703 std::string tempnam (const std::string& dir, const std::string& pfx,
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
704 std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
705 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
706 msg = "";
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
707
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
708 std::string retval;
10197
4d433bd2d4dc attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents: 10189
diff changeset
709
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
710 // get dir path to use for template
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
711 std::string templatename;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
712 if (dir.empty ())
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
713 templatename = env::get_temp_directory ();
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
714 else if (! file_stat (dir, false).is_dir ())
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
715 templatename = env::get_temp_directory ();
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
716 else
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
717 templatename = dir;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
718
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
719 // add dir sep char if it is not there
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
720 if (*templatename.rbegin () != file_ops::dir_sep_char ())
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
721 templatename += file_ops::dir_sep_char ();
19420
82f2a3437e02 Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents: 18412
diff changeset
722
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
723 if (pfx.empty ())
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
724 templatename += "file";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
725 else
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
726 templatename += pfx;
19458
d8fd3842a507 Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents: 19428
diff changeset
727
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
728 // add the required XXXXXX for the template
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
729 templatename += "XXXXXX";
19428
eee9f111c164 Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents: 19420
diff changeset
730
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
731 // create and copy template to char array for call to gen_tempname
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
732 char tname [templatename.length () + 1];
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19458
diff changeset
733
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
734 strcpy (tname, templatename.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
735
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
736 if (octave_gen_tempname_wrapper (tname) == -1)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
737 msg = std::strerror (errno);
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
738 else
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
739 retval = tname;
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
740
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
741 return retval;
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
742 }
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
743
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
744 std::string canonicalize_file_name (const std::string& name)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
745 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
746 std::string msg;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
747 return canonicalize_file_name (name, msg);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
748 }
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
749
23744
ae74608b6a5d don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
750 std::string canonicalize_file_name (const std::string& name, std::string& msg)
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
751 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
752 msg = "";
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
753
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
754 std::string retval;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
755
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
756 // FIXME: Consider replacing this with std::filesystem::canonical on all
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
757 // platforms once we allow using C++17.
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
758
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
759 #if defined (OCTAVE_USE_WINDOWS_API)
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
760 // open file handle
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
761 std::wstring wname = u8_to_wstring (name);
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
762 HANDLE h_file = CreateFileW (wname.c_str (), GENERIC_READ,
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
763 FILE_SHARE_READ, nullptr, OPEN_EXISTING,
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
764 FILE_FLAG_BACKUP_SEMANTICS, nullptr);
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
765
31177
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
766 // Might have been a symbolic link that points to a network share.
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
767 // It looks like opening a network share itself (not a file or folder
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
768 // *on* a share) might return an invalid handle. As a workaround, try to
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
769 // open a handle to the symbolic link itself (and do not resolve it).
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
770 if (h_file == INVALID_HANDLE_VALUE)
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
771 h_file = CreateFileW (wname.c_str (), GENERIC_READ,
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
772 FILE_SHARE_READ, nullptr, OPEN_EXISTING,
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
773 FILE_FLAG_BACKUP_SEMANTICS
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
774 | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
775
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
776 if (h_file == INVALID_HANDLE_VALUE)
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
777 {
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
778 msg = "Unable to open file \"" + name + "\"";
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
779 return retval;
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
780 }
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
781
29950
6549fa7558ba eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 29657
diff changeset
782 unwind_action close_file_handle (CloseHandle, h_file);
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
783
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29530
diff changeset
784 const std::size_t buf_size = 32767;
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
785 wchar_t buffer[buf_size] = L"";
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
786
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
787 // query canonical name
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
788 DWORD len = GetFinalPathNameByHandleW (h_file, buffer, buf_size,
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
789 FILE_NAME_NORMALIZED);
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
790 if (len >= buf_size)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30072
diff changeset
791 {
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
792 msg = "Error querying normalized name for \"" + name + "\"";
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
793 return retval;
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30072
diff changeset
794 }
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
795
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
796 retval = u8_from_wstring (std::wstring (buffer, len));
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
797
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
798 // remove prefix
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
799 // "Normal" paths are prefixed by "\\?\".
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
800 // UNC paths are prefixed by "\\?\UNC\".
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
801 if (retval.compare (0, 8, R"(\\?\UNC\)") == 0)
31097
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
802 {
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
803 retval = retval.erase (2, 6);
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
804
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
805 // If the initial path looked like a mapped network drive, replace
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
806 // portion of path that corresponds to mapped root with drive root.
31196
4c38cf0ce06c canonicalize_file_name: Check root of potential mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31185
diff changeset
807 if (name.size () < 3 || name[1] != ':')
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
808 return retval;
31177
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
809
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
810 // UNC path corresponding to original drive letter (mappped drive)
31196
4c38cf0ce06c canonicalize_file_name: Check root of potential mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31185
diff changeset
811 std::wstring orig_map = wname.substr (0, 3);
4c38cf0ce06c canonicalize_file_name: Check root of potential mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31185
diff changeset
812 orig_map[2] = L'\\';
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
813 HANDLE h_map = CreateFileW (orig_map.c_str (), GENERIC_READ,
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
814 FILE_SHARE_READ, nullptr, OPEN_EXISTING,
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
815 FILE_FLAG_BACKUP_SEMANTICS
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
816 | FILE_FLAG_OPEN_REPARSE_POINT,
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
817 nullptr);
31177
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
818
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
819 if (h_map == INVALID_HANDLE_VALUE)
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
820 // cannot determine common root
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
821 return retval;
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
822
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
823 unwind_action close_map_handle (CloseHandle, h_map);
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
824 len = GetFinalPathNameByHandleW (h_map, buffer, buf_size,
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
825 FILE_NAME_NORMALIZED);
31177
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
826
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
827 std::string orig_root
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
828 = u8_from_wstring (std::wstring (buffer, len));
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
829
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
830 if (orig_root.compare (0, 8, R"(\\?\UNC\)"))
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
831 // root was not a mapped share
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
832 return retval;
31177
51311efef5dd canonicalize_file_name: Handle symlinks to UNC network shares (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31097
diff changeset
833
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
834 orig_root = orig_root.erase (2, 6);
31216
f111d1caa73d canonicalize_file_name: Trim trailing file separators from root of mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31196
diff changeset
835 // trim trailing file separators from UNC path corresponding to root
f111d1caa73d canonicalize_file_name: Trim trailing file separators from root of mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31196
diff changeset
836 std::string file_seps = file_ops::dir_sep_chars ();
f111d1caa73d canonicalize_file_name: Trim trailing file separators from root of mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31196
diff changeset
837 while (file_seps.find (orig_root.back ()) != std::string::npos)
f111d1caa73d canonicalize_file_name: Trim trailing file separators from root of mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31196
diff changeset
838 orig_root.pop_back ();
f111d1caa73d canonicalize_file_name: Trim trailing file separators from root of mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31196
diff changeset
839
31185
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
840 if (retval.compare (0, orig_root.size (), orig_root))
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
841 // start of UNC path doesn't match mapped drive root
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
842 return retval;
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
843
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
844 // file is on mapped share
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
845 size_t sep_pos = orig_root.size ();
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
846 if (sep_pos != retval.size ())
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
847 retval = retval.substr (sep_pos-2);
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
848 else
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
849 retval.resize (2); // no file component
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
850 retval[0] = std::toupper (name[0]);
84df79fb637d canonicalize_file_name: Generalize check for mapped network drive (bug #62847).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31177
diff changeset
851 retval[1] = ':';
31097
b47bf773c508 canonicalize_file_path: Do not translate mapped network drive to UNC path (bug #62576).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
852 }
29530
47fc7cacc65d canonicalize_file_name: Be more wary when removing path prefix on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29521
diff changeset
853 else if (retval.compare (0, 4, R"(\\?\)") == 0)
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
854 retval = retval.erase (0, 4);
28471
a6c89130cfaa Improve canonicalize_file_name with non-ASCII characters on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28204
diff changeset
855 #else
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
856 char *tmp = octave_canonicalize_file_name_wrapper (name.c_str ());
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
857
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
858 if (tmp)
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
859 {
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
860 retval = tmp;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
861 free (tmp);
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
862 }
27496
def608acdfa9 Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27102
diff changeset
863
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
864 if (retval.empty ())
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
865 msg = std::strerror (errno);
29521
d7223245d26f canonicalize_file_name: Use newer Windows API functions (bug #60306).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29516
diff changeset
866 #endif
10252
2fcc927a8757 liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents: 10250
diff changeset
867
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
868 return retval;
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
869 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
870
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
871 OCTAVE_END_NAMESPACE(sys)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31320
diff changeset
872 OCTAVE_END_NAMESPACE(octave)