String GetExeFilePath() { static String exepath; ONCELOCK { const char *exe = procexepath_(); if(*exe) exepath = exe; else { String x = Argv0__; if(IsFullPath(x) && FileExists(x)) exepath = x; else { exepath = GetHomeDirFile("upp"); Vector<String> p = Split(FromSystemCharset(Environment().Get("PATH")), ':'); if(x.Find('/') >= 0) p.Add(GetCurrentDirectory()); for(int i = 0; i < p.GetCount(); i++) { String ep = NormalizePath(AppendFileName(p[i], x)); if(FileExists(ep)) exepath = ep; } } } } return exepath; }
static void sLogFile(char *fn, const char *app = ".log") { char *path = fn; const char *ehome = getenv("HOME"); strcpy(fn, ehome ? ehome : "/root"); if(!*fn || (fn += strlen(fn))[-1] != '/') *fn++ = '/'; *fn = '\0'; strcat(path, ".upp/"); const char *exe = procexepath_(); if(!*exe) exe = Argv0__; const char *q = strrchr(exe, '/'); if(q) exe = q + 1; if(!*exe) exe = "upp"; strcat(path, exe); mkdir(path, 0755); strcat(path, "/"); strcat(path, exe); strcat(path, app); }