本文整理汇总了C++中enif_alloc_binary函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_alloc_binary函数的具体用法?C++ enif_alloc_binary怎么用?C++ enif_alloc_binary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_alloc_binary函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: enif_alloc_binary
static void *namespace_decl_handler(expat_parser *parser_data, const XML_Char *prefix, const XML_Char *uri)
{
ErlNifBinary ns_name, ns_value;
if(uri == NULL)
{
parser_data->xmlns = (ERL_NIF_TERM)NULL;
return NULL;
}
if(prefix)
{
enif_alloc_binary(strlen(prefix)+6, &ns_name);
strcpy((char *)ns_name.data, "xmlns:");
strcpy((char *)ns_name.data+6, (const char *)prefix);
} else
{
enif_alloc_binary(5, &ns_name);
strcpy((char *)ns_name.data, "xmlns");
}
enif_alloc_binary(strlen(uri), &ns_value);
strcpy((char *)ns_value.data, uri);
parser_data->xmlns = enif_make_tuple(parser_data->env, 2,
enif_make_binary(parser_data->env, &ns_name),
enif_make_binary(parser_data->env, &ns_value));
return NULL;
};
开发者ID:erszcz,项目名称:exml,代码行数:30,代码来源:exml_event.c
示例2: to_html_nif
static ERL_NIF_TERM to_html_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
ErlNifBinary markdown_binary;
ErlNifBinary output_binary;
char *html;
size_t html_len;
int options = 0;
if (argc != 1) {
return enif_make_badarg(env);
}
if(!enif_inspect_binary(env, argv[0], &markdown_binary)){
return enif_make_badarg(env);
}
if (markdown_binary.size <= 0){
const char *empty_string = "";
const int empty_len = strlen(empty_string);
enif_alloc_binary(empty_len, &output_binary);
strncpy((char*)output_binary.data, empty_string, empty_len);
return enif_make_binary(env, &output_binary);
}
html = cmark_markdown_to_html((const char *)markdown_binary.data, markdown_binary.size, options);
html_len = strlen(html);
enif_release_binary(&markdown_binary);
enif_alloc_binary(html_len, &output_binary);
strncpy((char*)output_binary.data, html, html_len);
return enif_make_binary(env, &output_binary);
};
开发者ID:jamesdphillips,项目名称:cmark.ex,代码行数:32,代码来源:cmark_nif.c
示例3: encode_name
static ErlNifBinary encode_name(expat_parser *parser_data, const XML_Char *name)
{
ErlNifBinary encoded;
int name_len, prefix_len;
char *name_start;
char *prefix_start;
if((name_start = strchr(name, '\n')))
{
if((prefix_start = strchr(name_start+1, '\n')))
{
name_len = prefix_start - name_start;
prefix_len = strlen(prefix_start+1);
enif_alloc_binary(name_len+prefix_len, &encoded);
strncpy((char *)encoded.data, prefix_start+1, prefix_len);
strncpy((char *)encoded.data+prefix_len, name_start, name_len);
encoded.data[prefix_len] = ':';
} else
{
name_len = strlen(name_start+1);
enif_alloc_binary(name_len, &encoded);
strncpy((char *)encoded.data, name_start+1, name_len);
}
} else
{
enif_alloc_binary(strlen(name), &encoded);
strcpy((char *)encoded.data, name);
};
return encoded;
};
开发者ID:erszcz,项目名称:exml,代码行数:31,代码来源:exml_event.c
示例4: prefix_cb
static int prefix_cb(void *data, const unsigned char *k, uint32_t k_len, void *val)
{
callback_data *cb_data = data;
art_elem_struct *elem = val;
ErlNifBinary key, value;
enif_alloc_binary(k_len - 1, &key);
memcpy(key.data, k, k_len - 1);
enif_alloc_binary(elem->size, &value);
memcpy(value.data, elem->data, elem->size);
ErlNifEnv *msg_env = enif_alloc_env();
if(msg_env == NULL)
return mk_error(cb_data->env, "env_alloc_error");;
ERL_NIF_TERM caller_ref = enif_make_copy(msg_env, cb_data->caller_ref);
ERL_NIF_TERM res = enif_make_tuple2(msg_env,
caller_ref,
enif_make_tuple2(msg_env,
enif_make_binary(msg_env, &key), enif_make_binary(msg_env, &value)));
if(!enif_send(cb_data->env, &cb_data->pid, msg_env, res))
{
enif_free(msg_env);
return -1;
}
enif_free(msg_env);
return 0;
}
开发者ID:Leapsight,项目名称:elibart,代码行数:35,代码来源:elibart.c
示例5: fprintf
static void *namespace_decl_handler(expat_parser *parser_data, const XML_Char *prefix, const XML_Char *uri)
{
ErlNifBinary ns_prefix_bin, ns_uri_bin;
ERL_NIF_TERM ns_prefix, ns_uri, ns_pair;
if(uri == NULL)
{
/* parser_data->xmlns = (ERL_NIF_TERM)NULL; */
fprintf(stderr, "URI IS NULL?\n");
return NULL;
}
if(prefix)
{
enif_alloc_binary(strlen(prefix), &ns_prefix_bin);
strcpy((char *)ns_prefix_bin.data, (const char *)prefix);
ns_prefix = enif_make_binary(parser_data->env, &ns_prefix_bin);
} else
{
ns_prefix = NONE;
}
enif_alloc_binary(strlen(uri), &ns_uri_bin);
strcpy((char *)ns_uri_bin.data, uri);
ns_uri = enif_make_binary(parser_data->env, &ns_uri_bin);
ns_pair = enif_make_tuple(parser_data->env, 2, ns_uri, ns_prefix);
parser_data->xmlns = enif_make_list_cell(parser_data->env, ns_pair, parser_data->xmlns);
return NULL;
};
开发者ID:RGafiyatullin,项目名称:exml,代码行数:31,代码来源:exml_event.c
示例6: efile_altname
posix_errno_t efile_altname(ErlNifEnv *env, const efile_path_t *path, ERL_NIF_TERM *result) {
ErlNifBinary result_bin;
ASSERT_PATH_FORMAT(path);
if(is_path_root(path)) {
/* Root paths can't be queried so we'll just return them as they are. */
if(!enif_alloc_binary(path->size, &result_bin)) {
return ENOMEM;
}
sys_memcpy(result_bin.data, path->data, path->size);
} else {
WIN32_FIND_DATAW data;
HANDLE handle;
WCHAR *name_buffer;
int name_length;
/* Reject path wildcards. */
if(wcspbrk(&((const WCHAR*)path->data)[LP_PREFIX_LENGTH], L"?*")) {
return ENOENT;
}
handle = FindFirstFileW((const WCHAR*)path->data, &data);
if(handle == INVALID_HANDLE_VALUE) {
return windows_to_posix_errno(GetLastError());
}
FindClose(handle);
name_length = wcslen(data.cAlternateFileName);
if(name_length > 0) {
name_buffer = data.cAlternateFileName;
} else {
name_length = wcslen(data.cFileName);
name_buffer = data.cFileName;
}
/* Include NUL-terminator; it will be removed after normalization. */
name_length += 1;
if(!enif_alloc_binary(name_length * sizeof(WCHAR), &result_bin)) {
return ENOMEM;
}
sys_memcpy(result_bin.data, name_buffer, name_length * sizeof(WCHAR));
}
if(!normalize_path_result(&result_bin)) {
enif_release_binary(&result_bin);
return ENOMEM;
}
(*result) = enif_make_binary(env, &result_bin);
return 0;
}
开发者ID:HansN,项目名称:otp,代码行数:60,代码来源:win_prim_file.c
示例7: nif_recvfrom
/* 0: socket, 1: length, 2: flags, 3: struct sockaddr length */
static ERL_NIF_TERM
nif_recvfrom(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int sockfd = -1;
unsigned long len = 0;
unsigned long salen = 0;
int flags = 0;
ErlNifBinary buf = {0};
ErlNifBinary sa = {0};
ssize_t bufsz = 0;
if (!enif_get_int(env, argv[0], &sockfd))
return enif_make_badarg(env);
if (!enif_get_ulong(env, argv[1], &len))
return enif_make_badarg(env);
if (!enif_get_int(env, argv[2], &flags))
return enif_make_badarg(env);
if (!enif_get_ulong(env, argv[3], &salen))
return enif_make_badarg(env);
if (!enif_alloc_binary(len, &buf))
return error_tuple(env, ENOMEM);
if (!enif_alloc_binary(salen, &sa))
return error_tuple(env, ENOMEM);
if ( (bufsz = recvfrom(sockfd, buf.data, buf.size, flags,
(sa.size == 0 ? NULL : (struct sockaddr *)sa.data),
(socklen_t *)&salen)) == -1) {
enif_release_binary(&buf);
enif_release_binary(&sa);
switch (errno) {
case EAGAIN:
case EINTR:
return enif_make_tuple2(env, atom_error, atom_eagain);
default:
return error_tuple(env, errno);
}
}
PROCKET_REALLOC(buf, bufsz);
PROCKET_REALLOC(sa, salen);
return enif_make_tuple3(env, atom_ok, enif_make_binary(env, &buf),
enif_make_binary(env, &sa));
}
开发者ID:alepharchives,项目名称:procket,代码行数:49,代码来源:procket.c
示例8: salt_scalarmult_base
static nif_term_t
salt_scalarmult_base(nif_heap_t *hp, int argc, const nif_term_t argv[])
{
/* salt_scalarmult(Integer) -> Group_q. */
nif_bin_t n;
nif_bin_t q;
if (argc != 1)
return (BADARG);
/* Unpack arguments ensuring they're suitably typed. */
if (! enif_inspect_binary(hp, argv[0], &n))
return (BADARG);
/* Check constraints on size. */
if (n.size != crypto_scalarmult_SCALARBYTES)
return (BADARG);
/* Allocate space for plain text. NB: Passing ENOMEM as BADARG. */
if (! enif_alloc_binary(crypto_scalarmult_BYTES, &q))
return (BADARG);
crypto_scalarmult_base(q.data, n.data);
return (enif_make_binary(hp, &q));
}
开发者ID:AnsonSmith,项目名称:salt,代码行数:25,代码来源:salt_nif.c
示例9: efile_get_device_cwd
posix_errno_t efile_get_device_cwd(ErlNifEnv *env, int device_index, ERL_NIF_TERM *result) {
ErlNifBinary result_bin;
/* _wgetdcwd might crash the entire emulator on debug builds since the CRT
* invalid parameter handler asserts if passed a non-existent drive (Or
* simply one that has been unmounted), so we check it ourselves to avoid
* that. */
if(!is_valid_drive(device_index)) {
return EACCES;
}
if(!enif_alloc_binary(MAX_PATH * sizeof(WCHAR), &result_bin)) {
return ENOMEM;
}
if(_wgetdcwd(device_index, (WCHAR*)result_bin.data, MAX_PATH) == NULL) {
enif_release_binary(&result_bin);
return EACCES;
}
if(!normalize_path_result(&result_bin)) {
enif_release_binary(&result_bin);
return ENOMEM;
}
(*result) = enif_make_binary(env, &result_bin);
return 0;
}
开发者ID:HansN,项目名称:otp,代码行数:29,代码来源:win_prim_file.c
示例10: nif_decompress
//-
static
ERL_NIF_TERM
nif_decompress(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary input;
if(!enif_inspect_iolist_as_binary(env, argv[0], &input))
{
return(enif_make_badarg(env));
}
ErlNifBinary bin;
// [rad] Get decompressed size.
uint32_t decompressed_bytes = wfLZ_GetDecompressedSize((const uint8_t* const) input.data);
if(!decompressed_bytes)
{
return(erlang_produce_error(env, "not_compressed"));
}
// [rad] Create binary stream to hold decompressed data.
if(!enif_alloc_binary(decompressed_bytes, &bin))
{
return(erlang_produce_error(env, "not_enough_memory"));
}
// [rad] Perform decompression.
wfLZ_Decompress((const uint8_t* const) input.data, bin.data);
return(enif_make_binary(env, &bin));
}
开发者ID:Zabrane,项目名称:wflz-erlang-nif,代码行数:33,代码来源:wlfz_nif.c
示例11: nif_get_json
static ERL_NIF_TERM nif_get_json(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
gchar *path = get_char_argument(env, &argv[0]);
if (!path)
return enif_make_badarg(env);
gchar include_content_atom[10];
guint content_option = 0;
if (argc == 2 && enif_get_atom(env, argv[1], include_content_atom, sizeof(include_content_atom), ERL_NIF_LATIN1)) {
if (!g_ascii_strcasecmp(include_content_atom, "true"))
content_option = 1;
else if (!g_ascii_strcasecmp(include_content_atom, "raw"))
content_option = 2;
}
GString *json_str = gmimex_get_json(path, content_option);
g_free(path);
if (!json_str)
return enif_make_badarg(env);
ErlNifBinary result_binary = {0};
enif_alloc_binary(json_str->len, &result_binary);
(void)memcpy(result_binary.data, json_str->str, json_str->len);
g_string_free(json_str, TRUE);
return enif_make_binary(env, &result_binary);
}
开发者ID:swerter,项目名称:gmimex,代码行数:30,代码来源:gmimex_nif.c
示例12: nif_tcgetattr
static ERL_NIF_TERM
nif_tcgetattr(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
SRLY_STATE *sp = NULL;
ErlNifBinary buf = {0};
int err = 0;
if (!enif_get_resource(env, argv[0], SRLY_STATE_RESOURCE, (void **)&sp))
return enif_make_badarg(env);
if (!enif_alloc_binary(sizeof(struct termios), &buf))
return error_tuple(env, ENOMEM);
if (tcgetattr(sp->fd, (struct termios *)buf.data) < 0) {
err = errno;
enif_release_binary(&buf);
return error_tuple(env, err);
}
return enif_make_tuple2(env,
atom_ok,
enif_make_binary(env, &buf));
}
开发者ID:jj1bdx,项目名称:srly,代码行数:25,代码来源:serctl.c
示例13: enc_unknown
static inline int
enc_unknown(Encoder* e, ERL_NIF_TERM value)
{
ErlNifBinary* bin = e->curr;
ERL_NIF_TERM curr;
if(e->i > 0) {
if(!enc_result(e, &curr)) {
return 0;
}
e->iolist = enif_make_list_cell(e->env, curr, e->iolist);
e->iolen++;
}
e->iolist = enif_make_list_cell(e->env, value, e->iolist);
e->iolen++;
// Reinitialize our binary for the next buffer.
e->curr = bin;
if(!enif_alloc_binary(BIN_INC_SIZE, e->curr)) {
return 0;
}
memset(e->curr->data, 0, e->curr->size);
e->p = (char*) e->curr->data;
e->u = (unsigned char*) e->curr->data;
e->i = 0;
return 1;
}
开发者ID:Gustav-Simonsson,项目名称:jiffy,代码行数:32,代码来源:encoder.c
示例14: io_libc_fwrite
// fwrite implementation
static ERL_NIF_TERM
io_libc_fwrite(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
char fmt[1024];
int len = 0;
if((len = enif_get_string(env, argv[0], fmt, sizeof(fmt), ERL_NIF_LATIN1)) <= 0) return enif_make_badarg(env);
if(!enif_is_list(env, argv[1])) return enif_make_badarg(env);
ERL_NIF_TERM items = argv[1];
// At first, allocate result as empty binary
ErlNifBinary result;
enif_alloc_binary(0, &result);
// Get escape sequences one-by-one from fmt with according values from items
char *cur_fmt = fmt;
int format_result;
while ((format_result = format_first(env, &result, &cur_fmt, &items)) > 0) {
// Nothing to do here, everything is ok
}
// good: return resulting binary
if (format_result >= 0) return enif_make_binary(env, &result);
// bad: make badarg. TODO: return something pointing to erroneous place
return enif_make_badarg(env);
};
开发者ID:maxlapshin,项目名称:io_libc,代码行数:28,代码来源:io_libc.c
示例15: enif_make_list
static void *start_element_handler(expat_parser *parser_data, const XML_Char *name, const XML_Char **atts)
{
ErlNifBinary element_name;
ERL_NIF_TERM attrs_list = enif_make_list(parser_data->env, 0);
int i;
element_name = encode_name(parser_data, name);
for(i = 0; atts[i]; i += 2);
while(i)
{
ErlNifBinary attr_name, attr_value;
enif_alloc_binary(strlen(atts[i-1]), &attr_value);
strcpy((char *) attr_value.data, (const char *)atts[i-1]);
attr_name = encode_name(parser_data, atts[i-2]);
ERL_NIF_TERM attr = enif_make_tuple(parser_data->env, 2,
enif_make_binary(parser_data->env, &attr_name),
enif_make_binary(parser_data->env, &attr_value));
attrs_list = enif_make_list_cell(parser_data->env, attr, attrs_list);
i -= 2;
};
if(parser_data->xmlns)
attrs_list = enif_make_list_cell(parser_data->env, parser_data->xmlns, attrs_list);
parser_data->xmlns = (ERL_NIF_TERM)NULL;
ERL_NIF_TERM event = enif_make_tuple(parser_data->env, 3, XML_ELEMENT_START,
enif_make_binary(parser_data->env, &element_name),
attrs_list);
parser_data->result = enif_make_list_cell(parser_data->env, event, parser_data->result);
return NULL;
};
开发者ID:erszcz,项目名称:exml,代码行数:35,代码来源:exml_event.c
示例16: nacl_box_padded
static ERL_NIF_TERM nacl_box_padded(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
ErlNifBinary padded_msg;
ErlNifBinary nonce;
ErlNifBinary pk;
ErlNifBinary sk;
ErlNifBinary result;
if (!enif_inspect_iolist_as_binary(env, argv[0], &padded_msg))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[1], &nonce))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[2], &pk))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[3], &sk))
return enif_make_badarg(env);
if (nonce.size != crypto_box_NONCEBYTES) return enif_make_badarg(env);
if (pk.size != crypto_box_PUBLICKEYBYTES) return enif_make_badarg(env);
if (sk.size != crypto_box_SECRETKEYBYTES) return enif_make_badarg(env);
if (padded_msg.size < crypto_box_ZEROBYTES) return enif_make_badarg(env);
if (!enif_alloc_binary(padded_msg.size, &result))
return nacl_error_tuple(env, "alloc_failed");
crypto_box(result.data, padded_msg.data, padded_msg.size, nonce.data, pk.data, sk.data);
return enif_make_sub_binary(env,
enif_make_binary(env, &result),
crypto_box_BOXZEROBYTES,
padded_msg.size - crypto_box_BOXZEROBYTES);
}
开发者ID:chinnurtb,项目名称:erlang-nacl,代码行数:35,代码来源:nacl_nif.c
示例17: nacl_secretbox_open_padded
static ERL_NIF_TERM nacl_secretbox_open_padded(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
ErlNifBinary key;
ErlNifBinary nonce;
ErlNifBinary padded_ciphertext;
ErlNifBinary padded_message;
if (!enif_inspect_iolist_as_binary(env, argv[0], &padded_ciphertext))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[1], &nonce))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[2], &key))
return enif_make_badarg(env);
if (key.size != crypto_secretbox_KEYBYTES) return enif_make_badarg(env);
if (nonce.size != crypto_secretbox_NONCEBYTES) return enif_make_badarg(env);
if (padded_ciphertext.size < crypto_secretbox_BOXZEROBYTES) return enif_make_badarg(env);
if (!enif_alloc_binary(padded_ciphertext.size, &padded_message))
return nacl_error_tuple(env, "alloc_failed");
if (crypto_secretbox_open(padded_message.data, padded_ciphertext.data, padded_ciphertext.size,
nonce.data, key.data)) {
return nacl_error_tuple(env, "crypto_failed");
}
return enif_make_sub_binary(env,
enif_make_binary(env, &padded_message),
crypto_secretbox_ZEROBYTES,
padded_ciphertext.size - crypto_secretbox_ZEROBYTES);
}
开发者ID:chinnurtb,项目名称:erlang-nacl,代码行数:33,代码来源:nacl_nif.c
示例18: efile_get_cwd
posix_errno_t efile_get_cwd(ErlNifEnv *env, ERL_NIF_TERM *result) {
ErlNifBinary result_bin;
size_t bytes_copied;
if(!enif_alloc_binary(256, &result_bin)) {
return ENOMEM;
}
while(getcwd((char*)result_bin.data, result_bin.size) == NULL) {
posix_errno_t saved_errno = errno;
if(saved_errno != ERANGE) {
enif_release_binary(&result_bin);
return saved_errno;
} else {
if(!enif_realloc_binary(&result_bin, result_bin.size * 2)) {
enif_release_binary(&result_bin);
return ENOMEM;
}
}
}
/* getcwd(2) guarantees null-termination. */
bytes_copied = strlen((const char*)result_bin.data);
if(!enif_realloc_binary(&result_bin, bytes_copied)) {
enif_release_binary(&result_bin);
return ENOMEM;
}
(*result) = enif_make_binary(env, &result_bin);
return 0;
}
开发者ID:ebengt,项目名称:otp,代码行数:34,代码来源:unix_prim_file.c
示例19: mres
//
// build result for re2:match
//
static ERL_NIF_TERM mres(ErlNifEnv* env,
const re2::StringPiece& str,
const re2::StringPiece& match,
const matchoptions::capture_type ct)
{
switch (ct) {
case matchoptions::CT_BINARY:
ErlNifBinary bmatch;
if(!enif_alloc_binary(match.size(), &bmatch))
return a_err_alloc_binary;
memcpy(bmatch.data, match.data(), match.size());
return enif_make_binary(env, &bmatch);
default:
case matchoptions::CT_INDEX:
int l, r;
if (match.empty()) {
l = -1;
r = 0;
} else {
l = match.data() - str.data();
r = match.size();
}
return enif_make_tuple2(env,
enif_make_int(env, l),
enif_make_int(env, r));
}
}
开发者ID:cooldaemon,项目名称:re2,代码行数:30,代码来源:re2_nif.cpp
示例20: nif_read
/* 0: socket, 1: length */
static ERL_NIF_TERM
nif_read(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
int fd = -1;
unsigned long len = 0;
ErlNifBinary buf = {0};
ssize_t bufsz = 0;
if (!enif_get_int(env, argv[0], &fd))
return enif_make_badarg(env);
if (!enif_get_ulong(env, argv[1], &len))
return enif_make_badarg(env);
if (!enif_alloc_binary(len, &buf))
return error_tuple(env, ENOMEM);
if ( (bufsz = read(fd, buf.data, buf.size)) == -1) {
int err = errno;
enif_release_binary(&buf);
switch (err) {
case EAGAIN:
case EINTR:
return enif_make_tuple2(env, atom_error, atom_eagain);
default:
return error_tuple(env, err);
}
}
PROCKET_REALLOC(buf, bufsz);
return enif_make_tuple2(env, atom_ok, enif_make_binary(env, &buf));
}
开发者ID:alepharchives,项目名称:procket,代码行数:35,代码来源:procket.c
注:本文中的enif_alloc_binary函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论