_info.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.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. *
  17. * bool write_string_to_file(const char *file, const char *string)
  18. * {
  19. * int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
  20. * if (fd < 0)
  21. * return false;
  22. * ret = write(fd, string, strlen(string));
  23. * if (ret < 0) {
  24. * // Preserve errno from write above.
  25. * close_noerr(fd);
  26. * unlink_noerr(file);
  27. * return false;
  28. * }
  29. * if (close(fd) != 0) {
  30. * // Again, preserve errno.
  31. * unlink_noerr(file);
  32. * return false;
  33. * }
  34. * // A short write means out of space.
  35. * if (ret < strlen(string)) {
  36. * unlink(file);
  37. * errno = ENOSPC;
  38. * return false;
  39. * }
  40. * return true;
  41. * }
  42. */
  43. int main(int argc, char *argv[])
  44. {
  45. if (argc != 2)
  46. return 1;
  47. if (strcmp(argv[1], "depends") == 0)
  48. /* Nothing. */
  49. return 0;
  50. return 1;
  51. }