/* Loki_Update - A tool for updating Loki products over the Internet Copyright (C) 2000 Loki Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. info@lokigames.com */ /* I modified this file a little, removing unneeded features and making the thing compile ( Andreas Umbach ) */ #include #include #include #include #ifndef macintosh #ifndef WIN32 # include #endif #endif #ifndef PATH_MAX #define PATH_MAX 8192 #endif #if !defined(WIN32) && !defined(macintosh) && !defined(__APPLE__) void goto_installpath(const char *argv0) { char temppath[PATH_MAX]; char datapath[PATH_MAX]; char *home; home = getenv("HOME"); if ( ! home ) { home = "."; } strncpy(temppath, argv0, PATH_MAX); if ( ! strrchr(temppath, '/') ) { char *path; char *last; int found; found = 0; path = getenv("PATH"); do { /* Initialize our filename variable */ temppath[0] = '\0'; /* Get next entry from path variable */ last = strchr(path, ':'); if ( ! last ) last = path+strlen(path); /* Perform tilde expansion */ if ( *path == '~' ) { strcpy(temppath, home); ++path; } /* Fill in the rest of the filename */ if ( last > (path+1) ) { strncat(temppath, path, (last-path)); strcat(temppath, "/"); } strcat(temppath, "./"); strcat(temppath, argv0); /* See if it exists, and update path */ if (access(temppath, X_OK) == 0) { ++found; } path = last+1; } while ( *last && !found ); } else { /* Increment argv0 to the basename */ argv0 = strrchr(argv0, '/')+1; } /* Now canonicalize it to a full pathname for the data path */ datapath[0] = '\0'; if ( realpath(temppath, datapath) ) { /* There should always be '/' in the path */ *(strrchr(datapath, '/')) = '\0'; } if ( ! *datapath || (chdir(datapath) < 0) ) { fprintf(stderr, "Couldn't change to install directory\n"); exit(1); /* OK: critical, installation corrupt */ } } #endif