/* app_path * * get application path, it need argv[0], and store the result to path. * * */ char * app_path(char * path, const char * argv0) { char buf[PATH_MAX]; char * pos; if (argv0[0] == '/') { // run with absolute path strcpy(buf, argv0); } else { // run with relative path if(NULL == getcwd(buf, PATH_MAX)) { perror("getcwd error"); return NULL; } strcat(buf, "/"); strcat(buf, argv0); } if (NULL == realpath(buf, path)) { perror("realpath error"); return NULL; } return path; }