Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8KB

  1. // Copyright 2021 Jean Pierre Cimalando
  2. //
  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
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  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.
  14. //
  15. // SPDX-License-Identifier: Apache-2.0
  16. //
  17. #if !defined(_WIN32)
  18. // fts lacks large file support in glibc < 2.23
  19. #if defined(YSFX_FTS_LACKS_LFS_SUPPORT)
  20. # undef _FILE_OFFSET_BITS
  21. #endif
  22. #include "ysfx_utils.hpp"
  23. #ifndef __EMSCRIPTEN__
  24. #include <fts.h>
  25. #endif
  26. #include <string>
  27. #include <cstring>
  28. namespace ysfx {
  29. void visit_directories(const char *rootpath, bool (*visit)(const std::string &, void *), void *data)
  30. {
  31. #ifndef __EMSCRIPTEN__
  32. char *argv[] = {(char *)rootpath, nullptr};
  33. #if !defined(__FreeBSD__)
  34. using compar_arg_t = const FTSENT **;
  35. #else
  36. using compar_arg_t = const FTSENT *const *;
  37. #endif
  38. auto compar = [](compar_arg_t a, compar_arg_t b) -> int {
  39. return strcmp((*a)->fts_name, (*b)->fts_name);
  40. };
  41. FTS *fts = fts_open(argv, FTS_NOCHDIR|FTS_PHYSICAL, +compar);
  42. if (!fts)
  43. return;
  44. auto fts_cleanup = defer([fts]() { fts_close(fts); });
  45. std::string pathbuf;
  46. pathbuf.reserve(1024);
  47. while (FTSENT *ent = fts_read(fts)) {
  48. if (ent->fts_info == FTS_D) {
  49. pathbuf.assign(ent->fts_path);
  50. pathbuf.push_back('/');
  51. if (!visit(pathbuf, data))
  52. return;
  53. }
  54. }
  55. #endif
  56. }
  57. } // namespace ysfx
  58. #endif // !defined(_WIN32)