diff options
author | Richard W.M. Jones <[email protected]> | 2012-08-15 14:38:15 +0100 |
---|---|---|
committer | Richard W.M. Jones <[email protected]> | 2012-08-15 17:49:48 +0100 |
commit | bd35b3c055cb4a1bda041faede018dd7d4cfc1ba (patch) | |
tree | 46e20d13903e8071612d9ae45f440aa78c59d69f /erlang | |
parent | e3f356bda1d249a65f5606d5e4729ba6f7e56189 (diff) | |
download | libguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.tar.gz libguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.tar.xz libguestfs-bd35b3c055cb4a1bda041faede018dd7d4cfc1ba.zip |
erlang: Fix 64 bit integers in parameters.
Diffstat (limited to 'erlang')
-rw-r--r-- | erlang/erl-guestfs-proto.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/erlang/erl-guestfs-proto.c b/erlang/erl-guestfs-proto.c index 241a1940..a1f05775 100644 --- a/erlang/erl-guestfs-proto.c +++ b/erlang/erl-guestfs-proto.c @@ -20,11 +20,15 @@ #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #include <string.h> #include <errno.h> #include <erl_interface.h> -#include <ei.h> +/* We should switch over to using + #include <ei.h> +instead of erl_interface. +*/ #include "error.h" #include "full-read.h" @@ -44,6 +48,8 @@ extern ETERM *make_table (char **r); extern ETERM *make_bool (int r); extern char **get_string_list (ETERM *term); extern int get_bool (ETERM *term); +extern int get_int (ETERM *term); +extern int64_t get_int64 (ETERM *term); extern void free_strings (char **r); /* This stops things getting out of hand, but also lets us detect @@ -269,6 +275,44 @@ get_bool (ETERM *term) return 0; } +int +get_int (ETERM *term) +{ + switch (ERL_TYPE (term)) { + case ERL_INTEGER: + return ERL_INT_VALUE (term); + case ERL_U_INTEGER: + return (int) ERL_INT_UVALUE (term); + case ERL_LONGLONG: + /* XXX check for overflow */ + return (int) ERL_LL_VALUE (term); + case ERL_U_LONGLONG: + /* XXX check for overflow */ + return (int) ERL_LL_UVALUE (term); + default: + /* XXX fail in some way */ + return -1; + } +} + +int64_t +get_int64 (ETERM *term) +{ + switch (ERL_TYPE (term)) { + case ERL_INTEGER: + return ERL_INT_VALUE (term); + case ERL_U_INTEGER: + return ERL_INT_UVALUE (term); + case ERL_LONGLONG: + return ERL_LL_VALUE (term); + case ERL_U_LONGLONG: + return (int64_t) ERL_LL_UVALUE (term); + default: + /* XXX fail in some way */ + return -1; + } +} + void free_strings (char **r) { |