dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_ioctl.c
blobc33f778031699783e750f46017aab8a76aa36cc7
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include "libproc.h"
36 * ioctl() system call -- executed by subject process.
38 int
39 pr_ioctl(struct ps_prochandle *Pr, int fd, int code, void *buf, size_t size)
41 sysret_t rval; /* return value from ioctl() */
42 argdes_t argd[3]; /* arg descriptors for ioctl() */
43 argdes_t *adp = &argd[0]; /* first argument */
44 int error;
46 if (Pr == NULL) /* no subject process */
47 return (ioctl(fd, code, buf));
49 adp->arg_value = fd;
50 adp->arg_object = NULL;
51 adp->arg_type = AT_BYVAL;
52 adp->arg_inout = AI_INPUT;
53 adp->arg_size = 0;
54 adp++; /* move to code argument */
56 adp->arg_value = code;
57 adp->arg_object = NULL;
58 adp->arg_type = AT_BYVAL;
59 adp->arg_inout = AI_INPUT;
60 adp->arg_size = 0;
61 adp++; /* move to buffer argument */
63 if (size == 0) {
64 adp->arg_value = (long)buf;
65 adp->arg_object = NULL;
66 adp->arg_type = AT_BYVAL;
67 adp->arg_inout = AI_INPUT;
68 adp->arg_size = 0;
69 } else {
70 adp->arg_value = 0;
71 adp->arg_object = buf;
72 adp->arg_type = AT_BYREF;
73 adp->arg_inout = AI_INOUT;
74 adp->arg_size = size;
77 error = Psyscall(Pr, &rval, SYS_ioctl, 3, &argd[0]);
79 if (error) {
80 errno = (error > 0)? error : ENOSYS;
81 return (-1);
83 return (rval.sys_rval1);