file_change_detection.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Detecting file changes using modification times.
  2. Copyright (C) 2017-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _FILE_CHANGE_DETECTION_H
  16. #define _FILE_CHANGE_DETECTION_H
  17. #include <stdbool.h>
  18. #include <stdio.h>
  19. #include <sys/stat.h>
  20. #include <sys/types.h>
  21. /* Items for identifying a particular file version. Excerpt from
  22. struct stat64. */
  23. struct file_change_detection
  24. {
  25. /* Special values: 0 if file does not exist. -1 to force mismatch
  26. with the next comparison. */
  27. off64_t size;
  28. ino64_t ino;
  29. struct __timespec64 mtime;
  30. struct __timespec64 ctime;
  31. };
  32. /* Returns true if *LEFT and *RIGHT describe the same version of the
  33. same file. */
  34. bool __file_is_unchanged (const struct file_change_detection *left,
  35. const struct file_change_detection *right);
  36. /* Extract file change information to *FILE from the stat buffer
  37. *ST. */
  38. void __file_change_detection_for_stat (struct file_change_detection *file,
  39. const struct __stat64_t64 *st);
  40. /* Writes file change information for PATH to *FILE. Returns true on
  41. success. For benign errors, *FILE is cleared, and true is
  42. returned. For errors indicating resource outages and the like,
  43. false is returned. */
  44. bool __file_change_detection_for_path (struct file_change_detection *file,
  45. const char *path);
  46. /* Writes file change information for the stream FP to *FILE. Returns
  47. true on success, false on failure. If FP is NULL, treat the file
  48. as non-existing. */
  49. bool __file_change_detection_for_fp (struct file_change_detection *file,
  50. FILE *fp);
  51. #ifndef _ISOMAC
  52. libc_hidden_proto (__file_is_unchanged)
  53. libc_hidden_proto (__file_change_detection_for_stat)
  54. libc_hidden_proto (__file_change_detection_for_path)
  55. libc_hidden_proto (__file_change_detection_for_fp)
  56. #endif
  57. #endif /* _FILE_CHANGE_DETECTION_H */