178556Sobrien/* 278556Sobrien * Copyright (c) 1995-2004 Kungliga Tekniska H��gskolan 378556Sobrien * (Royal Institute of Technology, Stockholm, Sweden). 478556Sobrien * All rights reserved. 578556Sobrien * 678556Sobrien * Redistribution and use in source and binary forms, with or without 7167978Sdelphij * modification, are permitted provided that the following conditions 8167978Sdelphij * are met: 9167978Sdelphij * 1078556Sobrien * 1. Redistributions of source code must retain the above copyright 11215041Sobrien * notice, this list of conditions and the following disclaimer. 12215041Sobrien * 1378556Sobrien * 2. Redistributions in binary form must reproduce the above copyright 14167978Sdelphij * notice, this list of conditions and the following disclaimer in the 15167978Sdelphij * documentation and/or other materials provided with the distribution. 1678556Sobrien * 17167978Sdelphij * 3. Neither the name of the Institute nor the names of its contributors 18167978Sdelphij * may be used to endorse or promote products derived from this software 19167978Sdelphij * without specific prior written permission. 2078556Sobrien * 21167978Sdelphij * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22167978Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2378556Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24167978Sdelphij * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25167978Sdelphij * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26167978Sdelphij * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27167978Sdelphij * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28167978Sdelphij * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29167978Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3078556Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31146788Ssobomax * SUCH DAMAGE. 32146788Ssobomax */ 33146788Ssobomax 3478556Sobrien#include <config.h> 3578556Sobrien 36146788Ssobomax#include "roken.h" 3778556Sobrien 3878556Sobrien#ifndef HAVE___PROGNAME 3978556Sobrienextern const char *__progname; 4078556Sobrien#endif 4178556Sobrien 4278556Sobrien#ifndef HAVE_SETPROGNAME 4378556Sobrien 4478556SobrienROKEN_LIB_FUNCTION void ROKEN_LIB_CALL 4578556Sobriensetprogname(const char *argv0) 4678556Sobrien{ 4778556Sobrien 4878556Sobrien#ifndef HAVE___PROGNAME 4978556Sobrien 50146293Sobrien const char *p; 5178556Sobrien if(argv0 == NULL) 5278556Sobrien return; 5378556Sobrien p = strrchr(argv0, '/'); 5478556Sobrien 55177424Sdelphij#ifdef BACKSLASH_PATH_DELIM 5678556Sobrien { 5778556Sobrien const char * pb; 5878556Sobrien 5990067Ssobomax pb = strrchr((p != NULL)? p : argv0, '\\'); 6090067Ssobomax if (pb != NULL) 6190067Ssobomax p = pb; 6290067Ssobomax } 6390067Ssobomax#endif 6490067Ssobomax 6590067Ssobomax if(p == NULL) 6690067Ssobomax p = argv0; 6790067Ssobomax else 6890067Ssobomax p++; 6990067Ssobomax 7090067Ssobomax#ifdef _WIN32 7190067Ssobomax { 7290067Ssobomax char * fn = strdup(p); 7390067Ssobomax char * ext; 7490067Ssobomax 7590067Ssobomax strlwr(fn); 7690067Ssobomax ext = strrchr(fn, '.'); 7790067Ssobomax if (ext != NULL && !strcmp(ext, ".exe")) 7890067Ssobomax *ext = '\0'; 7990067Ssobomax 8090067Ssobomax __progname = fn; 8190067Ssobomax } 8290067Ssobomax#else 8390067Ssobomax 8490067Ssobomax __progname = p; 8590067Ssobomax 8690067Ssobomax#endif 8790067Ssobomax 8878556Sobrien#endif /* HAVE___PROGNAME */ 8978556Sobrien} 9078556Sobrien 9178556Sobrien#endif /* HAVE_SETPROGNAME */ 92146788Ssobomax