xref: /titanic_44/usr/src/lib/libproc/common/pr_rename.c (revision 2b4a78020b9c38d1b95e2f3fefa6d6e4be382d1f)
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 (c) 1998-2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <errno.h>
33 #include "libproc.h"
34 
35 /*
36  * rename() system call -- executed by subject process.
37  */
38 int
39 pr_rename(struct ps_prochandle *Pr, const char *old, const char *new)
40 {
41 	sysret_t rval;
42 	argdes_t argd[2];
43 	argdes_t *adp;
44 	int error;
45 
46 	if (Pr == NULL)
47 		return (rename(old, new));
48 
49 	adp = &argd[0];		/* old argument */
50 	adp->arg_value = 0;
51 	adp->arg_object = (void *)old;
52 	adp->arg_type = AT_BYREF;
53 	adp->arg_inout = AI_INPUT;
54 	adp->arg_size = strlen(old) + 1;
55 
56 	adp++;			/* new argument */
57 	adp->arg_value = 0;
58 	adp->arg_object = (void *)new;
59 	adp->arg_type = AT_BYREF;
60 	adp->arg_inout = AI_INPUT;
61 	adp->arg_size = strlen(new) + 1;
62 
63 	error = Psyscall(Pr, &rval, SYS_rename, 2, &argd[0]);
64 
65 	if (error) {
66 		errno = (error > 0) ? error : ENOSYS;
67 		return (-1);
68 	}
69 	return (rval.sys_rval1);
70 }
71 
72 /*
73  * link() system call -- executed by subject process.
74  */
75 int
76 pr_link(struct ps_prochandle *Pr, const char *existing, const char *new)
77 {
78 	sysret_t rval;
79 	argdes_t argd[2];
80 	argdes_t *adp;
81 	int error;
82 
83 	if (Pr == NULL)
84 		return (link(existing, new));
85 
86 	adp = &argd[0];		/* existing argument */
87 	adp->arg_value = 0;
88 	adp->arg_object = (void *)existing;
89 	adp->arg_type = AT_BYREF;
90 	adp->arg_inout = AI_INPUT;
91 	adp->arg_size = strlen(existing) + 1;
92 
93 	adp++;			/* new argument */
94 	adp->arg_value = 0;
95 	adp->arg_object = (void *)new;
96 	adp->arg_type = AT_BYREF;
97 	adp->arg_inout = AI_INPUT;
98 	adp->arg_size = strlen(new) + 1;
99 
100 	error = Psyscall(Pr, &rval, SYS_link, 2, &argd[0]);
101 
102 	if (error) {
103 		errno = (error > 0) ? error : ENOSYS;
104 		return (-1);
105 	}
106 	return (rval.sys_rval1);
107 }
108 
109 /*
110  * unlink() system call -- executed by subject process.
111  */
112 int
113 pr_unlink(struct ps_prochandle *Pr, const char *path)
114 {
115 	sysret_t rval;
116 	argdes_t argd[1];
117 	argdes_t *adp;
118 	int error;
119 
120 	if (Pr == NULL)
121 		return (unlink(path));
122 
123 	adp = &argd[0];		/* path argument */
124 	adp->arg_value = 0;
125 	adp->arg_object = (void *)path;
126 	adp->arg_type = AT_BYREF;
127 	adp->arg_inout = AI_INPUT;
128 	adp->arg_size = strlen(path) + 1;
129 
130 	error = Psyscall(Pr, &rval, SYS_unlink, 1, &argd[0]);
131 
132 	if (error) {
133 		errno = (error > 0) ? error : ENOSYS;
134 		return (-1);
135 	}
136 	return (rval.sys_rval1);
137 }
138