14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 78462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin #pragma prototyped 234887Schin 244887Schin /* 254887Schin * -last fcntl 264887Schin */ 274887Schin 284887Schin #include <ast.h> 294887Schin 304887Schin #ifndef fcntl 314887Schin 324887Schin NoN(fcntl) 334887Schin 344887Schin #else 354887Schin 364887Schin #include <ls.h> 374887Schin #include <ast_tty.h> 384887Schin #include <error.h> 394887Schin 404887Schin #if F_SETFD >= _ast_F_LOCAL 414887Schin #if _sys_filio 424887Schin #include <sys/filio.h> 434887Schin #endif 444887Schin #endif 454887Schin 464887Schin #if _lib_fcntl 474887Schin #undef fcntl 484887Schin extern int fcntl(int, int, ...); 494887Schin #endif 504887Schin 514887Schin int 524887Schin _ast_fcntl(int fd, int op, ...) 534887Schin { 544887Schin int n; 554887Schin int save_errno; 564887Schin struct stat st; 574887Schin va_list ap; 584887Schin 594887Schin save_errno = errno; 604887Schin va_start(ap, op); 614887Schin if (op >= _ast_F_LOCAL) switch (op) 624887Schin { 634887Schin #if F_DUPFD >= _ast_F_LOCAL 644887Schin case F_DUPFD: 654887Schin n = va_arg(ap, int); 664887Schin op = dup2(fd, n); 674887Schin break; 684887Schin #endif 694887Schin #if F_GETFL >= _ast_F_LOCAL 704887Schin case F_GETFL: 714887Schin op = fstat(fd, &st); 724887Schin break; 734887Schin #endif 744887Schin #if F_SETFD >= _ast_F_LOCAL && defined(FIOCLEX) 754887Schin case F_SETFD: 764887Schin n = va_arg(ap, int); 774887Schin op = ioctl(fd, n == FD_CLOEXEC ? FIOCLEX : FIONCLEX, 0); 784887Schin break; 794887Schin #endif 804887Schin default: 814887Schin errno = EINVAL; 824887Schin op = -1; 834887Schin break; 844887Schin } 854887Schin else 864887Schin #if _lib_fcntl 874887Schin op = fcntl(fd, op, va_arg(ap, int)); 884887Schin #else 894887Schin { 904887Schin errno = EINVAL; 914887Schin op = -1; 924887Schin } 934887Schin #endif 944887Schin va_end(ap); 954887Schin return(op); 964887Schin } 974887Schin 984887Schin #endif 99