Extract string->binary conversion
This commit is contained in:
12
c_src/geef.c
12
c_src/geef.c
@@ -137,6 +137,18 @@ int geef_terminate_binary(ErlNifBinary *bin)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int geef_string_to_bin(ErlNifBinary *bin, const char *str)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
if (!enif_alloc_binary(len, bin))
|
||||
return -1;
|
||||
|
||||
memcpy(bin->data, str, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ErlNifFunc geef_funcs[] =
|
||||
{
|
||||
{"repository_init", 2, geef_repository_init},
|
||||
|
||||
@@ -32,5 +32,7 @@ extern geef_atoms atoms;
|
||||
|
||||
/** NUL-terminate a binary */
|
||||
int geef_terminate_binary(ErlNifBinary *bin);
|
||||
/** Copy a string into a binary */
|
||||
int geef_string_to_bin(ErlNifBinary *bin, const char *str);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -90,18 +90,6 @@ on_oom:
|
||||
|
||||
}
|
||||
|
||||
static int geef_string_to_bin(ErlNifBinary *bin, const char *str)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(str);
|
||||
if (!enif_alloc_binary(len, bin))
|
||||
return -1;
|
||||
|
||||
memcpy(bin->data, str, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int geef_signature_to_erl(ERL_NIF_TERM *out, ErlNifEnv *env, git_signature *sig)
|
||||
{
|
||||
ErlNifBinary name, email;
|
||||
|
||||
Reference in New Issue
Block a user