1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A
1N/A/*
1N/A * -last fcntl
1N/A */
1N/A
1N/A#include <ast.h>
1N/A
1N/A#ifndef fcntl
1N/A
1N/ANoN(fcntl)
1N/A
1N/A#else
1N/A
1N/A#include <ls.h>
1N/A#include <ast_tty.h>
1N/A#include <error.h>
1N/A
1N/A#if F_SETFD >= _ast_F_LOCAL
1N/A#if _sys_filio
1N/A#include <sys/filio.h>
1N/A#endif
1N/A#endif
1N/A
1N/A#if _lib_fcntl
1N/A#undef fcntl
1N/Aextern int fcntl(int, int, ...);
1N/A#endif
1N/A
1N/Aint
1N/A_ast_fcntl(int fd, int op, ...)
1N/A{
1N/A int n;
1N/A int save_errno;
1N/A struct stat st;
1N/A va_list ap;
1N/A
1N/A save_errno = errno;
1N/A va_start(ap, op);
1N/A if (op >= _ast_F_LOCAL) switch (op)
1N/A {
1N/A#if F_DUPFD >= _ast_F_LOCAL
1N/A case F_DUPFD:
1N/A n = va_arg(ap, int);
1N/A op = dup2(fd, n);
1N/A break;
1N/A#endif
1N/A#if F_GETFL >= _ast_F_LOCAL
1N/A case F_GETFL:
1N/A op = fstat(fd, &st);
1N/A break;
1N/A#endif
1N/A#if F_SETFD >= _ast_F_LOCAL && defined(FIOCLEX)
1N/A case F_SETFD:
1N/A n = va_arg(ap, int);
1N/A op = ioctl(fd, n == FD_CLOEXEC ? FIOCLEX : FIONCLEX, 0);
1N/A break;
1N/A#endif
1N/A default:
1N/A errno = EINVAL;
1N/A op = -1;
1N/A break;
1N/A }
1N/A else
1N/A#if _lib_fcntl
1N/A op = fcntl(fd, op, va_arg(ap, int));
1N/A#else
1N/A {
1N/A errno = EINVAL;
1N/A op = -1;
1N/A }
1N/A#endif
1N/A va_end(ap);
1N/A return(op);
1N/A}
1N/A
1N/A#endif