xref: /titanic_50/usr/src/lib/libc/port/sys/fcntl.c (revision 0e42dee69ed771bf604dd1789fca9d77b5bbe302)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include "synonyms.h"
33 #include <sys/param.h>
34 #include <sys/sockio.h>
35 #include <sys/filio.h>
36 #include <sys/file.h>
37 #include <sys/types.h>
38 #include <sys/fcntl.h>
39 #include <signal.h>
40 #include <sys/stat.h>
41 #include <sys/stropts.h>
42 #include <sys/socket.h>
43 #include <sys/stropts.h>
44 #include <sys/stream.h>
45 #include <sys/socketvar.h>
46 #include <sys/syscall.h>
47 #include <errno.h>
48 #include <stdio.h>
49 #include <stdarg.h>
50 #include <unistd.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include "libc.h"
54 
55 extern int __fcntl(int fd, int cmd, intptr_t arg);
56 
57 #if !defined(_LP64)
58 /*
59  * XXX these hacks are needed for X.25 which assumes that s_fcntl and
60  * s_ioctl exist in the socket library.
61  * There is no need for a _s_ioctl for other purposes.
62  */
63 #pragma weak s_fcntl = _fcntl
64 #pragma weak _s_fcntl = _fcntl
65 #pragma weak s_ioctl = _s_ioctl
66 
67 int
68 _s_ioctl(int fd, int cmd, intptr_t arg)
69 {
70 	return (ioctl(fd, cmd, arg));
71 }
72 /* End XXX */
73 #endif	/* _LP64 */
74 
75 int
76 _fcntl(int fd, int cmd, ...)
77 {
78 	int	res;
79 	int	pid;
80 	intptr_t arg;
81 	va_list ap;
82 
83 	va_start(ap, cmd);
84 	arg = va_arg(ap, intptr_t);
85 	va_end(ap);
86 
87 	switch (cmd) {
88 	case F_SETOWN:
89 		pid = (int)arg;
90 		return (ioctl(fd, FIOSETOWN, &pid));
91 
92 	case F_GETOWN:
93 		if (ioctl(fd, FIOGETOWN, &res) < 0)
94 			return (-1);
95 		return (res);
96 
97 	default:
98 		return (__fcntl(fd, cmd, arg));
99 	}
100 }
101