1 // Copyright 2021 Jean Pierre Cimalando
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
20 // fts lacks large file support in glibc < 2.23
21 #if defined(YSFX_FTS_LACKS_LFS_SUPPORT)
22 # undef _FILE_OFFSET_BITS
25 #include "ysfx_utils.hpp"
26 #ifndef __EMSCRIPTEN__
34 void visit_directories(const char *rootpath
, bool (*visit
)(const std::string
&, void *), void *data
)
36 #ifndef __EMSCRIPTEN__
37 char *argv
[] = {(char *)rootpath
, nullptr};
39 #if !defined(__FreeBSD__)
40 using compar_arg_t
= const FTSENT
**;
42 using compar_arg_t
= const FTSENT
*const *;
45 auto compar
= [](compar_arg_t a
, compar_arg_t b
) -> int {
46 return strcmp((*a
)->fts_name
, (*b
)->fts_name
);
49 FTS
*fts
= fts_open(argv
, FTS_NOCHDIR
|FTS_PHYSICAL
, +compar
);
52 auto fts_cleanup
= defer([fts
]() { fts_close(fts
); });
55 pathbuf
.reserve(1024);
57 while (FTSENT
*ent
= fts_read(fts
)) {
58 if (ent
->fts_info
== FTS_D
) {
59 pathbuf
.assign(ent
->fts_path
);
60 pathbuf
.push_back('/');
61 if (!visit(pathbuf
, data
))
70 #endif // !defined(_WIN32)