diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-22 01:06:20 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-22 01:06:20 -0400 |
commit | 007b2a19f8d9bdf926aa584d85beb5bdac32bf9d (patch) | |
tree | b0a7df56e904d7547a90fe57c474510f7b4bcc44 /gnu-taler-error-codes/c.footer | |
parent | 05d427aafa7f9e637db969e4933905be2a8d9b9c (diff) | |
download | gana-007b2a19f8d9bdf926aa584d85beb5bdac32bf9d.tar.gz gana-007b2a19f8d9bdf926aa584d85beb5bdac32bf9d.zip |
generate c function for looking up ec hints
Diffstat (limited to 'gnu-taler-error-codes/c.footer')
-rw-r--r-- | gnu-taler-error-codes/c.footer | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/gnu-taler-error-codes/c.footer b/gnu-taler-error-codes/c.footer new file mode 100644 index 0000000..c348200 --- /dev/null +++ b/gnu-taler-error-codes/c.footer | |||
@@ -0,0 +1,33 @@ | |||
1 | |||
2 | |||
3 | |||
4 | /** | ||
5 | * Returns a hint for a given error code. | ||
6 | * | ||
7 | * @param ec the error code. | ||
8 | * @return the hint if it could be found, otherwise NULL. | ||
9 | */ | ||
10 | const char * | ||
11 | TALER_ErrorCode_get_hint (enum TALER_ErrorCode ec) | ||
12 | { | ||
13 | unsigned int lower = 0; | ||
14 | unsigned int upper = code_hint_pairs_length - 1; | ||
15 | unsigned int mid = upper / 2; | ||
16 | while (lower <= upper) | ||
17 | { | ||
18 | mid = (upper + lower) / 2; | ||
19 | if (code_hint_pairs[mid].ec < ec) | ||
20 | { | ||
21 | lower = mid + 1; | ||
22 | } | ||
23 | else if (code_hint_pairs[mid].ec > ec) | ||
24 | { | ||
25 | upper = mid - 1; | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | return code_hint_pairs[mid].hint; | ||
30 | } | ||
31 | } | ||
32 | return NULL; | ||
33 | } | ||