X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fnoerr%2F_info;fp=ccan%2Fnoerr%2F_info;h=fee413d3bbc90b23a756bc3a1b7eefb8a1c019e0;hp=0000000000000000000000000000000000000000;hb=570c9c555f076e74f46141bb42b5d1d7ac89f632;hpb=8f61c0bccb152b2365baf70deac1e59264d7feb7 diff --git a/ccan/noerr/_info b/ccan/noerr/_info new file mode 100644 index 00000000..fee413d3 --- /dev/null +++ b/ccan/noerr/_info @@ -0,0 +1,60 @@ +#include +#include +#include "config.h" + +/** + * noerr - routines for cleaning up without blatting errno + * + * It is a good idea to follow the standard C convention of setting errno in + * your own helper functions. Unfortunately, care must be taken in the error + * paths as most standard functions can (and do) overwrite errno, even if they + * succeed. + * + * Example: + * #include + * #include + * #include + * #include + * #include + * #include + * #include + * + * bool write_string_to_file(const char *file, const char *string) + * { + * int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600); + * if (fd < 0) + * return false; + * ret = write(fd, string, strlen(string)); + * if (ret < 0) { + * // Preserve errno from write above. + * close_noerr(fd); + * unlink_noerr(file); + * return false; + * } + * if (close(fd) != 0) { + * // Again, preserve errno. + * unlink_noerr(file); + * return false; + * } + * // A short write means out of space. + * if (ret < strlen(string)) { + * unlink(file); + * errno = ENOSPC; + * return false; + * } + * return true; + * } + * + * Licence: LGPL (2 or any later version) + */ +int main(int argc, char *argv[]) +{ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) + /* Nothing. */ + return 0; + + return 1; +}