New libutil function: parse_capacity(3).

Giorgos Keramidas keramida at freebsd.org
Thu Sep 16 15:51:39 PDT 2004


On 2004-09-16 20:42, Pawel Jakub Dawidek <pjd at freebsd.org> wrote:
> http://people.freebsd.org/~pjd/patches/parse_capacity.patch
> Any comments before committing?

Is it intentional that it works even for "negative" capacities?

: $ ./foo
:        -10 fffffffffffffff6 |        -10 fffffffffffffff6
:     -10240 ffffffffffffd800 |       -10k ffffffffffffd800

-------------- next part --------------
#include <sys/types.h>
#include <stdio.h>

struct data {
	off_t		d_off;
	const char	*d_str;
};

static struct data v[] = {
	{ -10,		"-10" },
	{ -10 * 1024,	"-10k" },
};
static const size_t	vlen = sizeof(v) / sizeof(v[0]);

extern off_t parse_capacity(const char *capacity);
static void foo(const struct data *);

static void
foo(const struct data *dp)
{
	off_t	val;

	val = parse_capacity(dp->d_str);
	printf("%10lld %016llx | %10s %016llx\n", dp->d_off, dp->d_off,
	    dp->d_str, (unsigned long long)val);
}

int
main(void)
{
	size_t k;

	for (k = 0; k < vlen; k++)
		foo(v + k);
	return 0;
}


More information about the freebsd-arch mailing list