/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "dup2-array.h"
#include <unistd.h>
{
struct dup2 d;
}
{
int fd;
for (;;) {
for (i = 0; i < count; i++) {
if (moved[i])
continue;
for (j = 0; j < count; j++) {
!moved[j]) {
conflict = j;
break;
}
}
if (j == count) {
/* no conflicts, move it */
i_error("dup2(%d, %d) failed: %m",
return -1;
}
}
}
break;
if (moves) {
/* it's possible that the conflicting fd was
moved already. try again. */
continue;
}
/* ok, we have to dup() */
if (fd == -1) {
return -1;
}
}
return 0;
}