From 5e1fa5cd4090f229a40903f13abf328e86271717 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 1 Nov 2013 02:22:12 +0000 Subject: [parseopt] Add parse_timeout() Parsing a timeout value (specified in milliseconds) into an internal timeout value measured in timer ticks is a common operation. Provide a parse_timeout() value to carry out this conversion automatically. Signed-off-by: Michael Brown --- src/core/parseopt.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/core') diff --git a/src/core/parseopt.c b/src/core/parseopt.c index 38b1f29f9..514508357 100644 --- a/src/core/parseopt.c +++ b/src/core/parseopt.c @@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include #include /** @file @@ -95,6 +96,27 @@ int parse_integer ( char *text, unsigned int *value ) { return 0; } +/** + * Parse timeout value (in ms) + * + * @v text Text + * @ret value Integer value + * @ret rc Return status code + */ +int parse_timeout ( char *text, unsigned long *value ) { + unsigned int value_ms; + int rc; + + /* Parse raw integer value */ + if ( ( rc = parse_integer ( text, &value_ms ) ) != 0 ) + return rc; + + /* Convert to a number of timer ticks */ + *value = ( ( value_ms * TICKS_PER_SEC ) / 1000 ); + + return 0; +} + /** * Parse network device name * -- cgit v1.2.3-55-g7522