clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -38,54 +38,51 @@
* POSIX C function: exec a program on the search path. Tries
* execv() repeatedly until one of the choices works.
*/
int
execvp(const char *prog, char *const *args)
{
const char *searchpath, *s, *t;
char progpath[PATH_MAX];
size_t len;
int execvp(const char *prog, char *const *args) {
const char *searchpath, *s, *t;
char progpath[PATH_MAX];
size_t len;
if (strchr(prog, '/') != NULL) {
execv(prog, args);
return -1;
}
if (strchr(prog, '/') != NULL) {
execv(prog, args);
return -1;
}
searchpath = getenv("PATH");
if (searchpath == NULL) {
errno = ENOENT;
return -1;
}
searchpath = getenv("PATH");
if (searchpath == NULL) {
errno = ENOENT;
return -1;
}
for (s = searchpath; s != NULL; s = t) {
t = strchr(s, ':');
if (t != NULL) {
len = t - s;
/* advance past the colon */
t++;
}
else {
len = strlen(s);
}
if (len == 0) {
continue;
}
if (len >= sizeof(progpath)) {
continue;
}
memcpy(progpath, s, len);
snprintf(progpath + len, sizeof(progpath) - len, "/%s", prog);
execv(progpath, args);
switch (errno) {
case ENOENT:
case ENOTDIR:
case ENOEXEC:
/* routine errors, try next dir */
break;
default:
/* oops, let's fail */
return -1;
}
}
errno = ENOENT;
return -1;
for (s = searchpath; s != NULL; s = t) {
t = strchr(s, ':');
if (t != NULL) {
len = t - s;
/* advance past the colon */
t++;
} else {
len = strlen(s);
}
if (len == 0) {
continue;
}
if (len >= sizeof(progpath)) {
continue;
}
memcpy(progpath, s, len);
snprintf(progpath + len, sizeof(progpath) - len, "/%s", prog);
execv(progpath, args);
switch (errno) {
case ENOENT:
case ENOTDIR:
case ENOEXEC:
/* routine errors, try next dir */
break;
default:
/* oops, let's fail */
return -1;
}
}
errno = ENOENT;
return -1;
}