jehanne/sys/src/lib/jehanne/9sys/dup.c

41 lines
1008 B
C
Raw Normal View History

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
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;
2019-11-26 02:25:23 +01:00
f = sys_create("#d/new", -1, in.aslong);
2017-01-05 03:02:56 +01:00
if(f == -1)
return -1;
if(f >= 0){
/* this should never happen */
2019-11-26 02:25:23 +01:00
sys_close(f);
return -1;
}
2017-01-05 03:02:56 +01:00
out.aslong = ~f;
return out.fd[1];
}