skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

filecopy_unsafe.c (441B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/fcntl.h>
      4 #include <skalibs/djbunix.h>
      5 
      6 int filecopy_unsafe (char const *src, char const *dst, unsigned int mode)
      7 {
      8   int d ;
      9   int s = open2(src, O_RDONLY) ;
     10   if (s < 0) return 0 ;
     11   d = open3(dst, O_WRONLY | O_CREAT | O_TRUNC, mode) ;
     12   if (d < 0) goto errs ;
     13   if (fd_cat(s, d) < 0) goto errd ;
     14   fd_close(d) ;
     15   fd_close(s) ;
     16   return 1 ;
     17 errd:
     18   fd_close(d) ;
     19 errs:
     20   fd_close(s) ;
     21   return 0 ;
     22 }
     23