/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* -last fcntl25*/2627#include <ast.h>2829#ifndef fcntl3031NoN(fcntl)3233#else3435#include <ls.h>36#include <ast_tty.h>37#include <error.h>3839#if F_SETFD >= _ast_F_LOCAL40#if _sys_filio41#include <sys/filio.h>42#endif43#endif4445#if _lib_fcntl46#undef fcntl47extern int fcntl(int, int, ...);48#endif4950int51_ast_fcntl(int fd, int op, ...)52{53int n;54int save_errno;55struct stat st;56va_list ap;5758save_errno = errno;59va_start(ap, op);60if (op >= _ast_F_LOCAL) switch (op)61{62#if F_DUPFD >= _ast_F_LOCAL63case F_DUPFD:64n = va_arg(ap, int);65op = dup2(fd, n);66break;67#endif68#if F_GETFL >= _ast_F_LOCAL69case F_GETFL:70op = fstat(fd, &st);71break;72#endif73#if F_SETFD >= _ast_F_LOCAL && defined(FIOCLEX)74case F_SETFD:75n = va_arg(ap, int);76op = ioctl(fd, n == FD_CLOEXEC ? FIOCLEX : FIONCLEX, 0);77break;78#endif79default:80errno = EINVAL;81op = -1;82break;83}84else85#if _lib_fcntl86op = fcntl(fd, op, va_arg(ap, int));87#else88{89errno = EINVAL;90op = -1;91}92#endif93va_end(ap);94return(op);95}9697#endif9899100