Changeset 5721


Ignore:
Timestamp:
Apr 29, 2008, 3:36:14 AM (14 years ago)
Author:
charles
Message:

use basename() to parse argv0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/misc.c

    r5715 r5721  
    2828#include <errno.h>
    2929#include <fcntl.h>
     30#include <libgen.h> /* basename */
    3031#include <stdlib.h>
    3132#include <stdio.h>
     
    4546setmyname( const char * argv0 )
    4647{
    47     const char * name;
    48 
    49     name = strrchr( argv0, '/' );
    50     if( NULL == name || '\0' == *(++name) )
    51     {
    52         name = argv0;
    53     }
    54     strlcpy( gl_myname, name, sizeof gl_myname );
     48    char tmp[MAX_PATH_LENGTH];
     49    strlcpy( tmp, argv0, sizeof( tmp ) );
     50    strlcpy( gl_myname, basename( tmp ), sizeof( gl_myname ) );
    5551}
    5652
Note: See TracChangeset for help on using the changeset viewer.