#include <unistd.h>
#include <sys/param.h>
#include <stdio.h>
main(int argc, char *argv[]) {
    char buffer[MAXPATHLEN];
    char *prog_name;

    if(getcwd(buffer, MAXPATHLEN)) {
	printf("%s\n", buffer);
	exit(0);
    }

    /* kill the pathname from argv[0] */
    prog_name = argv[0];
    while(*prog_name)
	prog_name++;
    while(prog_name > argv[0] && prog_name[-1] != '/')
	prog_name--;

    perror(prog_name);
    exit(1);
}
