comparison liboctave/util/oct-glob.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 597f3ee61a48
children b0785d76430a
comparison
equal deleted inserted replaced
32077:ed3a18fe328a 32078:632f9b828de1
51 // transforms the glob_match::glob function to be glob_match::rpl_glob, 51 // transforms the glob_match::glob function to be glob_match::rpl_glob,
52 // which is not what we want... 52 // which is not what we want...
53 53
54 OCTAVE_BEGIN_NAMESPACE(octave) 54 OCTAVE_BEGIN_NAMESPACE(octave)
55 55
56 static bool
57 single_match_exists (const std::string& file)
58 {
59 sys::file_stat s (file);
60
61 return s.exists ();
62 }
63
64 OCTAVE_BEGIN_NAMESPACE(sys) 56 OCTAVE_BEGIN_NAMESPACE(sys)
65 57
66 bool 58 bool
67 fnmatch (const string_vector& pat, const std::string& str, int fnm_flags) 59 fnmatch (const string_vector& pat, const std::string& str, int fnm_flags)
68 { 60 {
119 // check for us unless the pattern contains globbing 111 // check for us unless the pattern contains globbing
120 // characters. Hmm. 112 // characters. Hmm.
121 113
122 if (n > 1 114 if (n > 1
123 || (n == 1 115 || (n == 1
124 && single_match_exists (std::string (matches[0])))) 116 && sys::file_exists (std::string (matches[0]))))
125 { 117 {
126 retval.resize (k+n); 118 retval.resize (k+n);
127 119
128 for (int j = 0; j < n; j++) 120 for (int j = 0; j < n; j++)
129 { 121 {
369 // check for us unless the pattern contains globbing 361 // check for us unless the pattern contains globbing
370 // characters. Hmm. 362 // characters. Hmm.
371 363
372 if (n > 1 364 if (n > 1
373 || (n == 1 365 || (n == 1
374 && single_match_exists (std::string (matches[0])))) 366 && sys::file_exists (std::string (matches[0]))))
375 { 367 {
376 retval.resize (k + n); 368 retval.resize (k + n);
377 369
378 for (int j = 0; j < n; j++) 370 for (int j = 0; j < n; j++)
379 { 371 {