mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 05:21:49 +03:00
[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 <mcb30@ipxe.org>
This commit is contained in:
@@ -30,6 +30,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
#include <ipxe/menu.h>
|
||||
#include <ipxe/settings.h>
|
||||
#include <ipxe/params.h>
|
||||
#include <ipxe/timer.h>
|
||||
#include <ipxe/parseopt.h>
|
||||
|
||||
/** @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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user