dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / comp / fcntl.c
blob5573da3fe9e98d47c5ca2b55be345a99396ea584
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
25 * -last fcntl
28 #include <ast.h>
30 #ifndef fcntl
32 NoN(fcntl)
34 #else
36 #include <ls.h>
37 #include <ast_tty.h>
38 #include <error.h>
40 #if F_SETFD >= _ast_F_LOCAL
41 #if _sys_filio
42 #include <sys/filio.h>
43 #endif
44 #endif
46 #if _lib_fcntl
47 #undef fcntl
48 extern int fcntl(int, int, ...);
49 #endif
51 int
52 _ast_fcntl(int fd, int op, ...)
54 int n;
55 int save_errno;
56 struct stat st;
57 va_list ap;
59 save_errno = errno;
60 va_start(ap, op);
61 if (op >= _ast_F_LOCAL) switch (op)
63 #if F_DUPFD >= _ast_F_LOCAL
64 case F_DUPFD:
65 n = va_arg(ap, int);
66 op = dup2(fd, n);
67 break;
68 #endif
69 #if F_GETFL >= _ast_F_LOCAL
70 case F_GETFL:
71 op = fstat(fd, &st);
72 break;
73 #endif
74 #if F_SETFD >= _ast_F_LOCAL && defined(FIOCLEX)
75 case F_SETFD:
76 n = va_arg(ap, int);
77 op = ioctl(fd, n == FD_CLOEXEC ? FIOCLEX : FIONCLEX, 0);
78 break;
79 #endif
80 default:
81 errno = EINVAL;
82 op = -1;
83 break;
85 else
86 #if _lib_fcntl
87 op = fcntl(fd, op, va_arg(ap, int));
88 #else
90 errno = EINVAL;
91 op = -1;
93 #endif
94 va_end(ap);
95 return(op);
98 #endif