home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
comm
/
tcp
/
amitcp
/
src
/
netlib
/
_dup2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-12
|
1KB
|
75 lines
RCS_ID_C="$Id: _dup2.c,v 3.2 1994/04/12 20:43:21 jraja Exp $";
/*
* _dup2.c - duplicate a file descriptor for SAS C
*
* Author: ppessi <Pekka.Pessi@hut.fi>
*
* Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* Created : Thu Mar 24 05:19:36 1994 ppessi
* Last modified: Thu Mar 24 07:58:07 1994 ppessi
*
*/
#include <ios1.h>
#include <fcntl.h>
#include <stdlib.h>
#include <dos.h>
#define USE_BUILTIN_MATH
#include <string.h>
#include <errno.h>
#include <dos/dos.h>
#include <proto/dos.h>
#include <bsdsocket.h>
/****** net.lib/dup2 **********************************************************
SEE ALSO
dup()
*******************************************************************************
*/
int
__dup2(int old_fd, int new_fd)
{
struct UFB *ufb;
int ufbflg;
/*
* Check if there is nothing to do
*/
if (old_fd == new_fd)
return old_fd;
/*
* Check for the break signals
*/
__chkabort();
__close(new_fd);
/*
* Find the ufb * for the old FD
*/
if ((ufb = __chkufb(old_fd)) == NULL) {
errno = EBADF;
return -1;
}
ufbflg = ufb->ufbflg;
/*
* The brain dead UFB system won't allow duplicating ordinary files
*/
if ((ufbflg & UFB_SOCK) == UFB_SOCK) {
return Dup2Socket(old_fd, new_fd);
} else {
errno = EBADF;
return -1;
}
}