2017-01-05 03:02:56 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Jehanne.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
|
|
|
*
|
|
|
|
* Jehanne is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2 of the License.
|
|
|
|
*
|
|
|
|
* Jehanne is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
|
|
|
|
int
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_dup(int oldfd, int newfd)
|
2017-01-05 03:02:56 +01:00
|
|
|
{
|
|
|
|
FdPair in, out;
|
|
|
|
long f;
|
|
|
|
|
|
|
|
in.fd[0] = oldfd;
|
|
|
|
in.fd[1] = newfd;
|
|
|
|
|
|
|
|
f = create("#d/new", -1, in.aslong);
|
|
|
|
if(f == -1)
|
|
|
|
return -1;
|
2017-01-16 23:53:05 +01:00
|
|
|
if(f >= 0){
|
|
|
|
/* this should never happen */
|
|
|
|
close(f);
|
|
|
|
return -1;
|
|
|
|
}
|
2017-01-05 03:02:56 +01:00
|
|
|
out.aslong = ~f;
|
|
|
|
return out.fd[1];
|
|
|
|
}
|