/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Change the file descriptor
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
int fd;
int newfd;
#endif
{
#ifdef F_DUPFD /* the simple case */
errno = 0;
return dupfd;
#else /* do it the hard way */
return dupfd;
/* dup() succeeded but didn't get the right number, recurse */
/* close the one that didn't match */
return newfd;
#endif
}
#if __STD_C
#else
Sfio_t *f;
int newfd;
#endif
{
SFMTXDECL(f);
SFMTXENTER(f, -1);
SFMTXRETURN(f, -1);
{ /* restoring file descriptor after a previous freeze */
if(newfd < 0)
SFMTXRETURN(f, -1);
}
else
{ /* change file descriptor */
SFMTXRETURN(f, -1);
SFLOCK(f,0);
if(oldfd >= 0)
{ if(newfd >= 0)
{ SFOPEN(f,0);
SFMTXRETURN(f, -1);
}
}
else
{ /* sync stream if necessary */
{ if(SFSYNC(f) < 0)
{ SFOPEN(f,0);
SFMTXRETURN(f, -1);
}
}
{ SFOPEN(f,0);
SFMTXRETURN(f, -1);
}
#ifdef MAP_TYPE
}
#endif
/* make stream appears uninitialized */
}
}
SFOPEN(f,0);
}
/* notify changes */
if(_Sfnotify)
SFMTXRETURN(f,newfd);
}