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.

72 lines
1.5KB

  1. #include "cache.h"
  2. #include "run-command.h"
  3. /*
  4. * Some cases use stdio, but want to flush after the write
  5. * to get error handling (and to get better interactive
  6. * behaviour - not buffering excessively).
  7. *
  8. * Of course, if the flush happened within the write itself,
  9. * we've already lost the error code, and cannot report it any
  10. * more. So we just ignore that case instead (and hope we get
  11. * the right error code on the flush).
  12. *
  13. * If the file handle is stdout, and stdout is a file, then skip the
  14. * flush entirely since it's not needed.
  15. */
  16. void maybe_flush_or_die(FILE *f, const char *desc)
  17. {
  18. static int skip_stdout_flush = -1;
  19. struct stat st;
  20. char *cp;
  21. if (f == stdout) {
  22. if (skip_stdout_flush < 0) {
  23. cp = getenv("GIT_FLUSH");
  24. if (cp)
  25. skip_stdout_flush = (atoi(cp) == 0);
  26. else if ((fstat(fileno(stdout), &st) == 0) &&
  27. S_ISREG(st.st_mode))
  28. skip_stdout_flush = 1;
  29. else
  30. skip_stdout_flush = 0;
  31. }
  32. if (skip_stdout_flush && !ferror(f))
  33. return;
  34. }
  35. if (fflush(f)) {
  36. check_pipe(errno);
  37. die_errno("write failure on '%s'", desc);
  38. }
  39. }
  40. void fprintf_or_die(FILE *f, const char *fmt, ...)
  41. {
  42. va_list ap;
  43. int ret;
  44. va_start(ap, fmt);
  45. ret = vfprintf(f, fmt, ap);
  46. va_end(ap);
  47. if (ret < 0) {
  48. check_pipe(errno);
  49. die_errno("write error");
  50. }
  51. }
  52. void fsync_or_die(int fd, const char *msg)
  53. {
  54. if (fsync(fd) < 0) {
  55. die_errno("fsync error on '%s'", msg);
  56. }
  57. }
  58. void write_or_die(int fd, const void *buf, size_t count)
  59. {
  60. if (write_in_full(fd, buf, count) < 0) {
  61. check_pipe(errno);
  62. die_errno("write error");
  63. }
  64. }