Annotation of coherent/e/lib/misc/pathn.c, revision 1.1.1.1

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: 
                     12: #define PATHSIZE 64
                     13: 
                     14: char   *getenv(), *path(), *strchr();
                     15: 
                     16: char *
                     17: pathn(name, envpath, deflpath, acs)
                     18: char *name, *envpath, *deflpath, *acs;
                     19: {
                     20:        register char *pathptr;
                     21: 
                     22:        if ((NULL == envpath) || (NULL == (pathptr = getenv(envpath))))
                     23:                pathptr = deflpath;
                     24: 
                     25:        if (NULL == strchr(acs, 'w')) {
                     26:                if ((pathptr = path(pathptr, name, AREAD)) == NULL)
                     27:                        return (name);
                     28:                else
                     29:                        return (pathptr);
                     30:        }
                     31:        else {
                     32:                register char *p, c;
                     33:                static char fullname[PATHSIZE];
                     34: 
                     35:                if ((p = path(pathptr, name, AWRITE)) == NULL) {
                     36:                        for (p = fullname; (c = *pathptr++) && c != LISTSEP;)
                     37:                                *p++ = c;
                     38:                        *p++ = PATHSEP;
                     39:                        strcpy(p, name);
                     40:                        return (fullname);
                     41:                } else
                     42:                        return (p);
                     43:        }
                     44: }
                     45: #ifdef TEST
                     46: #include <misc.h>
                     47: 
                     48: main()
                     49: {
                     50:        char name[80], envpath[80], deflpath[80], acs[80];
                     51: 
                     52:        for (;;) {
                     53:                ask(name, "file name");
                     54:                if ('q' == name[0])
                     55:                        return(0);
                     56:                ask(envpath, "env");
                     57:                ask(deflpath, "path");
                     58:                ask(acs,  "acs");
                     59:                printf("found %s\n", pathn(name, envpath, deflpath, acs));
                     60:        }
                     61: }
                     62: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.