THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
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.

74 lines
2.5KB

  1. #ifndef CHDIR_NOTIFY_H
  2. #define CHDIR_NOTIFY_H
  3. /*
  4. * An API to let code "subscribe" to changes to the current working directory.
  5. * The general idea is that some code asks to be notified when the working
  6. * directory changes, and other code that calls chdir uses a special wrapper
  7. * that notifies everyone.
  8. */
  9. /*
  10. * Callers who need to know about changes can do:
  11. *
  12. * void foo(const char *old_path, const char *new_path, void *data)
  13. * {
  14. * warning("switched from %s to %s!", old_path, new_path);
  15. * }
  16. * ...
  17. * chdir_notify_register("description", foo, data);
  18. *
  19. * In practice most callers will want to move a relative path to the new root;
  20. * they can use the reparent_relative_path() helper for that. If that's all
  21. * you're doing, you can also use the convenience function:
  22. *
  23. * chdir_notify_reparent("description", &my_path);
  24. *
  25. * Whenever a chdir event occurs, that will update my_path (if it's relative)
  26. * to adjust for the new cwd by freeing any existing string and allocating a
  27. * new one.
  28. *
  29. * Registered functions are called in the order in which they were added. Note
  30. * that there's currently no way to remove a function, so make sure that the
  31. * data parameter remains valid for the rest of the program.
  32. *
  33. * The "name" argument is used only for printing trace output from
  34. * $GIT_TRACE_SETUP. It may be NULL, but if non-NULL should point to
  35. * storage which lasts as long as the registration is active.
  36. */
  37. typedef void (*chdir_notify_callback)(const char *name,
  38. const char *old_cwd,
  39. const char *new_cwd,
  40. void *data);
  41. void chdir_notify_register(const char *name, chdir_notify_callback cb, void *data);
  42. void chdir_notify_reparent(const char *name, char **path);
  43. /*
  44. *
  45. * Callers that want to chdir:
  46. *
  47. * chdir_notify(new_path);
  48. *
  49. * to switch to the new path and notify any callbacks.
  50. *
  51. * Note that you don't need to chdir_notify() if you're just temporarily moving
  52. * to a directory and back, as long as you don't call any subscribed code in
  53. * between (but it should be safe to do so if you're unsure).
  54. */
  55. int chdir_notify(const char *new_cwd);
  56. /*
  57. * Reparent a relative path from old_root to new_root. For example:
  58. *
  59. * reparent_relative_path("/a", "/a/b", "b/rel");
  60. *
  61. * would return the (newly allocated) string "rel". Note that we may return an
  62. * absolute path in some cases (e.g., if the resulting path is not inside
  63. * new_cwd).
  64. */
  65. char *reparent_relative_path(const char *old_cwd,
  66. const char *new_cwd,
  67. const char *path);
  68. #endif /* CHDIR_NOTIFY_H */