Mercurial > octave
comparison liboctave/util/kpse.cc @ 32078:632f9b828de1
Avoid using file_stat in liboctave/util (bug #59711).
* cmd-edit.cc (looks_like_filename), cmd-hist.cc (gnu_history::do_append),
kpse.cc (kpse_element_dir), oct-glob.cc (glob, windows_glob),
url-transfer.cc (base_url_transfer::mget_directory): Use functions "dir_exists"
or "file_exists" instead of "file_stat".
* kpse.cc (dir_p), oct-glob.cc (single_match_exists): Remove unused static
functions.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 06 May 2023 10:56:33 +0200 |
parents | 21f9b34eb893 |
children | 2e484f9f1f18 |
comparison
equal
deleted
inserted
replaced
32077:ed3a18fe328a | 32078:632f9b828de1 |
---|---|
43 | 43 |
44 #include "dir-ops.h" | 44 #include "dir-ops.h" |
45 #include "file-ops.h" | 45 #include "file-ops.h" |
46 #include "file-stat.h" | 46 #include "file-stat.h" |
47 #include "kpse.h" | 47 #include "kpse.h" |
48 #include "lo-sysdep.h" | |
48 #include "oct-env.h" | 49 #include "oct-env.h" |
49 #include "oct-password.h" | 50 #include "oct-password.h" |
50 #include "oct-time.h" | 51 #include "oct-time.h" |
51 #include "pathsearch.h" | 52 #include "pathsearch.h" |
52 #include "unistd-wrappers.h" | 53 #include "unistd-wrappers.h" |
53 | 54 |
54 #if defined (OCTAVE_USE_WINDOWS_API) | 55 #if defined (OCTAVE_USE_WINDOWS_API) |
55 # define WIN32_LEAN_AND_MEAN 1 | 56 # define WIN32_LEAN_AND_MEAN 1 |
56 # include <windows.h> | 57 # include <windows.h> |
57 | |
58 # include "lo-sysdep.h" | |
59 #endif | 58 #endif |
60 | 59 |
61 // Define the characters which separate components of filenames and | 60 // Define the characters which separate components of filenames and |
62 // environment variable paths. | 61 // environment variable paths. |
63 | 62 |
1013 indx = i; | 1012 indx = i; |
1014 c = (c == satisfy) ? c : 0; | 1013 c = (c == satisfy) ? c : 0; |
1015 return c; | 1014 return c; |
1016 } | 1015 } |
1017 | 1016 |
1018 /* Return true if FN is a directory or a symlink to a directory, | |
1019 false if not. */ | |
1020 | |
1021 static bool | |
1022 dir_p (const std::string& fn) | |
1023 { | |
1024 octave::sys::file_stat fs (fn); | |
1025 | |
1026 return (fs && fs.is_dir ()); | |
1027 } | |
1028 | |
1029 /* Given a path element ELT, return a the element with a trailing slash | 1017 /* Given a path element ELT, return a the element with a trailing slash |
1030 or an empty string if the element is not a directory. | 1018 or an empty string if the element is not a directory. |
1031 | 1019 |
1032 It's up to the caller to expand ELT. This is because this routine is | 1020 It's up to the caller to expand ELT. This is because this routine is |
1033 most likely only useful to be called from 'kpse_path_search', which | 1021 most likely only useful to be called from 'kpse_path_search', which |
1040 | 1028 |
1041 /* If given nothing, return nothing. */ | 1029 /* If given nothing, return nothing. */ |
1042 if (elt.empty ()) | 1030 if (elt.empty ()) |
1043 return ret; | 1031 return ret; |
1044 | 1032 |
1045 if (dir_p (elt)) | 1033 if (octave::sys::dir_exists (elt)) |
1046 { | 1034 { |
1047 ret = elt; | 1035 ret = elt; |
1048 | 1036 |
1049 char last_char = ret.back (); | 1037 char last_char = ret.back (); |
1050 | 1038 |