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
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]
23 * Copyright (c) 1994, by Sun Microsytems, Inc.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * interfaces to find an executable (from libc code)
32 /* Copyright (c) 1988 AT&T */
33 /* All Rights Reserved */
41 #include <sys/types.h>
44 #include "prb_proc_int.h"
46 static const char *exec_cat(const char *s1
, const char *s2
, char *si
);
49 find_executable(const char *name
, char *ret_path
)
52 char fname
[PATH_MAX
+ 2];
57 return (prb_status_map(ENOENT
));
59 if ((pathstr
= getenv("PATH")) == NULL
) {
60 if (geteuid() == 0 || getuid() == 0)
61 pathstr
= "/usr/sbin:/usr/bin";
63 pathstr
= "/usr/bin:";
65 cp
= strchr(name
, '/') ? (const char *) "" : pathstr
;
68 cp
= exec_cat(cp
, name
, fname
);
69 if (stat(fname
, &stat_buf
) != -1) {
70 /* successful find of the file */
71 (void) strncpy(ret_path
, fname
, PATH_MAX
+ 2);
72 return (PRB_STATUS_OK
);
76 return (prb_status_map(ENOENT
));
82 exec_cat(const char *s1
, const char *s2
, char *si
)
85 /* number of characters in s2 */
86 int cnt
= PATH_MAX
+ 1;
89 while (*s1
&& *s1
!= ':') {
96 if (si
!= s
&& cnt
> 0) {
100 while (*s2
&& cnt
> 0) {
105 return (*s1
? ++s1
: 0);