+
+let generate_errnostring_gperf () =
+ generate_header CStyle LGPLv2plus;
+
+ pr "\
+%%language=ANSI-C
+%%define lookup-function-name guestfs___string_to_errno_lookup
+%%readonly-tables
+%%null-strings
+
+%%{
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include \"errnostring.h\"
+
+";
+
+ (* Some of these errnos might not exist on the target platform, but
+ * we are going to include E_ macros directly in the C output of
+ * gperf. To avoid this causing errors, we include macros to define
+ * unknown errors as EINVAL (see specification of
+ * guestfs___string_to_errno above). Note this only affects the
+ * single output file containing gperf-generated code.
+ *)
+ List.iter (
+ fun e ->
+ pr "#ifndef %s\n" e;
+ pr "#define %s EINVAL\n" e;
+ pr "#endif\n";
+ ) errnos;
+
+ pr "\
+
+%%}
+
+struct errnostring_entry;
+
+%%%%
+";
+
+ List.iter (
+ fun e ->
+ pr "%s, %s\n" e e
+ ) errnos