void shellexec(char **argv, char **envp, const char *path, int idx) { char *cmdname; int e; if (strchr(argv[0], '/') != NULL) { tryexec(argv[0], argv, envp); e = errno; } else { e = ENOENT; while ((cmdname = padvance(&path, argv[0])) != NULL) { if (--idx < 0 && pathopt == NULL) { tryexec(cmdname, argv, envp); if (errno != ENOENT && errno != ENOTDIR) e = errno; if (e == ENOEXEC) break; } stunalloc(cmdname); } } /* Map to POSIX errors */ if (e == ENOENT || e == ENOTDIR) { exerrno = 127; exerror(EXEXEC, "%s: not found", argv[0]); } else { exerrno = 126; exerror(EXEXEC, "%s: %s", argv[0], strerror(e)); } }
STATIC char * find_dot_file(char *basename) { char *fullname; const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ if (strchr(basename, '/')) return basename; while ((fullname = padvance(&path, basename)) != NULL) { if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { /* * Don't bother freeing here, since it will * be freed by the caller. */ return fullname; } stunalloc(fullname); } /* not found in the PATH */ error("%s: not found", basename); /* NOTREACHED */ }
void chkmail(void) { const char *mpath; char *p; char *q; time_t *mtp; struct stackmark smark; #ifdef WINDOWS struct stat statb; #else struct stat64 statb; #endif setstackmark(&smark); mpath = mpathset() ? mpathval() : mailval(); for (mtp = mailtime; mtp < mailtime + MAXMBOXES; mtp++) { p = padvance(&mpath, nullstr); if (p == NULL) break; if (*p == '\0') continue; for (q = p ; *q ; q++); #ifdef DEBUG if (q[-1] != '/') abort(); #endif q[-1] = '\0'; /* delete trailing '/' */ #ifdef WINDOWS if (stat(p, &statb) < 0) { #else if (stat64(p, &statb) < 0) { #endif *mtp = 0; continue; } if (!changed && statb.st_mtime != *mtp) { outfmt( &errout, snlfmt, pathopt ? pathopt : "you have mail" ); } *mtp = statb.st_mtime; } changed = 0; popstackmark(&smark); } void changemail(const char *val) { changed++; }
void chkmail(int32_t silent) { int32_t i; const_cstring_t mpath; cstring_t p; cstring_t q; struct stackmark smark; struct stat statb; if (silent) nmboxes = 10; if (nmboxes == 0) return; setstackmark(&smark); mpath = mpathset() ? mpathval() : mailval(); for (i = 0 ; i < nmboxes ; i++) { p = padvance(&mpath, nullstr); if (p == NULL) break; if (*p == '\0') continue; for (q = p ; *q ; q++); if (q[-1] != '/') abort(); q[-1] = '\0'; /* delete trailing '/' */ #ifdef notdef /* this is what the System V shell claims to do (it lies) */ if (stat(p, &statb) < 0) statb.st_mtime = 0; if (statb.st_mtime > mailtime[i] && ! silent) { out2str(pathopt ? pathopt : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_mtime; #else /* this is what it should do */ if (stat(p, &statb) < 0) statb.st_size = 0; if (statb.st_size > mailtime[i] && ! silent) { out2str(pathopt ? pathopt : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_size; #endif } nmboxes = i; popstackmark(&smark); }
static const char * find_dot_file(const char *basename) { static char localname[FILENAME_MAX+1]; char *fullname; const char *path = pathval(); struct stat statb; /* don't try this for absolute or relative paths */ if( strchr(basename, '/')) return basename; while ((fullname = padvance(&path, basename)) != NULL) { strcpy(localname, fullname); stunalloc(fullname); if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) return localname; } return basename; }
void shellexec(char **argv, char **envp, char *path, int index) { char *cmdname; int e; if (strchr(argv[0], '/') != NULL) { tryexec(argv[0], argv, envp); e = errno; } else { e = ENOENT; while ((cmdname = padvance(&path, argv[0])) != NULL) { if (--index < 0 && pathopt == NULL) { tryexec(cmdname, argv, envp); if (errno != ENOENT && errno != ENOTDIR) e = errno; } stunalloc(cmdname); } } /* Map to POSIX errors */ switch (e) { case EACCES: exerrno = 126; break; case ENOENT: exerrno = 127; break; default: exerrno = 2; break; } if (e == ENOENT || e == ENOTDIR) exerror(EXEXEC, "%s: not found", argv[0]); exerror(EXEXEC, "%s: %s", argv[0], strerror(e)); }