190926Snectar/*
2233294Sstas * Copyright (c) 1995-2004 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
490926Snectar * All rights reserved.
5233294Sstas *
690926Snectar * Redistribution and use in source and binary forms, with or without
790926Snectar * modification, are permitted provided that the following conditions
890926Snectar * are met:
9233294Sstas *
1090926Snectar * 1. Redistributions of source code must retain the above copyright
1190926Snectar *    notice, this list of conditions and the following disclaimer.
12233294Sstas *
1390926Snectar * 2. Redistributions in binary form must reproduce the above copyright
1490926Snectar *    notice, this list of conditions and the following disclaimer in the
1590926Snectar *    documentation and/or other materials provided with the distribution.
16233294Sstas *
1790926Snectar * 3. Neither the name of the Institute nor the names of its contributors
1890926Snectar *    may be used to endorse or promote products derived from this software
1990926Snectar *    without specific prior written permission.
20233294Sstas *
2190926Snectar * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2290926Snectar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2390926Snectar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2490926Snectar * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2590926Snectar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2690926Snectar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2790926Snectar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2890926Snectar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2990926Snectar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3090926Snectar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3190926Snectar * SUCH DAMAGE.
3290926Snectar */
3390926Snectar
3490926Snectar#include <config.h>
3590926Snectar
3690926Snectar#include "roken.h"
3790926Snectar
3890926Snectar#ifndef HAVE___PROGNAME
3990926Snectarextern const char *__progname;
4090926Snectar#endif
4190926Snectar
4290926Snectar#ifndef HAVE_SETPROGNAME
43233294Sstas
44233294SstasROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
4590926Snectarsetprogname(const char *argv0)
4690926Snectar{
47233294Sstas
4890926Snectar#ifndef HAVE___PROGNAME
49233294Sstas
50178825Sdfr    const char *p;
5190926Snectar    if(argv0 == NULL)
5290926Snectar	return;
5390926Snectar    p = strrchr(argv0, '/');
54233294Sstas
55233294Sstas#ifdef BACKSLASH_PATH_DELIM
56233294Sstas    {
57233294Sstas        const char * pb;
58233294Sstas
59233294Sstas        pb = strrchr((p != NULL)? p : argv0, '\\');
60233294Sstas        if (pb != NULL)
61233294Sstas            p = pb;
62233294Sstas    }
63233294Sstas#endif
64233294Sstas
6590926Snectar    if(p == NULL)
66178825Sdfr	p = argv0;
6790926Snectar    else
6890926Snectar	p++;
69233294Sstas
70233294Sstas#ifdef _WIN32
71233294Sstas    {
72233294Sstas        char * fn = strdup(p);
73233294Sstas        char * ext;
74233294Sstas
75233294Sstas        strlwr(fn);
76233294Sstas        ext = strrchr(fn, '.');
77233294Sstas        if (ext != NULL && !strcmp(ext, ".exe"))
78233294Sstas            *ext = '\0';
79233294Sstas
80233294Sstas        __progname = fn;
81233294Sstas    }
82233294Sstas#else
83233294Sstas
8490926Snectar    __progname = p;
85233294Sstas
8690926Snectar#endif
87233294Sstas
88233294Sstas#endif  /* HAVE___PROGNAME */
8990926Snectar}
90233294Sstas
9190926Snectar#endif /* HAVE_SETPROGNAME */
92