/* * This file is part of Jehanne. * * Copyright (C) 2017 Giacomo Tesio * * 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 . */ #include #include int jehanne_dup(int oldfd, int newfd) { FdPair in, out; long f; in.fd[0] = oldfd; in.fd[1] = newfd; f = sys_create("#d/new", -1, in.aslong); if(f == -1) return -1; if(f >= 0){ /* this should never happen */ sys_close(f); return -1; } out.aslong = ~f; return out.fd[1]; }