|
|
1.1 root 1: /*
2: * find a file on a path in the environment, or a default path
3: * with an access priveledge.
4: *
5: * example: pathn("helpfile", "LIBPATH", ",,\lib", "r");
6: *
7: * Returns full path name.
8: */
9: #include <stdio.h>
10: #include <path.h>
11: #include <unistd.h>
12:
13: #define PATHSIZE 64
14:
15: char *getenv(), *path(), *strchr();
16:
17: char *
18: pathn(name, envpath, deflpath, acs)
19: char *name, *envpath, *deflpath, *acs;
20: {
21: register char *pathptr;
22:
23: if ((NULL == envpath) || (NULL == (pathptr = getenv(envpath))))
24: pathptr = deflpath;
25:
26: if (NULL == strchr(acs, 'w')) {
27: if ((pathptr = path(pathptr, name, R_OK)) == NULL)
28: return (name);
29: else
30: return (pathptr);
31: }
32: else {
33: register char *p, c;
34: static char fullname[PATHSIZE];
35:
36: if ((p = path(pathptr, name, W_OK)) == NULL) {
37: for (p = fullname; (c = *pathptr++) && c != LISTSEP;)
38: *p++ = c;
39: *p++ = PATHSEP;
40: strcpy(p, name);
41: return (fullname);
42: } else
43: return (p);
44: }
45: }
46: #ifdef TEST
47: #include <misc.h>
48:
49: main()
50: {
51: char name[80], envpath[80], deflpath[80], acs[80];
52:
53: for (;;) {
54: ask(name, "file name");
55: if ('q' == name[0])
56: return(0);
57: ask(envpath, "env");
58: ask(deflpath, "path");
59: ask(acs, "acs");
60: printf("found %s\n", pathn(name, envpath, deflpath, acs));
61: }
62: }
63: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.