errnostring: Handle changed type of 'len' parameter in gperf 3.1 (RHBZ#1416941).

The prototype of the hash function changed in gperf 3.1:

* The 'len' parameter of the hash function and of the lookup function is now
  of type 'size_t' instead of 'unsigned int'. This makes it safe to call these
  functions with strings of length > 4 GB, on 64-bit machines.

This commit moves the guestfs_int_string_to_errno function into the
third (functions) section of the gperf file so it is able to use the
lookup function without needing a prototype.

Thanks: Marius Cirsta
This commit is contained in:
Richard W.M. Jones
2017-01-26 21:22:48 +00:00
parent 00a2b689b3
commit 004de6cf45

View File

@@ -229,9 +229,8 @@ extern const char *guestfs_int_errno_to_string (int errnum);
*/
extern int guestfs_int_string_to_errno (const char *errnostr);
/* Private structure and function used by the perfect hash implementation. */
/* Private structure used by the perfect hash implementation. */
struct errnostring_entry { char *name; int errnum; };
extern const struct errnostring_entry *guestfs_int_string_to_errno_lookup (register const char *str, register unsigned int len);
#endif /* GUESTFS_ERRNOSTRING_H_ */
"
@@ -277,17 +276,6 @@ guestfs_int_errno_to_string (int errnum)
else
return errno_to_string[errnum];
}
int
guestfs_int_string_to_errno (const char *errnostr)
{
const struct errnostring_entry *v =
guestfs_int_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 () =
@@ -337,4 +325,19 @@ struct errnostring_entry;
List.iter (
fun e ->
pr "%s, %s\n" e e
) errnos
) errnos;
pr "\
%%%%
int
guestfs_int_string_to_errno (const char *errnostr)
{
const struct errnostring_entry *v =
guestfs_int_string_to_errno_lookup (errnostr, strlen (errnostr));
if (v /* not necessary to check v->name != NULL here */)
return v->errnum;
else
return EINVAL;
}
"