6 * noerr - routines for cleaning up without blatting errno
8 * It is a good idea to follow the standard C convention of setting errno in
9 * your own helper functions. Unfortunately, care must be taken in the error
10 * paths as most standard functions can (and do) overwrite errno, even if they
14 * #include <sys/types.h>
15 * #include <sys/stat.h>
17 * #include <stdbool.h>
20 * #include <ccan/noerr/noerr.h>
22 * bool write_string_to_file(const char *file, const char *string)
24 * int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
27 * ret = write(fd, string, strlen(string));
29 * // Preserve errno from write above.
34 * if (close(fd) != 0) {
35 * // Again, preserve errno.
39 * // A short write means out of space.
40 * if (ret < strlen(string)) {
48 * Licence: LGPL (2 or any later version)
49 * Author: Rusty Russell <rusty@rustcorp.com.au>
51 int main(int argc, char *argv[])
56 if (strcmp(argv[1], "depends") == 0)