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.

65 lines
1.7KB

  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. auto compar = [](const FTSENT **a, const FTSENT **b) -> int {
  34. return strcmp((*a)->fts_name, (*b)->fts_name);
  35. };
  36. FTS *fts = fts_open(argv, FTS_NOCHDIR|FTS_PHYSICAL, +compar);
  37. if (!fts)
  38. return;
  39. auto fts_cleanup = defer([fts]() { fts_close(fts); });
  40. std::string pathbuf;
  41. pathbuf.reserve(1024);
  42. while (FTSENT *ent = fts_read(fts)) {
  43. if (ent->fts_info == FTS_D) {
  44. pathbuf.assign(ent->fts_path);
  45. pathbuf.push_back('/');
  46. if (!visit(pathbuf, data))
  47. return;
  48. }
  49. }
  50. #endif
  51. }
  52. } // namespace ysfx
  53. #endif // !defined(_WIN32)