summaryrefslogtreecommitdiff
path: root/src/libstddjb/fd_copy2.c
blob: 4f2e80d78dd24b2f80f829bae7eecd9acb32d238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* ISC license. */

#include <errno.h>
#include <skalibs/djbunix.h>

int fd_copy2 (int to1, int from1, int to2, int from2)
{
  if ((to1 == from2) || (to2 == from1)) return (errno = EINVAL, -1) ;
  if (fd_copy(to1, from1) == -1) return -1 ;
  if (fd_copy(to2, from2) == -1)
  {
    if (to1 != from1) fd_close(to1) ;
    return -1 ;
  }
  return 0 ;
}