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>
18 * bool write_string_to_file(const char *file, const char *string)
20 * int ret, fd = open(file, O_WRONLY|O_CREAT|O_EXCL, 0600);
23 * ret = write(fd, string, strlen(string));
25 * // Preserve errno from write above.
30 * if (close(fd) != 0) {
31 * // Again, preserve errno.
35 * // A short write means out of space.
36 * if (ret < strlen(string)) {
44 int main(int argc, char *argv[])
49 if (strcmp(argv[1], "depends") == 0)