File: mych

package info (click to toggle)
gcl 2.6.14-19
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 60,804 kB
  • sloc: ansic: 177,407; lisp: 151,508; asm: 128,169; sh: 22,510; cpp: 11,923; tcl: 3,181; perl: 2,930; makefile: 2,360; sed: 334; yacc: 226; lex: 95; awk: 30; fortran: 24; csh: 23
file content (60 lines) | stat: -rwxr-xr-x 970 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from main.c
#else
	kcl_self = find_executable(argv[0]);
#endif


#ifdef NeXT
#include <fcntl.h>
#include <sys/stat.h>


static int
is_executable(fn)
    char *fn;
{
    struct stat s;

    return stat (fn, &s) != -1 && (s.st_mode & S_IFMT) == S_IFREG
	    && access (fn, X_OK) != -1;
}

char *
find_executable(fn)
    char *fn;
{
    char *path, *getenv();
    static char buf[MAXPATHLEN+1];
    static char msg[100];
    register char *p;

    for (p = fn; *p; p++) {
	if (*p == '/') {
	    if (is_executable (fn))
		return fn;
	    else {
		sprintf(msg, "%s is not executable", fn);
		error(msg);
	    }
	}
    }
    if ((path = getenv ("PATH")) == 0)
	error("PATH is undefined");
    do {
	p = buf;
	while (*path && *path != ':')
	    *p++ = *path++;
	if (*path)
	    ++path;
	if (p > buf)
	    *p++ = '/';
	strcpy (p, fn);
	if (is_executable (buf))
	    return buf;
    } while (*path);
    sprintf(msg, "cannot find pathname of %s", fn);
    error(msg);
}
#endif