mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 08:16:59 +00:00
dhcpd-pools.h: portable program_invocation_short_name
The program_invocation_short_name portability code is copied from util-linux project almost as is. Reported-by: Roar Pettersen <rope1968@gmail.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
a10396710e
commit
d54721b3a4
2 changed files with 53 additions and 5 deletions
|
|
@ -24,13 +24,46 @@
|
|||
#define _POSIX_SOURCE 1
|
||||
#define POSIXLY_CORRECT 1
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
extern void exit();
|
||||
extern char *malloc();
|
||||
#endif /* STDC_HEADERS */
|
||||
|
||||
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
|
||||
# ifdef HAVE___PROGNAME
|
||||
extern char *__progname;
|
||||
# define program_invocation_short_name __progname
|
||||
# else /* HAVE___PROGNAME */
|
||||
# ifdef HAVE_GETEXECNAME
|
||||
# include <stdlib.h>
|
||||
# define program_invocation_short_name \
|
||||
prog_inv_sh_nm_from_file(getexecname(), 0)
|
||||
# else /* HAVE_GETEXECNAME */
|
||||
# define program_invocation_short_name \
|
||||
prog_inv_sh_nm_from_file(__FILE__, 1)
|
||||
# endif /* HAVE_PROGRAM_INVOCATION_SHORT_NAME */
|
||||
static char prog_inv_sh_nm_buf[256];
|
||||
static inline char *prog_inv_sh_nm_from_file(char *f, char stripext)
|
||||
{
|
||||
char *t;
|
||||
if ((t = strrchr(f, '/')) != NULL) {
|
||||
t++;
|
||||
} else {
|
||||
t = f;
|
||||
}
|
||||
strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
|
||||
prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
|
||||
|
||||
if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL) {
|
||||
*t = '\0';
|
||||
}
|
||||
return prog_inv_sh_nm_buf;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Structures and unions */
|
||||
struct configuration_t {
|
||||
char *dhcpdconf_file;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue