use basename() to parse argv0
This commit is contained in:
parent
b05c7820c2
commit
ad817bae7f
|
@ -27,6 +27,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <libgen.h> /* basename */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -44,14 +45,9 @@ static char gl_myname[256];
|
||||||
void
|
void
|
||||||
setmyname( const char * argv0 )
|
setmyname( const char * argv0 )
|
||||||
{
|
{
|
||||||
const char * name;
|
char tmp[MAX_PATH_LENGTH];
|
||||||
|
strlcpy( tmp, argv0, sizeof( tmp ) );
|
||||||
name = strrchr( argv0, '/' );
|
strlcpy( gl_myname, basename( tmp ), sizeof( gl_myname ) );
|
||||||
if( NULL == name || '\0' == *(++name) )
|
|
||||||
{
|
|
||||||
name = argv0;
|
|
||||||
}
|
|
||||||
strlcpy( gl_myname, name, sizeof gl_myname );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
Loading…
Reference in New Issue