9 file_exists(char *file)
14 ret = stat(file, &st);
20 warn("enametoolong: %d", strlen(file));
23 error("failed to stat() for '%s' (%s)", file, strerror(errno));
32 file_mtime(char *file, time_t *t)
37 ret = stat(file, &st);
42 error("failed to stat() for '%s' (%s)", file, strerror(errno));
50 copy_stream(FILE *rfp, FILE *wfp)
55 while ((readsz = fread(buf, 1, sizeof(buf), rfp)) != 0) {
56 if (fwrite(buf, readsz, 1, wfp) == 0) {
69 move_file_to_stream(char *file, FILE *wfp)
73 if ((rfp = fopen(file, "r")) == NULL)
76 copy_stream(rfp, wfp);
90 xrename(char *from, char *to)
92 FILE *rfp = NULL, *wfp = NULL;
94 if ((rfp = fopen(from, "r")) == NULL)
97 if ((wfp = fopen(to, "w")) == NULL)
100 copy_stream(rfp, wfp);
102 if (rfp) fclose(rfp);
103 if (wfp) fclose(wfp);
109 if (rfp) fclose(rfp);
110 if (wfp) fclose(wfp);