Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
615 serge 1
/****************************************************************************
2
*
3
*                            Open Watcom Project
4
*
5
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6
*
7
*  ========================================================================
8
*
9
*    This file contains Original Code and/or Modifications of Original
10
*    Code as defined in and that are subject to the Sybase Open Watcom
11
*    Public License version 1.0 (the 'License'). You may not use this file
12
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14
*    provided with the Original Code and Modifications, and is also
15
*    available at www.sybase.com/developer/opensource.
16
*
17
*    The Original Code and all software distributed under the License are
18
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22
*    NON-INFRINGEMENT. Please see the License for the specific language
23
*    governing rights and limitations under the License.
24
*
25
*  ========================================================================
26
*
27
* Description:  Implementation of _cmdname().
28
*
29
****************************************************************************/
30
 
31
 
32
#ifdef __WATCOMC__
33
    #include "variety.h"
34
#else
35
    #define _WCRTLINK
36
#endif
37
#include 
38
#include 
39
#include 
40
#include 
41
 
42
extern char **_argv;    /* argument vector */
43
 
44
/* NOTE: This file isn't used for QNX. It's got its own version. */
45
 
46
#ifdef __LINUX__
47
 
48
_WCRTLINK char *_cmdname( char *name )
49
{
50
    int save_errno = errno;
51
    int result = readlink( "/proc/self/exe", name, PATH_MAX );
52
 
53
    errno = save_errno;
54
 
55
    /* fall back to argv[0] if readlink doesn't work */
56
    if( result == -1 || result == PATH_MAX )
57
        return( strcpy( name, _argv[0] ) );
58
 
59
    /* readlink does not add a NUL so we need to do it ourselves */
60
    name[result] = '\0';
61
    return( name );
62
}
63
 
64
#else
65
 
66
_WCRTLINK char *_cmdname( char *name )
67
{
68
    return( strcpy( name, _argv[0] ) );
69
}
70
 
71
#endif