Created
March 22, 2013 07:44
-
-
Save eddix/5219617 to your computer and use it in GitHub Desktop.
Revisions
-
eddix created this gist
Mar 22, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ /* 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; }