Home | History | Annotate | Download | only in sys
      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 2008 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 "lint.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 <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_syscall(int fd, int cmd, ...);
     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 s_ioctl for other purposes.
     62  */
     63 #pragma weak s_fcntl = __fcntl
     64 #pragma weak _s_fcntl = __fcntl
     65 int
     66 s_ioctl(int fd, int cmd, intptr_t arg)
     67 {
     68 	return (ioctl(fd, cmd, arg));
     69 }
     70 #endif	/* _LP64 */
     71 
     72 int
     73 __fcntl(int fd, int cmd, ...)
     74 {
     75 	int	res;
     76 	int	pid;
     77 	intptr_t arg;
     78 	va_list ap;
     79 
     80 	va_start(ap, cmd);
     81 	arg = va_arg(ap, intptr_t);
     82 	va_end(ap);
     83 
     84 	switch (cmd) {
     85 	case F_SETOWN:
     86 		pid = (int)arg;
     87 		return (ioctl(fd, FIOSETOWN, &pid));
     88 
     89 	case F_GETOWN:
     90 		if (ioctl(fd, FIOGETOWN, &res) < 0)
     91 			return (-1);
     92 		return (res);
     93 
     94 	default:
     95 		return (__fcntl_syscall(fd, cmd, arg));
     96 	}
     97 }
     98