nbdkit_parse_delay3
Parse human-readable delays and sleeps for nbdkit
Usage
#include <nbdkit-plugin.h>int nbdkit_parse_delay (const char *what, const char *str,unsigned *sec, unsigned *nsec);
Overview
The utility function "nbdkit_parse_delay" can be used to parse configuration parameters on the nbdkit(1) command line specifying delays and sleeps.
The "str" parameter is a string in one of the following formats:
- 1
- 1.2
- "1.2s"
-
Seconds
- "1.2ms"
- "120ms"
-
Milliseconds
- "1.2us"
- "1.2μs"
- "120μs"
-
Microseconds
- "1ns"
-
Nanoseconds, the smallest possible time division for this function.
The "what" parameter is printed in error messages to provide context.
The output ("sec", "nsec") can be passed straight to nbdkit_nanosleep(3).
Return value
On success the function returns 0 and sets *sec and *nsec to the seconds and nanoseconds parsed.
If there is an error it calls nbdkit_error(3) and returns -1. In this case, *sec and *nsec are not touched.
Language bindings
In nbdkit-ocaml-plugin(3):
NBDKit.parse_delay : string -> string -> int * int
import nbdkit(sec, nsec) = nbdkit.parse_delay(what, str)