1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
26 #include <sys/types.h>
29 #define __environ environ
32 /* Execute FILE, searching in the `PATH' environment variable if it contains
33 no slashes, with arguments ARGV and environment from `environ'. */
35 DEFUN(execvp
, (file
, argv
), CONST
char *file AND
char *CONST argv
[])
37 if (strchr (file
, '/') == NULL
)
45 gid_t groups
[NGROUPS_MAX
];
48 path
= getenv ("PATH");
51 /* There is no `PATH' in the environment.
52 The default search path is the current directory
53 followed by the path `confstr' returns for `_CS_PATH'. */
54 len
= confstr (_CS_PATH
, (char *) NULL
, 0);
55 path
= (char *) __alloca (1 + len
);
57 (void) confstr (_CS_PATH
, path
+ 1, len
);
60 len
= strlen (file
) + 1;
61 name
= __alloca (strlen (path
) + len
);
64 ngroups
= getgroups (sizeof (groups
) / sizeof (groups
[0]), groups
);
69 p
= strchr (path
, ':');
71 p
= strchr (path
, '\0');
74 /* Two adjacent colons, or a colon at the beginning or the end
75 of `PATH' means to search the current directory. */
76 (void) memcpy (name
, file
, len
);
79 /* Construct the pathname to try. */
80 (void) memcpy (name
, path
, p
- path
);
82 (void) memcpy (&name
[(p
- path
) + 1], file
, len
);
84 if (stat (name
, &st
) == 0 && S_ISREG (st
.st_mode
))
89 else if (st
.st_gid
== gid
)
94 for (i
= 0; i
< ngroups
; ++i
)
95 if (st
.st_gid
== groups
[i
])
101 if (st
.st_mode
& bit
)
108 while (*p
++ != '\0');
111 return __execve (file
, argv
, __environ
);