_info 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "config.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. /**
  5. * noerr - routines for cleaning up without blatting errno
  6. *
  7. * It is a good idea to follow the standard C convention of setting errno in
  8. * your own helper functions. Unfortunately, care must be taken in the error
  9. * paths as most standard functions can (and do) overwrite errno, even if they
  10. * succeed.
  11. *
  12. * Example:
  13. * #include <sys/types.h>
  14. * #include <sys/stat.h>
  15. * #include <fcntl.h>
  16. * #include <stdbool.h>
  17. * #include <string.h>
  18. * #include <errno.h>
  19. * #include <ccan/noerr/noerr.h>
  20. *
  21. * static bool write_string_to_file(const char *file, const char *string)
  22. * {
  23. * int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
  24. * if (fd < 0)
  25. * return false;
  26. * ret = write(fd, string, strlen(string));
  27. * if (ret < 0) {
  28. * // Preserve errno from write above.
  29. * close_noerr(fd);
  30. * unlink_noerr(file);
  31. * return false;
  32. * }
  33. * if (close(fd) != 0) {
  34. * // Again, preserve errno.
  35. * unlink_noerr(file);
  36. * return false;
  37. * }
  38. * // A short write means out of space.
  39. * if (ret < (int)strlen(string)) {
  40. * unlink(file);
  41. * errno = ENOSPC;
  42. * return false;
  43. * }
  44. * return true;
  45. * }
  46. *
  47. * License: CC0 (Public domain)
  48. * Author: Rusty Russell <rusty@rustcorp.com.au>
  49. */
  50. int main(int argc, char *argv[])
  51. {
  52. if (argc != 2)
  53. return 1;
  54. if (strcmp(argv[1], "depends") == 0)
  55. /* Nothing. */
  56. return 0;
  57. return 1;
  58. }