X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fnamespacize.c;h=ae20e3d66c136e83b4675526f9d76c34647d8b41;hp=ac4135459d88b1868d8967013daa14c824ae23de;hb=38ec541c4fd76d971a4959e31cd2a9ff113237ca;hpb=49a1a4366fdcea418582a97cb0bf700373b89868 diff --git a/tools/namespacize.c b/tools/namespacize.c index ac413545..ae20e3d6 100644 --- a/tools/namespacize.c +++ b/tools/namespacize.c @@ -13,7 +13,9 @@ #include "ccan/take/take.h" #include "ccan/rbuf/rbuf.h" #include "ccan/tal/path/path.h" +#include "ccan/tal/grab_file/grab_file.h" #include "ccan/err/err.h" +#include "ccan/noerr/noerr.h" #include "tools.h" static bool verbose = false; @@ -28,15 +30,6 @@ static int indent = 0; #define verbose_indent() (indent += 2) #define verbose_unindent() (indent -= 2) -static int unlink_no_errno(const char *filename) -{ - int ret = 0, serrno = errno; - if (unlink(filename) < 0) - ret = errno; - errno = serrno; - return ret; -} - static char **get_dir(const char *dir) { DIR *d; @@ -259,7 +252,7 @@ static void analyze_headers(const char *dir, struct replace **repl) hdr = tal_fmt(dir, "%s.h", path_join(NULL, dir, take(path_basename(NULL, dir)))); - contents = tal_grab_file(dir, hdr, NULL); + contents = grab_file(dir, hdr); if (!contents) err(1, "Reading %s", hdr); @@ -291,7 +284,7 @@ static void write_replacement_file(const char *dir, struct replace **repl) for (r = *repl; r; r = r->next) { if (write(fd,r->string,strlen(r->string)) != strlen(r->string) || write(fd, "\n", 1) != 1) { - unlink_no_errno(replname); + unlink_noerr(replname); if (errno == 0) errx(1, "Short write to %s: disk full?", replname); @@ -334,7 +327,7 @@ static const char *rewrite_file(const char *filename, int fd; verbose("Rewriting %s\n", filename); - file = tal_grab_file(filename, filename, NULL); + file = grab_file(filename, filename); if (!file) err(1, "Reading file %s", filename); @@ -431,7 +424,7 @@ static struct replace *read_replacement_file(const char *depdir) char *replname = path_join(depdir, depdir, ".namespacize"); char *file, **line; - file = tal_grab_file(replname, replname, NULL); + file = grab_file(replname, replname); if (!file) { if (errno != ENOENT) err(1, "Opening %s", replname);