Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
New pkg_config_int64 + new option: FETCH_RETRY default to 3
Baptiste Daroussin committed 13 years ago
commit 0c07dc2c3935e3e8883cc630d1d94ff3ab5160ea
parent f73a80c
2 files changed +35 -0
modified libpkg/pkg.h
@@ -257,6 +257,7 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_DEVELOPER_MODE = 14,
	PKG_CONFIG_PORTAUDIT_SITE = 15,
	PKG_CONFIG_SRV_MIRROR = 16,
+
	PKG_CONFIG_FETCH_RETRY = 17,
} pkg_config_key;

typedef enum {
@@ -838,6 +839,7 @@ int pkg_config_string(pkg_config_key key, const char **value);
int pkg_config_bool(pkg_config_key key, bool *value);
int pkg_config_list(pkg_config_key key, struct pkg_config_kv **kv);
const char *pkg_config_kv_get(struct pkg_config_kv *kv, pkg_config_kv_t type);
+
int pkg_config_int64(pkg_config_key key, int64_t *value);

/**
 * @todo Document
modified libpkg/pkg_config.c
@@ -42,6 +42,7 @@
#define STRING 0
#define BOOL 1
#define LIST 2
+
#define INTEGER 3

struct pkg_config_kv {
	char *key;
@@ -164,6 +165,12 @@ static struct config_entry c[] = {
		"NO",
		{ NULL }
	},
+
	[PKG_CONFIG_FETCH_RETRY] = {
+
		INTEGER,
+
		"FETCH_RETRY",
+
		"3",
+
		{ NULL }
+
	},
};

static bool parsed = false;
@@ -252,6 +259,32 @@ pkg_config_string(pkg_config_key key, const char **val)
}

int
+
pkg_config_int64(pkg_config_key key, int64_t *val)
+
{
+
	const char *errstr = NULL;
+

+
	*val = 0;
+

+
	if (parsed != true) {
+
		pkg_emit_error("pkg_init() must be called before pkg_config_int64()");
+
		return (EPKG_FATAL);
+
	}
+

+
	if (c[key].type != INTEGER) {
+
		pkg_emit_error("this config entry is not an integer");
+
		return (EPKG_FATAL);
+
	}
+
	if (c[key].val != NULL) {
+
		*val = strtonum(c[key].val, 0, INT64_MAX, &errstr);
+
		if (errstr != NULL) {
+
			pkg_emit_error("Unable to convert %s to int64: %s",
+
			    c[key].val, errstr);
+
		}
+
	}
+
	return (EPKG_OK);
+
}
+

+
int
pkg_config_bool(pkg_config_key key, bool *val)
{
	*val = false;