filecopy_suffix.c (580B)
1 /* ISC license. */ 2 3 #include <string.h> 4 #include <errno.h> 5 #include <unistd.h> 6 #include <stdio.h> 7 #include <skalibs/djbunix.h> 8 9 int filecopy_suffix (char const *src, char const *dst, unsigned int mode, char const *suffix) 10 { 11 size_t dstlen = strlen(dst) ; 12 size_t suffixlen = strlen(suffix) ; 13 char tmp[dstlen + suffixlen + 1] ; 14 memcpy(tmp, dst, dstlen) ; 15 memcpy(tmp + dstlen, suffix, suffixlen + 1) ; 16 if (!filecopy_unsafe(src, tmp, mode)) return 0 ; 17 if (rename(tmp, dst) < 0) 18 { 19 int e = errno ; 20 unlink(tmp) ; 21 errno = e ; 22 return 0 ; 23 } 24 return 1 ; 25 }