ref: c1b943384c1cf8bddbad7df63319d597710f943d
parent: d6a35f12c5156009d35534fb9bb3d59a541d2e2c
author: Ori Bernstein <[email protected]>
date: Sat Sep 9 17:00:56 EDT 2023
5e: handle path as expected
--- a/5e.c
+++ b/5e.c
@@ -87,7 +87,7 @@
static void
dotext(int argc, char **argv)
{
- char *file;
+ char *file, **p, *path[] = {"/bin", ".", nil};
if(**argv == '/' || **argv == '.' || **argv == '#') {
if(loadtext(*argv, argc, argv) < 0)
@@ -94,10 +94,15 @@
sysfatal("loadtext: %r");
return;
}
- file = smprint("/bin/%s", *argv);
- if(loadtext(file, argc, argv) < 0)
- sysfatal("loadtext: %r");
- free(file);
+ for(p = path; *p; p++){
+ file = smprint("%s/%s", *p, *argv);
+ if(loadtext(file, argc, argv) >= 0){
+ free(file);
+ return;
+ }
+ free(file);
+ }
+ sysfatal("loadtext: %r");
}
void