本文整理汇总了C++中driver_alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ driver_alloc函数的具体用法?C++ driver_alloc怎么用?C++ driver_alloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了driver_alloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reg_start
static ErlDrvData
reg_start(ErlDrvPort port, char* buf)
{
RegPort* rp;
char* s;
REGSAM sam = KEY_READ;
if ((s = strchr(buf, ' ')) != NULL) {
while (isspace(*s))
s++;
while (*s != '\0') {
if (*s == 'r') {
sam |= KEY_READ;
} else if (*s == 'w') {
sam |= KEY_WRITE;
}
s++;
}
}
rp = driver_alloc(sizeof(RegPort));
if (rp == NULL) {
return ERL_DRV_ERROR_GENERAL;
}
rp->port = port;
rp->hkey = rp->hkey_root = HKEY_CLASSES_ROOT;
rp->sam = sam;
rp->key = driver_alloc(1);
rp->key_size = 0;
rp->name_buf_size = 64;
rp->name_buf = driver_alloc(rp->name_buf_size);
rp->value_buf_size = 64;
rp->value_buf = driver_alloc(rp->value_buf_size);
return (ErlDrvData) rp;
}
示例2: strlen
char *escape_quotes(char *text) {
int bufsize = strlen(text) * 2;
char *buf = (char *) driver_alloc(bufsize);
memset(buf, 0, bufsize);
int i = 0;
int x = 0;
int escaped = 0;
for (i = 0; i < strlen(text); i++) {
if (text[i] == '"') {
if(!escaped) {
memcpy(&buf[x], (char *) "\\\"", 2);
x += 2;
}
else {
memcpy(&buf[x], &text[i], 1);
x++;
}
}
else {
if(text[i] =='\\') {
escaped = 1;
}
else {
escaped = 0;
}
memcpy(&buf[x], &text[i], 1);
x++;
}
}
char *retval = (char *) driver_alloc(strlen(buf) + 1);
memset(retval, 0, strlen(buf) + 1);
strncpy(retval, buf, strlen(buf));
driver_free(buf);
return retval;
}
示例3: fill_passwd
static void
fill_passwd (ErlDrvTermData *data, struct passwd *pwd,
char **name,
char **passwd)
{
char *pw_name = pwd->pw_name;
char *pw_passwd = pwd->pw_passwd;
size_t len_name = strlen (pw_name);
size_t len_passwd = strlen (pw_passwd);
if (name)
{
*name = (char *) driver_alloc (sizeof (char) * (len_name + 1));
memcpy (*name, pw_name, sizeof (char) * (len_name + 1));
pw_name = *name;
}
if (passwd)
{
*passwd = (char *) driver_alloc (sizeof (char *) * (len_passwd + 1));
memcpy (*passwd, pw_passwd, sizeof (char) * (len_passwd + 1));
pw_passwd = *passwd;
}
*data++ = ERL_DRV_ATOM;
*data++ = driver_mk_atom ("pw_name");
*data++ = ERL_DRV_STRING;
*data++ = (ErlDrvTermData) pw_name;
*data++ = strlen (pwd->pw_name);
*data++ = ERL_DRV_TUPLE;
*data++ = 2;
*data++ = ERL_DRV_ATOM;
*data++ = driver_mk_atom ("pw_passwd");
*data++ = ERL_DRV_STRING;
*data++ = (ErlDrvTermData) pw_passwd;
*data++ = strlen (pwd->pw_name);
*data++ = ERL_DRV_TUPLE;
*data++ = 2;
*data++ = ERL_DRV_ATOM;
*data++ = driver_mk_atom ("pw_uid");
*data++ = ERL_DRV_UINT;
*data++ = pwd->pw_uid;
*data++ = ERL_DRV_TUPLE;
*data++ = 2;
*data++ = ERL_DRV_ATOM;
*data++ = driver_mk_atom ("pw_gid");
*data++ = ERL_DRV_UINT;
*data++ = pwd->pw_gid;
*data++ = ERL_DRV_TUPLE;
*data++ = 2;
*data++ = ERL_DRV_TUPLE;
*data++ = 4;
}
示例4: standard_outputv
static void
standard_outputv(ErlDrvData drv_data, ErlIOVec* ev)
{
wxe_data* sd = (wxe_data *) drv_data;
WXEBinRef * binref;
ErlDrvBinary* bin;
if(ev->vsize == 2) {
binref = driver_alloc(sizeof(WXEBinRef));
binref->base = ev->iov[1].iov_base;
binref->size = ev->iov[1].iov_len;
binref->from = driver_caller(sd->port);
bin = ev->binv[1];
driver_binary_inc_refc(bin); /* Otherwise it could get deallocated */
binref->bin = bin;
binref->next = sd->bin;
sd->bin = binref;
} else { /* Empty binary (becomes NULL) */
binref = driver_alloc(sizeof(WXEBinRef));
binref->base = NULL;
binref->size = 0;
binref->from = driver_caller(sd->port);
binref->bin = NULL;
binref->next = sd->bin;
sd->bin = binref;
}
}
示例5: process_data
decode_result process_data(ErlDrvData handle,unsigned char* buf, ErlDrvSizeT* sz,char*& html_content,char*& url_address){
int index = 0,size=0,type=0,ver=0;
if (ei_decode_version((char*)buf, &index,&ver)){
//data encoding version mismatch
return decode_result{false,std::pair<std::string,std::string>("",""),
"data encoding version mismatch"};
}
else if (ei_get_type((char*)buf,&index,&type,&size)){
//must be a binary
return decode_result{false,std::pair<std::string,std::string>("",""),
"must be a binary"};
} else{
int tuple_arity;
ei_decode_tuple_header((char*)buf,&index,&tuple_arity);
ei_get_type((char*)buf,&index,&type,&size);
url_address = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,url_address);
ei_get_type((char*)buf,&index,&type,&size);
//cout << "Html Content Size " << size << endl;
html_content = (char*)driver_alloc((size+2)*sizeof(char));
ei_decode_string((char*)buf,&index,html_content);
*sz = size;
std::string url_address_str(url_address);
std::string html_content_str(html_content);
return decode_result{true,std::pair<std::string,std::string>(url_address_str,html_content_str),NULL};
}
}
示例6: ejabberd_zlib_drv_start
static ErlDrvData ejabberd_zlib_drv_start(ErlDrvPort port, char *buff)
{
ejabberd_zlib_data *d =
(ejabberd_zlib_data *)driver_alloc(sizeof(ejabberd_zlib_data));
d->port = port;
d->d_stream = (z_stream *)driver_alloc(sizeof(z_stream));
d->d_stream->zalloc = zlib_alloc;
d->d_stream->zfree = zlib_free;
d->d_stream->opaque = (voidpf)0;
deflateInit(d->d_stream, Z_DEFAULT_COMPRESSION);
d->i_stream = (z_stream *)driver_alloc(sizeof(z_stream));
d->i_stream->zalloc = zlib_alloc;
d->i_stream->zfree = zlib_free;
d->i_stream->opaque = (voidpf)0;
inflateInit(d->i_stream);
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
return (ErlDrvData)d;
}
示例7: exmpp_xml_start
static ErlDrvData
exmpp_xml_start(ErlDrvPort port, char *command)
{
struct exmpp_xml_data *edd;
/* Set binary mode. */
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
/* Allocate driver data structure. */
edd = driver_alloc(sizeof(*edd));
if (edd == NULL)
return (ERL_DRV_ERROR_GENERAL);
/* Initialize generic context. */
if (init_context(&edd->ctx) != 0) {
driver_free(edd);
return (ERL_DRV_ERROR_GENERAL);
}
edd->ctx.make_attributes = exmpp_xml_cb_make_attributes;
/* Initialize driver instance's context. */
edd->parser = NULL;
/* Initialize the declared_nss list. */
edd->declared_nss = driver_alloc(sizeof(*(edd->declared_nss)));
if (edd->declared_nss == NULL) {
free_context(&edd->ctx);
driver_free(edd);
return (ERL_DRV_ERROR_GENERAL);
}
ei_x_new(edd->declared_nss);
return ((ErlDrvData)edd);
}
示例8: erl_tess_impl
int erl_tess_impl(char* buff, ErlDrvPort port, ErlDrvTermData caller)
{
ErlDrvBinary* bin;
int i;
int num_vertices;
GLdouble *n;
int AP;
int a_max = 2;
int i_max = 6;
num_vertices = * (int *) buff; buff += 8; /* Align */
n = (double *) buff; buff += 8*3;
egl_tess.alloc_max = a_max*num_vertices*3;
bin = driver_alloc_binary(egl_tess.alloc_max*sizeof(GLdouble));
egl_tess.error = 0;
egl_tess.tess_coords = (double *) bin->orig_bytes;
memcpy(egl_tess.tess_coords,buff,num_vertices*3*sizeof(GLdouble));
egl_tess.index_max = i_max*3*num_vertices;
egl_tess.tess_index_list = (int *) driver_alloc(sizeof(int) * egl_tess.index_max);
egl_tess.tess_coords = (double *) bin->orig_bytes;
egl_tess.index_n = 0;
egl_tess.alloc_n = num_vertices*3;
gluTessNormal(tess, n[0], n[1], n[2]);
gluTessBeginPolygon(tess, 0);
gluTessBeginContour(tess);
for (i = 0; i < num_vertices; i++) {
gluTessVertex(tess, egl_tess.tess_coords+3*i, egl_tess.tess_coords+3*i);
}
gluTessEndContour(tess);
gluTessEndPolygon(tess);
AP = 0; ErlDrvTermData *rt;
rt = (ErlDrvTermData *) driver_alloc(sizeof(ErlDrvTermData) * (13+egl_tess.index_n*2));
rt[AP++]=ERL_DRV_ATOM; rt[AP++]=driver_mk_atom((char *) "_egl_result_");
for(i=0; i < egl_tess.index_n; i++) {
rt[AP++] = ERL_DRV_INT; rt[AP++] = (int) egl_tess.tess_index_list[i];
};
rt[AP++] = ERL_DRV_NIL; rt[AP++] = ERL_DRV_LIST; rt[AP++] = egl_tess.index_n+1;
rt[AP++] = ERL_DRV_BINARY; rt[AP++] = (ErlDrvTermData) bin;
rt[AP++] = egl_tess.alloc_n*sizeof(GLdouble); rt[AP++] = 0;
rt[AP++] = ERL_DRV_TUPLE; rt[AP++] = 2; // Return tuple {list, Bin}
rt[AP++] = ERL_DRV_TUPLE; rt[AP++] = 2; // Result tuple
driver_send_term(port,caller,rt,AP);
/* fprintf(stderr, "List %d: %d %d %d \r\n", */
/* res, */
/* n_pos, */
/* (tess_alloc_vertex-new_vertices)*sizeof(GLdouble), */
/* num_vertices*6*sizeof(GLdouble)); */
driver_free_binary(bin);
driver_free(egl_tess.tess_index_list);
driver_free(rt);
return 0;
}
示例9: exmpp_ht_store
int
exmpp_ht_store(struct exmpp_hashtable *ht, const char *key, int key_len,
void *value)
{
unsigned int index;
struct exmpp_ht_entry *entry;
if (ht == NULL || ht->entries == NULL)
return (-1);
/* Allocate the new entry. */
entry = driver_alloc(sizeof(*entry));
if (entry == NULL)
return (-1);
if (key_len == -1) {
entry->hash = ht_hash(key);
entry->key = exmpp_strdup(key);
if (entry->key == NULL)
return (-1);
} else {
entry->hash = ht_hash_len(key, key_len);
entry->key = driver_alloc(key_len + 1);
if (entry->key == NULL)
return (-1);
memcpy(entry->key, key, key_len);
entry->key[key_len] = '\0';
}
entry->key_len = key_len;
entry->value = value;
#if defined(USE_RWLOCK)
erl_drv_rwlock_rwlock(ht->lock);
#endif
/* Expand the table is necessary. */
if (++(ht->entries_count) > ht->load_limit) {
/*
* Ignore the return value. If expand fails, we should
* still try cramming just this value into the existing
* table -- we may not have memory for a larger table,
* but one more element may be ok. Next time we insert,
* we'll try expanding again.
*/
ht_expand(ht);
}
/* Wire the new entry. */
index = entry->hash % ht->length;
entry->next = ht->entries[index];
ht->entries[index] = entry;
#if defined(USE_RWLOCK)
erl_drv_rwlock_rwunlock(ht->lock);
#endif
return (0);
}
示例10: get_pwall
static int
get_pwall (pwd_drv_t *drv)
{
size_t pwd_count = 0;
setpwent ();
while (getpwent ())
pwd_count++;
endpwent ();
size_t term_count = passwd_term_count ();
size_t result_count = pwd_count * term_count;
ErlDrvTermData *result = (ErlDrvTermData *) driver_alloc (sizeof (ErlDrvTermData) * (result_count + 3));
if (!result)
{
fprintf (drv->log, "Couldn't allocate memory for result\n");
fflush (drv->log);
return send_error (drv, "error", "Couldn't allocate memory for result");
}
char **names = (char **) driver_alloc (sizeof (char *) * pwd_count);
char **pwds = (char **) driver_alloc (sizeof (char *) * pwd_count);
setpwent ();
size_t result_idx = 0;
struct passwd *pwd = getpwent ();
while (pwd)
{
fill_passwd (&result[result_idx * term_count], pwd, &names[result_idx], &pwds[result_idx]);
result_idx++;
pwd = getpwent ();
}
endpwent ();
result[result_count++] = ERL_DRV_NIL;
result[result_count++] = ERL_DRV_LIST;
result[result_count++] = pwd_count + 1;
int r = driver_output_term (drv->port,
result,
result_count);
size_t i = 0;
for (; i < pwd_count; ++i)
{
driver_free (pwds[i]);
driver_free (names[i]);
}
driver_free (pwds);
driver_free (names);
driver_free (result);
return r;
}
示例11: hash_ring_drv_start
static ErlDrvData hash_ring_drv_start(ErlDrvPort port, char *buff)
{
hash_ring_data* d = (hash_ring_data*)driver_alloc(sizeof(hash_ring_data));
d->port = port;
d->numRings = INITIAL_RING_SPACE;
d->rings = (hash_ring_t**)driver_alloc(sizeof(hash_ring_t) * d->numRings);
d->ring_usage = (unsigned char*)driver_alloc(sizeof(unsigned char) * d->numRings);
memset(d->ring_usage, 0, sizeof(unsigned char) * d->numRings);
return (ErlDrvData)d;
}
示例12: driver_alloc
static inline async_sqlite3_command *make_async_command_script(
sqlite3_drv_t *drv, char *script, int script_length) {
async_sqlite3_command *result =
(async_sqlite3_command *) driver_alloc(sizeof(async_sqlite3_command));
char *script_copy = driver_alloc(sizeof(char) * script_length);
memset(result, 0, sizeof(async_sqlite3_command));
memcpy(script_copy, script, sizeof(char) * script_length);
result->driver_data = drv;
result->type = t_script;
result->script = script_copy;
result->end = script_copy + script_length;
return result;
}
示例13: read_int32
// Any string read using this function must be freed
// using driver_free later
char *read_string(char **data) {
int length = read_int32(data);
char *buf = NULL;
if (length > 0) {
buf = (char *) driver_alloc(length + 1);
memset(buf, 0, length + 1);
memcpy(buf, (const char *) *data, length);
(*data) += length;
}
else {
buf = (char *) driver_alloc(1);
memset(buf, 0, 1);
}
return buf;
}
示例14: start
static ErlDrvData start(ErlDrvPort port, char *) {
if (NULL != port) {
void *ptr = driver_alloc(sizeof(driver_data_t));
if (NULL != ptr) {
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
driver_data_t *data = (driver_data_t *)ptr;
data->port = port;
strcpy(data->path, "flat_in/"); // << EGenLoader.cpp: FLAT_IN_PATH
TPCE::CDriverGlobalSettings dgs;
TPCE::TDriverGlobalSettings &dgs_d = dgs.dft;
data->configured_customer_count = dgs_d.iConfiguredCustomerCount;
data->active_customer_count = dgs_d.iActiveCustomerCount;
data->scale_factor = dgs_d.iScaleFactor;
data->days_of_initial_trades = dgs_d.iDaysOfInitialTrades;
return (ErlDrvData)data;
}
}
return ERL_DRV_ERROR_GENERAL;
}
示例15: tcbdb_start
static ErlDrvData
tcbdb_start (ErlDrvPort port,
char* buf)
{
ErlDrvSysInfo info;
TcDriverData* d = (TcDriverData*) driver_alloc (sizeof (TcDriverData));
(void) buf;
memset (d, 0, sizeof (TcDriverData));
d->ref_count = 1;
d->port = port;
d->bdb = tcbdbnew ();
driver_system_info (&info, sizeof (info));
if (info.thread_support && info.async_threads > 0)
{
d->async_threads = 1;
}
d->cur = tcbdbcurnew (d->bdb);
init_handlers (d->handlers);
d->magic = ((intptr_t) d) >> 8;
return (ErlDrvData) d;
}