diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 79e5d10b51..f0c116f617 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -74,6 +74,10 @@ if(WITH_CAP) target_link_libraries(librpm PRIVATE PkgConfig::LIBCAP) endif() +if(NOT HAVE_SETPROGNAME AND NOT HAVE___PROGNAME) + target_link_libraries(librpm PRIVATE libmisc) +endif() + add_custom_command(OUTPUT tagtbl.inc COMMAND AWK=${AWK} ${CMAKE_CURRENT_SOURCE_DIR}/gentagtbl.sh ${CMAKE_SOURCE_DIR}/include/rpm/rpmtag.h > tagtbl.inc DEPENDS ${CMAKE_SOURCE_DIR}/include/rpm/rpmtag.h gentagtbl.sh diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 925d2ea952..3dbda4c47d 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -1,2 +1,2 @@ -add_library(libmisc OBJECT fts.c rpmfts.h) +add_library(libmisc OBJECT fts.c rpmfts.h rpmxprogname.c rpmxprogname.h) target_include_directories(libmisc PRIVATE ${Intl_INCLUDE_DIRS}) diff --git a/misc/rpmxprogname.c b/misc/rpmxprogname.c new file mode 100644 index 0000000000..edb7677f83 --- /dev/null +++ b/misc/rpmxprogname.c @@ -0,0 +1,31 @@ +/* Original author: Kamil Rytarowski + File: rpmxprogname.c + Date of creation: 2013-08-10 + License: the same as RPM itself */ + +#include "rpmxprogname.h" + +#include /* strrchr */ + +const char *_rpmxprogname = NULL; + +const char *_rpmxgetprogname(void) +{ + const char *empty = ""; + + if (_rpmxprogname != NULL) /* never return NULL string */ + return _rpmxprogname; + else + return empty; +} + +void _rpmxsetprogname(const char *pn) +{ + if (pn != NULL && _rpmxprogname == NULL /* set the value only once */) { + char *p = strrchr(pn, '/'); /* locate the last occurrence of '/' */ + if (p != NULL) + _rpmxprogname = p + 1 /* strip beginning '/' */; + else + _rpmxprogname = pn; + } +} diff --git a/misc/rpmxprogname.h b/misc/rpmxprogname.h new file mode 100644 index 0000000000..15c008634b --- /dev/null +++ b/misc/rpmxprogname.h @@ -0,0 +1,21 @@ +/* Original author: Kamil Rytarowski + File: rpmxprogname.c + Date of creation: 2013-08-10 + License: the same as RPM itself */ + +#ifndef _RPMXPROGNAME_H +#define _RPMXPROGNAME_H + +#ifdef __cplusplus +extern "C" { +#endif + +const char *_rpmxgetprogname(void); +void _rpmxsetprogname(const char *pn); + +#ifdef __cplusplus +} +#endif + +#endif /* _RPMXPROGNAME_H */ + diff --git a/misc/system.h b/misc/system.h index 36ea094cfa..53b3242583 100644 --- a/misc/system.h +++ b/misc/system.h @@ -85,8 +85,10 @@ extern int fdatasync(int fildes); # define xsetprogname(pn) extern const char *__progname; # define xgetprogname(pn) __progname -#else -# error "Did not find any sutable implementation of xsetprogname/xgetprogname" +#else /* Reimplement setprogname and getprogname */ +# include "rpmxprogname.h" +# define xsetprogname(pn) _rpmxsetprogname(pn) +# define xgetprogname() _rpmxgetprogname() #endif /* Take care of NLS matters. */