hex_to_raw actually works
This commit is contained in:
52
geef.c
52
geef.c
@@ -3,52 +3,32 @@
|
||||
#include <git/common.h>
|
||||
#include <git/oid.h>
|
||||
|
||||
|
||||
static int
|
||||
load(ErlNifEnv* env, void** priv, ERL_NIF_TERM load_info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
reload(ErlNifEnv* env, void** priv, ERL_NIF_TERM load_info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
upgrade(ErlNifEnv* env, void** priv, void** old_priv,
|
||||
ERL_NIF_TERM load_info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
unload(ErlNifEnv* env, void* priv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#define MAXBUFLEN 1024
|
||||
|
||||
static ERL_NIF_TERM
|
||||
object_exists(ErlNifEnv* env, ERL_NIF_TERM a1)
|
||||
geef_hex_to_raw(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
char sha[MAXBUFLEN];
|
||||
(void)memset(&sha, '\0', sizeof(sha));
|
||||
|
||||
if (enif_get_string(env, argv[0], sha, sizeof(sha), ERL_NIF_LATIN1) < 1)
|
||||
return enif_make_badarg(env);
|
||||
|
||||
git_oid oid;
|
||||
static char *sha = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
|
||||
|
||||
printf("sha: %s\n", sha);
|
||||
git_oid_mkstr(&oid, sha);
|
||||
//printf("raw: %s", (&oid)->id);
|
||||
|
||||
unsigned long val;
|
||||
if(!enif_get_ulong(env, a1, &val)) {
|
||||
return enif_make_badarg(env);
|
||||
} else {
|
||||
return enif_make_ulong(env, val*2);
|
||||
}
|
||||
ErlNifBinary ibin;
|
||||
enif_alloc_binary(env, 20, &ibin);
|
||||
memcpy(ibin.data, (&oid)->id, 20);
|
||||
|
||||
return enif_make_binary(env, &ibin);
|
||||
}
|
||||
|
||||
static ErlNifFunc geef_funcs[] =
|
||||
{
|
||||
{"object_exists", 1, object_exists}
|
||||
{"hex_to_raw", 1, geef_hex_to_raw}
|
||||
};
|
||||
|
||||
ERL_NIF_INIT(geef, geef_funcs, load, reload, upgrade, unload)
|
||||
ERL_NIF_INIT(geef, geef_funcs, NULL, NULL, NULL, NULL)
|
||||
|
||||
Reference in New Issue
Block a user