Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Sep 2004 01:49:29 +0300
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: New libutil function: parse_capacity(3).
Message-ID:  <20040916224929.GA50482@gothmog.gr>
In-Reply-To: <20040916184201.GD30151@darkness.comp.waw.pl>
References:  <20040916184201.GD30151@darkness.comp.waw.pl>

next in thread | previous in thread | raw e-mail | index | archive | help

--vtzGhvizbBRQ85DL
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On 2004-09-16 20:42, Pawel Jakub Dawidek <pjd@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


--vtzGhvizbBRQ85DL
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="foo.c"

#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;
}

--vtzGhvizbBRQ85DL--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040916224929.GA50482>