xref: /titanic_52/usr/src/lib/libc/port/sys/fcntl.c (revision 3f7d54a6b84904c8f4d8daa4c7b577bede7df8b9)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 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 #include "lint.h"
31 #include <sys/param.h>
32 #include <sys/sockio.h>
33 #include <sys/filio.h>
34 #include <sys/file.h>
35 #include <sys/types.h>
36 #include <fcntl.h>
37 #include <signal.h>
38 #include <sys/stat.h>
39 #include <sys/stropts.h>
40 #include <sys/socket.h>
41 #include <sys/stropts.h>
42 #include <sys/stream.h>
43 #include <sys/socketvar.h>
44 #include <sys/syscall.h>
45 #include <errno.h>
46 #include <stdio.h>
47 #include <stdarg.h>
48 #include <unistd.h>
49 #include <string.h>
50 #include <stdlib.h>
51 #include "libc.h"
52 
53 #if !defined(_LP64)
54 /*
55  * XXX these hacks are needed for X.25 which assumes that s_fcntl and
56  * s_ioctl exist in the socket library.
57  * There is no need for s_ioctl for other purposes.
58  */
59 #pragma weak s_fcntl = __fcntl
60 #pragma weak _s_fcntl = __fcntl
61 int
62 s_ioctl(int fd, int cmd, intptr_t arg)
63 {
64 	return (ioctl(fd, cmd, arg));
65 }
66 #endif	/* _LP64 */
67 
68 int
69 __fcntl(int fd, int cmd, ...)
70 {
71 	int	res;
72 	int	pid;
73 	intptr_t arg;
74 	va_list ap;
75 
76 	va_start(ap, cmd);
77 	arg = va_arg(ap, intptr_t);
78 	va_end(ap);
79 
80 	switch (cmd) {
81 	case F_SETOWN:
82 		pid = (int)arg;
83 		return (ioctl(fd, FIOSETOWN, &pid));
84 
85 	case F_GETOWN:
86 		if (ioctl(fd, FIOGETOWN, &res) < 0)
87 			return (-1);
88 		return (res);
89 
90 	default:
91 		return (syscall(SYS_fcntl, fd, cmd, arg));
92 	}
93 }
94