dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_rename.c
blobfe0a2847a4db03d37d1c719375d640a140e6148f
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <errno.h>
30 #include "libproc.h"
33 * rename() system call -- executed by subject process.
35 int
36 pr_rename(struct ps_prochandle *Pr, const char *old, const char *new)
38 sysret_t rval;
39 argdes_t argd[4];
40 argdes_t *adp;
41 int error;
43 if (Pr == NULL)
44 return (rename(old, new));
46 adp = &argd[0]; /* old fd argument */
47 adp->arg_value = AT_FDCWD;
48 adp->arg_object = NULL;
49 adp->arg_type = AT_BYVAL;
50 adp->arg_inout = AI_INPUT;
51 adp->arg_size = 0;
53 adp++; /* move to old argument */
54 adp->arg_value = 0;
55 adp->arg_object = (void *)old;
56 adp->arg_type = AT_BYREF;
57 adp->arg_inout = AI_INPUT;
58 adp->arg_size = strlen(old) + 1;
60 adp++; /* move to new fd argument */
61 adp->arg_value = AT_FDCWD;
62 adp->arg_object = NULL;
63 adp->arg_type = AT_BYVAL;
64 adp->arg_inout = AI_INPUT;
65 adp->arg_size = 0;
67 adp++; /* move to new argument */
68 adp->arg_value = 0;
69 adp->arg_object = (void *)new;
70 adp->arg_type = AT_BYREF;
71 adp->arg_inout = AI_INPUT;
72 adp->arg_size = strlen(new) + 1;
74 error = Psyscall(Pr, &rval, SYS_renameat, 4, &argd[0]);
76 if (error) {
77 errno = (error > 0) ? error : ENOSYS;
78 return (-1);
80 return (rval.sys_rval1);
84 * link() system call -- executed by subject process.
86 int
87 pr_link(struct ps_prochandle *Pr, const char *existing, const char *new)
89 sysret_t rval;
90 argdes_t argd[5];
91 argdes_t *adp;
92 int error;
94 if (Pr == NULL)
95 return (link(existing, new));
97 adp = &argd[0]; /* first directory fd argument */
98 adp->arg_value = AT_FDCWD;
99 adp->arg_object = NULL;
100 adp->arg_type = AT_BYVAL;
101 adp->arg_inout = AI_INPUT;
102 adp->arg_size = 0;
104 adp++; /* existing argument */
105 adp->arg_value = 0;
106 adp->arg_object = (void *)existing;
107 adp->arg_type = AT_BYREF;
108 adp->arg_inout = AI_INPUT;
109 adp->arg_size = strlen(existing) + 1;
111 adp++; /* second directory fd argument */
112 adp->arg_value = AT_FDCWD;
113 adp->arg_object = NULL;
114 adp->arg_type = AT_BYVAL;
115 adp->arg_inout = AI_INPUT;
116 adp->arg_size = 0;
118 adp++; /* new argument */
119 adp->arg_value = 0;
120 adp->arg_object = (void *)new;
121 adp->arg_type = AT_BYREF;
122 adp->arg_inout = AI_INPUT;
123 adp->arg_size = strlen(new) + 1;
125 adp++; /* flag argument */
126 adp->arg_value = 0;
127 adp->arg_object = NULL;
128 adp->arg_type = AT_BYVAL;
129 adp->arg_inout = AI_INPUT;
130 adp->arg_size = 0;
132 error = Psyscall(Pr, &rval, SYS_linkat, 5, &argd[0]);
134 if (error) {
135 errno = (error > 0) ? error : ENOSYS;
136 return (-1);
138 return (rval.sys_rval1);
142 * unlink() system call -- executed by subject process.
145 pr_unlink(struct ps_prochandle *Pr, const char *path)
147 sysret_t rval;
148 argdes_t argd[3];
149 argdes_t *adp;
150 int error;
152 if (Pr == NULL)
153 return (unlink(path));
155 adp = &argd[0]; /* directory fd argument */
156 adp->arg_value = AT_FDCWD;
157 adp->arg_object = NULL;
158 adp->arg_type = AT_BYVAL;
159 adp->arg_inout = AI_INPUT;
160 adp->arg_size = 0;
161 adp++; /* move to path argument */
163 adp->arg_value = 0;
164 adp->arg_object = (void *)path;
165 adp->arg_type = AT_BYREF;
166 adp->arg_inout = AI_INPUT;
167 adp->arg_size = strlen(path) + 1;
168 adp++; /* move to flags argument */
170 adp->arg_value = 0;
171 adp->arg_object = NULL;
172 adp->arg_type = AT_BYVAL;
173 adp->arg_inout = AI_INPUT;
174 adp->arg_size = 0;
176 error = Psyscall(Pr, &rval, SYS_unlinkat, 3, &argd[0]);
178 if (error) {
179 errno = (error > 0) ? error : ENOSYS;
180 return (-1);
182 return (rval.sys_rval1);