skalibs

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

fd_copy2.c (350B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <skalibs/djbunix.h>
      5 
      6 int fd_copy2 (int to1, int from1, int to2, int from2)
      7 {
      8   if ((to1 == from2) || (to2 == from1)) return (errno = EINVAL, -1) ;
      9   if (fd_copy(to1, from1) == -1) return -1 ;
     10   if (fd_copy(to2, from2) == -1)
     11   {
     12     if (to1 != from1) fd_close(to1) ;
     13     return -1 ;
     14   }
     15   return 0 ;
     16 }