1cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Invoke dup, but avoid some glitches.
2cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
305436638acc7c010349a69c3395f1a57c642dc62Ying Wang   Copyright (C) 2001, 2004-2006, 2009-2012 Free Software Foundation, Inc.
405436638acc7c010349a69c3395f1a57c642dc62Ying Wang
505436638acc7c010349a69c3395f1a57c642dc62Ying Wang   This program is free software: you can redistribute it and/or modify
6cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   it under the terms of the GNU General Public License as published by
705436638acc7c010349a69c3395f1a57c642dc62Ying Wang   the Free Software Foundation; either version 3 of the License, or
805436638acc7c010349a69c3395f1a57c642dc62Ying Wang   (at your option) any later version.
9cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
10cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   This program is distributed in the hope that it will be useful,
11cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   but WITHOUT ANY WARRANTY; without even the implied warranty of
12cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   GNU General Public License for more details.
14cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
15cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   You should have received a copy of the GNU General Public License
1605436638acc7c010349a69c3395f1a57c642dc62Ying Wang   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
18cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Written by Paul Eggert.  */
19cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
2005436638acc7c010349a69c3395f1a57c642dc62Ying Wang#include <config.h>
21cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
22cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#include "unistd-safer.h"
23cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
24cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#include <fcntl.h>
25cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#include <unistd.h>
26cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
27cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or
28cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   STDERR_FILENO.  */
29cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
30cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectint
31cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectdup_safer (int fd)
32cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{
33cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project  return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
34cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project}
35