1 /* @(#)fdup.c 1.16 10/11/06 Copyright 1986, 1995-2010 J. Schilling */ 2 /* 3 * Copyright (c) 1986, 1995-2010 J. Schilling 4 */ 5 /* 6 * The contents of this file are subject to the terms of the 7 * Common Development and Distribution License, Version 1.0 only 8 * (the "License"). You may not use this file except in compliance 9 * with the License. 10 * 11 * See the file CDDL.Schily.txt in this distribution for details. 12 * A copy of the CDDL is also available via the Internet at 13 * http://www.opensource.org/licenses/cddl1.txt 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file CDDL.Schily.txt from this distribution. 17 */ 18 19 #include "schilyio.h" 20 21 /* 22 * Note that because of a definition in schilyio.h we are using 23 * fseeko()/ftello() instead of fseek()/ftell() if available. 24 */ 25 26 EXPORT FILE * fdup(f)27fdup(f) 28 register FILE *f; 29 { 30 int newfd; 31 32 down(f); 33 if ((newfd = dup(fileno(f))) < 0) 34 return ((FILE *)NULL); 35 36 lseek(newfd, ftell(f), SEEK_SET); 37 return (_fcons((FILE *)0, newfd, (FI_READ | FI_WRITE | FI_CLOSE))); 38 } 39