util_path.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __UTIL_PATH_H__
  17. #define __UTIL_PATH_H__
  18. /* Utility functions to get paths to files distributed with the program. For
  19. * the standalone apps, paths are relative to the executable, for dynamically
  20. * linked libraries, the path to the library may be set with path_init, which
  21. * then makes all paths relative to that. */
  22. #include <stdio.h>
  23. #include "util/util_set.h"
  24. #include "util/util_string.h"
  25. #include "util/util_types.h"
  26. #include "util/util_vector.h"
  27. CCL_NAMESPACE_BEGIN
  28. /* program paths */
  29. void path_init(const string &path = "", const string &user_path = "");
  30. string path_get(const string &sub = "");
  31. string path_user_get(const string &sub = "");
  32. string path_cache_get(const string &sub = "");
  33. /* path string manipulation */
  34. string path_filename(const string &path);
  35. string path_dirname(const string &path);
  36. string path_join(const string &dir, const string &file);
  37. string path_escape(const string &path);
  38. bool path_is_relative(const string &path);
  39. /* file info */
  40. size_t path_file_size(const string &path);
  41. bool path_exists(const string &path);
  42. bool path_is_directory(const string &path);
  43. string path_files_md5_hash(const string &dir);
  44. uint64_t path_modified_time(const string &path);
  45. /* directory utility */
  46. void path_create_directories(const string &path);
  47. /* file read/write utilities */
  48. FILE *path_fopen(const string &path, const string &mode);
  49. bool path_write_binary(const string &path, const vector<uint8_t> &binary);
  50. bool path_write_text(const string &path, string &text);
  51. bool path_read_binary(const string &path, vector<uint8_t> &binary);
  52. bool path_read_text(const string &path, string &text);
  53. /* File manipulation. */
  54. bool path_remove(const string &path);
  55. /* source code utility */
  56. string path_source_replace_includes(const string &source,
  57. const string &path,
  58. const string &source_filename = "");
  59. /* cache utility */
  60. void path_cache_clear_except(const string &name, const set<string> &except);
  61. CCL_NAMESPACE_END
  62. #endif