← Back to context

Comment by age123456gpg

4 days ago

Here [1] is a related trick in the old Unix to run either `foo`, `/bin/foo` or `/usr/bin/foo` (apparently before `PATH` convention existed):

    char string[10000];
    strp = string;
    for (i=0; i<9; i++)
        *strp++ = "/usr/bin/"[i];
    p = *argv++;
    while(*strp++ = *p++);

    // string == "/usr/bin/foo"
    execv(string+9, args); // foo (execv returns only in case of error, i.e. when foo does not exist)
    execv(string+4, args); // /bin/foo
    execv(string, args);   // /usr/bin/foo

[1] https://github.com/dspinellis/unix-history-repo/blob/Researc...