abspath - determine absolute pathname

abspath (name,result)
char *name;
char *result;

Abspath places the absolute pathname of the string name into the
string result.

Abspath converts the pathname in the string name to an absolute
pathname by prepending the name of the current working directory if
necessary. Then the absolute pathname is compacted by removing and
resolving superfluous steps.

Null components, and components of "." are removed because they
have no effect on the meaning of the pathname.

Components of ".." are resolved by removing them together with the
preceding step. However, there are certain situations in which the
preceding step cannot be removed (for example, if there is no
preceding step) and in these cases the ".." will remain.

Abspath never returns an absolute pathname containing a trailing
slash except for the case "/".

Abspath calls getwd to obtain the name of the current working
directory when needed. To improve performance, the result from
getwd is saved so that getwd need not be invoked again during
subsequent calls on abspath.

The special invocation abspath(0,0) tells abspath to forget its
saved name of the current working directory. Abspath has no way of
knowing if the name of the current directory has changed, so if you
care about these things you must tell it. Otherwise, abspath will
continue to use its saved result from getwd and this will most
likely cause it to produce erroneous results.

pwd(1), chdir(2), getwd(3), path(3), expand(3)

Returns -1 on error (failure in getwd); 0 otherwise.

The string result is assumed to be large enough. Intermediate
calculations place a string in result that at most consists of the
name of the current working directory concatenated with the string
name plus two more characters.

If getwd fails, abspath gives up and returns -1. Generally,
failures in getwd are pretty catastrophic.

If you call chdir or if the name of the current directory changes
for some other reason, abspath will most likely produce incorrect
results for relative path names until you call abspath(0,0).

Should getwd return a name for the current working directory that
does not begin with a slash, abspath will produce a result pathname
string that it considers to be a reasonable interpretation of the
situation. This is not expected to happen, but abspath is