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

#include <unistd.h>
#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 ;
}