X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=generator%2Fgenerator_errnostring.ml;h=a0249892d5c3c76a5f9e80724307fad7e4dafbdf;hp=d0a5734f8f0fd67927ddba0641f94ec7c7f2fdde;hb=2066805a5d93b62beaf6653324715f0b62b06a05;hpb=d859c283c469b9d9124d90d0ac32024671372ed5 diff --git a/generator/generator_errnostring.ml b/generator/generator_errnostring.ml index d0a5734..a024989 100644 --- a/generator/generator_errnostring.ml +++ b/generator/generator_errnostring.ml @@ -224,7 +224,11 @@ extern const char *guestfs___errno_to_string (int errnum); * system, EINVAL is returned (all POSIX-conforming systems must * support EINVAL). */ -//extern int guestfs___string_to_errno (const char *errnostr); +extern int guestfs___string_to_errno (const char *errnostr); + +/* Private structure and function used by the perfect hash implementation. */ +struct errnostring_entry { char *name; int errnum; }; +extern const struct errnostring_entry *guestfs___string_to_errno_lookup (register const char *str, register unsigned int len); #endif /* GUESTFS_ERRNOSTRING_H_ */ " @@ -236,6 +240,7 @@ let generate_errnostring_c () = #include #include +#include #include #include \"errnostring.h\" @@ -270,4 +275,63 @@ guestfs___errno_to_string (int errnum) return errno_to_string[errnum]; } +int +guestfs___string_to_errno (const char *errnostr) +{ + const struct errnostring_entry *v = + guestfs___string_to_errno_lookup (errnostr, strlen (errnostr)); + if (v /* not necessary to check v->name != NULL here */) + return v->errnum; + else + return EINVAL; +} " + +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 + +#include +#include +#include + +#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