diff options
author | Remi Collet <remi@remirepo.net> | 2024-12-19 09:08:31 +0100 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2024-12-19 09:08:31 +0100 |
commit | 8997cc9cfca46c31d20a8e91372d63536f19ef0c (patch) | |
tree | 405dfdb8633845faa8ca151b77885fa15d2493af /rpminfo.c | |
parent | deb0dd428220509aa74242a230586065c3df53ff (diff) |
add rpmexpand, rpmexpandnumeric to retrieve rpm macro value
add rpmdefine to set rpm macro value
Diffstat (limited to 'rpminfo.c')
-rw-r--r-- | rpminfo.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -30,6 +30,7 @@ #include <rpm/rpmio.h> #include <rpm/rpmlib.h> #include <rpm/rpmts.h> +#include <rpm/rpmmacro.h> #include "php_rpminfo.h" @@ -867,6 +868,64 @@ PHP_FUNCTION(rpmgetsymlink) } /* }}} */ +/* {{{ proto array rpmexpand(string $text): string + Expand macro in text */ +PHP_FUNCTION(rpmexpand) +{ + char *text, *result; + size_t len; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpand(text, NULL); + RETVAL_STRING(result); + free(result); +} +/* }}} */ + +/* {{{ proto array rpmexpandnumeric(string $text): int + Expand macro in text */ +PHP_FUNCTION(rpmexpandnumeric) +{ + char *text; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &text, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmExpandNumeric(text); + + RETURN_LONG(result); +} +/* }}} */ + +/* {{{ proto array rpmdefine(string $macro): bool + Define a new macro */ +PHP_FUNCTION(rpmdefine) +{ + char *macro; + size_t len; + int result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", ¯o, &len) == FAILURE) { + RETURN_THROWS(); + } + + (void)rpminfo_getts(); // read config files + + result = rpmDefineMacro(NULL, macro, RMIL_GLOBAL); + + RETURN_BOOL(result == 0); +} +/* }}} */ /* {{{ PHP_MINIT_FUNCTION */ |