本文整理汇总了C++中Malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ Malloc函数的具体用法?C++ Malloc怎么用?C++ Malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ipmipower_connection_array_create
struct ipmipower_connection *
ipmipower_connection_array_create(const char *hostname, unsigned int *len)
{
char *str = NULL;
int index = 0;
hostlist_t hl = NULL;
hostlist_iterator_t itr = NULL;
struct ipmipower_connection *ics;
int size = sizeof(struct ipmipower_connection);
int hl_count;
int errcount = 0;
int emfilecount = 0;
assert(hostname && len);
*len = 0;
if (!(hl = hostlist_create(hostname)))
{
ipmipower_output(MSG_TYPE_HOSTNAME_INVALID, hostname);
return NULL;
}
if (!(itr = hostlist_iterator_create(hl)))
ierr_exit("hostlist_iterator_create() error");
hostlist_uniq(hl);
hl_count = hostlist_count(hl);
ics = (struct ipmipower_connection *)Malloc(size * hl_count);
memset(ics, '\0', (size * hl_count));
while ((str = hostlist_next(itr)))
{
ics[index].ipmi_fd = -1;
ics[index].ping_fd = -1;
/* cleanup only at the end, gather all error outputs for
* later
*/
if (_connection_setup(&ics[index], str) < 0)
{
if (errno == EMFILE && !emfilecount)
{
cbuf_printf(ttyout, "file descriptor limit reached\n");
emfilecount++;
}
errcount++;
}
free(str);
index++;
}
hostlist_iterator_destroy(itr);
hostlist_destroy(hl);
if (errcount)
{
int i;
for (i = 0; i < hl_count; i++)
{
close(ics[i].ipmi_fd);
close(ics[i].ping_fd);
if (ics[i].ipmi_in)
cbuf_destroy(ics[i].ipmi_in);
if (ics[i].ipmi_out)
cbuf_destroy(ics[i].ipmi_out);
if (ics[i].ping_in)
cbuf_destroy(ics[i].ping_in);
if (ics[i].ping_out)
cbuf_destroy(ics[i].ping_out);
}
Free(ics);
return NULL;
}
*len = hl_count;
return ics;
}
示例2: forward_response
/*
* forward_response - send request to server, then store resposne content
* in cache if necessary
*/
int forward_response(int client_fd, int server_fd, Response *response) {
#ifdef DEBUG
printf("enter forward_response\n");
#endif
size_t n;
int length = -1;
int read_size;
rio_t server_rio;
char header_buffer[MAXLINE];
char temp_buffer[MAX_OBJECT_SIZE];
char buffer[10 * MAX_OBJECT_SIZE];
char content_buffer[10 * MAX_OBJECT_SIZE];
rio_readinitb(&server_rio, server_fd);
int buffer_pos = 0;
while ((n = rio_readlineb(&server_rio, header_buffer, MAXLINE)) != 0) {
memcpy(response->header + buffer_pos,
header_buffer, sizeof(char) * n);
buffer_pos += n;
/*specify content-length info if header has this info */
if (strstr(header_buffer, "Content-Length: ")) {
sscanf(header_buffer + 16, "%d", &length);
}
if (!strcmp(header_buffer, "\r\n")) {
break;
}
}
if (length == -1)
read_size = MAX_OBJECT_SIZE;
else
read_size = min(length, MAX_OBJECT_SIZE);
#ifdef DEBUG
printf("finish response header\n");
#endif
int sum = 0;
while ((n = rio_readnb(&server_rio, temp_buffer, read_size)) != 0) {
memcpy(content_buffer + sum, temp_buffer, sizeof(char) * n);
sum += n;
}
memcpy(buffer, response->header, sizeof(char) * buffer_pos);
memcpy(buffer + buffer_pos, content_buffer, sizeof(char) * sum);
if (rio_writen(client_fd, buffer, buffer_pos + sum) < 0) {
sleep(1);
if (rio_writen(client_fd, buffer, buffer_pos + sum) < 0) {
sleep(2);
if (rio_writen(client_fd, buffer, buffer_pos + sum) < 0)
proxy_error("rio_writen in forward_response"
" header content error");
return -1;
}
}
#ifdef DEBUG
printf("read byte size:%u\n", sum);
#endif
if (sum <= MAX_OBJECT_SIZE) {
response->content = Malloc(sizeof(char) * sum);
memcpy(response->content, content_buffer, sum * sizeof(char));
response->content_size = sum;
} else {
response->content_size = sum;
}
#ifdef DEBUG
printf("leave forward_response\n");
#endif
return 1;
}
示例3: train
//
// Interface functions
//
model* train(const problem *prob, const parameter *param)
{
problem newprob;
remove_zero_weight(&newprob, prob);
prob = &newprob;
int i,j;
int l = prob->l;
int n = prob->n;
int w_size = prob->n;
model *model_ = Malloc(model,1);
if(prob->bias>=0)
model_->nr_feature=n-1;
else
model_->nr_feature=n;
model_->param = *param;
model_->bias = prob->bias;
int nr_class;
int *label = NULL;
int *start = NULL;
int *count = NULL;
int *perm = Malloc(int,l);
// group training data of the same class
group_classes(prob,&nr_class,&label,&start,&count,perm);
model_->nr_class=nr_class;
model_->label = Malloc(int,nr_class);
for(i=0;i<nr_class;i++)
model_->label[i] = label[i];
// calculate weighted C
double *weighted_C = Malloc(double, nr_class);
for(i=0;i<nr_class;i++)
weighted_C[i] = param->C;
for(i=0;i<param->nr_weight;i++)
{
for(j=0;j<nr_class;j++)
if(param->weight_label[i] == label[j])
break;
if(j == nr_class)
fprintf(stderr,"warning: class label %d specified in weight is not found\n", param->weight_label[i]);
else
weighted_C[j] *= param->weight[i];
}
// constructing the subproblem
feature_node **x = Malloc(feature_node *,l);
double *W = Malloc(double,l);
for(i=0;i<l;i++)
{
x[i] = prob->x[perm[i]];
W[i] = prob->W[perm[i]];
}
int k;
problem sub_prob;
sub_prob.l = l;
sub_prob.n = n;
sub_prob.x = Malloc(feature_node *,sub_prob.l);
sub_prob.y = Malloc(int,sub_prob.l);
sub_prob.W = Malloc(double,sub_prob.l);
for(k=0; k<sub_prob.l; k++)
{
sub_prob.x[k] = x[k];
sub_prob.W[k] = W[k];
}
// multi-class svm by Crammer and Singer
if(param->solver_type == MCSVM_CS)
{
model_->w=Malloc(double, n*nr_class);
for(i=0;i<nr_class;i++)
for(j=start[i];j<start[i]+count[i];j++)
sub_prob.y[j] = i;
Solver_MCSVM_CS Solver(&sub_prob, nr_class, weighted_C, param->eps);
Solver.Solve(model_->w);
}
示例4: Malloc
static void *OpenSslMallocFun(size_t size) {
return Malloc(size);
}
示例5: _event_dump
/*
* _event_dump
*
* Output event debugging info
*/
static void
_event_dump(struct cerebro_event *event)
{
#if CEREBRO_DEBUG
if (conf.event_server_debug)
{
char *buf;
Pthread_mutex_lock(&debug_output_mutex);
fprintf(stderr, "**************************************\n");
fprintf(stderr, "* Cerebrod Event:\n");
fprintf(stderr, "* ---------------\n");
fprintf(stderr, "* Version: %d\n", event->version);
fprintf(stderr, "* Nodename: %s\n", event->nodename);
fprintf(stderr, "* Event_Name: %s\n", event->event_name);
fprintf(stderr, "* Value Type: %d\n", event->event_value_type);
fprintf(stderr, "* Value Len: %d\n", event->event_value_len);
switch(event->event_value_type)
{
case CEREBRO_DATA_VALUE_TYPE_NONE:
break;
case CEREBRO_DATA_VALUE_TYPE_INT32:
fprintf(stderr, "* Value = %d",
*((int32_t *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_U_INT32:
fprintf(stderr, "* Value = %u",
*((u_int32_t *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_FLOAT:
fprintf(stderr, "* Value = %f",
*((float *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_DOUBLE:
fprintf(stderr, "* Value = %f",
*((double *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_STRING:
/* Watch for NUL termination */
buf = Malloc(event->event_value_len + 1);
memset(buf, '\0', event->event_value_len + 1);
memcpy(buf,
event->event_value,
event->event_value_len);
fprintf(stderr, "* Value = %s", buf);
Free(buf);
break;
#if SIZEOF_LONG == 4
case CEREBRO_DATA_VALUE_TYPE_INT64:
fprintf(stderr, "* Value = %lld",
*((int64_t *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_U_INT64:
fprintf(stderr, "* Value = %llu",
*((u_int64_t *)event->event_value));
break;
#else /* SIZEOF_LONG == 8 */
case CEREBRO_DATA_VALUE_TYPE_INT64:
fprintf(stderr, "* Value = %ld",
*((int64_t *)event->event_value));
break;
case CEREBRO_DATA_VALUE_TYPE_U_INT64:
fprintf(stderr, "* Value = %lu",
*((u_int64_t *)event->event_value));
break;
#endif /* SIZEOF_LONG == 8 */
default:
break;
}
fprintf(stderr, "\n");
fprintf(stderr, "**************************************\n");
Pthread_mutex_unlock(&debug_output_mutex);
}
#endif /* CEREBRO_DEBUG */
}
示例6: main
//#ifdef WIN32
int main(int c, char **v)
//#else
//int anago_cui(int c, char **v)
//#endif
{
mm_init();
if(c >= 2){
const struct reader_driver *r = &DRIVER_KAZZO;
#ifdef _UNICODE
int i;
wchar_t **v;
v = Malloc(sizeof(wchar_t *) * c);
for(i = 0; i < c; i++){
size_t len = strlen(vv[i]) + 1;
v[i] = Malloc(sizeof(wchar_t) * len);
mbstowcs(v[i], vv[i], len);
}
#endif
switch(v[1][0]){
case wgT('x'): case wgT('X'):
r = &DRIVER_DUMMY; //though down
case wgT('f'): case wgT('F'):
program(c, v, r);
break;
case wgT('z'): case wgT('R'): case wgT('W'):
r = &DRIVER_DUMMY; //though down
case wgT('d'): case wgT('D'):
case wgT('r'): case wgT('w'):
dump(c, v, r);
break;
case wgT('V'):
r = &DRIVER_DUMMY;
case wgT('v'):
vram_scan(c, v, r);
break;
case wgT('b'):
crc32_display(c, v);
break;
default:
usage(v[0]);
PUTS(wgT("mode are d, D, f, g"));
break;
}
#ifdef _UNICODE
for(i = 0; i < c; i++){
Free(v[i]);
}
Free(v);
#endif
}else{ //usage
#ifdef _UNICODE
size_t len = strlen(vv[0]) + 1;
wchar_t *t = Malloc(sizeof(wchar_t) * len);
mbstowcs(t, vv[0], len);
usage(t);
Free(t);
#else
usage(v[0]);
#endif
}
mm_end();
return 0;
}
示例7: load_config
/* load_config - load configuration from config and rules file */
void load_config (void)
{
FILE *config, *rules;
char buf[CONF_MAXLEN], *tok, *beg;
size_t len, line_cnt, erule_cnt, drule_cnt, srule_cnt, vrule_cnt;
int state;
int port;
/*** load program configuration ***/
if (NULL == (config = fopen(conf.config_file, "r"))) {
fprintf(stderr, "Can't read '%s' configuration file.\n",
conf.config_file);
usage();
exit(1);
}
line_cnt = 0;
while (fgets(buf, CONF_MAXLEN, config) != NULL) {
++line_cnt;
if ('#' == buf[0] || '\n' == buf[0]) /* comment or empty line */
continue;
/* SMTP Port */
else if (0 == strncmp("smtp_port = ", buf, 12)) {
if ((port = atoi(buf+12)) > 0)
conf.smtp_port = htons(port);
else
fprintf(stderr, "Syntax error in config file on line %d"
"-- bad SMTP port (smtp_port).\n", line_cnt);
}
/* rules file location */
else if (0 == strncmp("rules = ", buf, 8)) {
if (NULL != conf.rules_file)
continue;
len = strlen(buf+8)+1;
conf.rules_file = Malloc(len);
strncpy(conf.rules_file, buf+8, len);
conf.rules_file[len-2] = '\0';
}
/* mail server address */
else if (0 == strncmp("mail_srv_addr = ", buf, 16)) {
(buf+16)[strlen(buf+16)-1] = '\0';
if (1 != inet_pton(AF_INET, buf+16, &(conf.mail_srv.sin_addr))) {
fprintf(stderr, "Syntax error in config file on line %d"
" - not valid mail server address (mail_srv).\n",
line_cnt);
break;
}
else
conf.mail_srv.sin_family = AF_INET;
}
/* mail server port */
else if (0 == strncmp("mail_srv_port = ", buf, 16)) {
if ((port = atoi(buf+16)) > 0)
conf.mail_srv.sin_port = htons(port);
else
fprintf(stderr, "Syntax error in config file on line %d"
"-- bad mail server port (mail_srv_port).\n", line_cnt);
}
else
fprintf(stderr, "Syntax error in config file on line %d.\n",
line_cnt);
}
fclose(config);
/* check whether configuration is complete */
if (0 == conf.mail_srv.sin_port || 0 == conf.mail_srv.sin_family) {
fprintf(stderr, "Configuration error, mail server address or port "
"was not set\n");
exit(1);
}
if (0 == conf.smtp_port) {
conf.smtp_port = htons(DEFAULT_SMTP_PORT);
fprintf(stderr, "Loaded default SMTP port as none was set.\n");
}
/* load default rules file, if none was set */
if (NULL == conf.rules_file) {
len = strlen(DEFAULT_RULES_FILE)+1;
conf.rules_file = Malloc(len);
strncpy(conf.rules_file, DEFAULT_RULES_FILE, len);
fprintf(stderr, "Loaded default SMTP port as none was set.\n");
}
/*** load encryption/signing rules ***/
if (NULL == (rules = fopen(conf.rules_file, "r"))) {
fprintf(stderr, "Can't read '%s' rules file.\n", conf.rules_file);
exit(1);
}
line_cnt = 0;
conf.encr_rules_size = 0;
conf.sign_rules_size = 0;
//.........这里部分代码省略.........
示例8: main
int main(int argc, char **argv) {
char sp1[] = "9878";
char sp2[] = "9879";
int maxfd;
int nready, clientEcho[FD_SETSIZE], clientTime[FD_SETSIZE];
ssize_t nEcho, nTime;
fd_set rset, allset;
int listenfdEcho, *iptrEcho;
pthread_t tid;
socklen_t addrlenEcho, lenEcho;
struct sockaddr *cliaddrEcho;
int listenfdTime, *iptrTime;
// pthread_t tid;
socklen_t addrlenTime, lenTime;
struct sockaddr *cliaddrTime;
if (argc == 1) {
listenfdEcho = Tcp_listen(NULL, sp1, &addrlenEcho);
listenfdTime = Tcp_listen(NULL, sp2, &addrlenTime);
} else
err_quit("usage: tcpserv01 [ <host> ] <service or port>");
int oneEcho = 1;
setsockopt(listenfdEcho, SOL_SOCKET, SO_REUSEADDR, &oneEcho,
sizeof(oneEcho));
int oneTime = 1;
setsockopt(listenfdEcho, SOL_SOCKET, SO_REUSEADDR, &oneTime,
sizeof(oneTime));
cliaddrTime = Malloc(addrlenTime);
cliaddrEcho = Malloc(addrlenEcho);
FD_ZERO(&allset);
FD_SET(listenfdEcho, &allset);
FD_SET(listenfdTime, &allset);
if (listenfdEcho > listenfdTime)
maxfd = listenfdEcho;
else
maxfd = listenfdTime;
printf("%s\n\n","waiting for connection" );
for (;;) {
rset = allset; /* structure assignment */
nready = Select(maxfd + 1, &rset, NULL, NULL, NULL);
if (FD_ISSET(listenfdEcho, &rset)) { /* new client connection */
lenEcho = addrlenEcho;
iptrEcho = Malloc(sizeof(int));
*iptrEcho = Accept(listenfdEcho, cliaddrEcho, &lenEcho);
Pthread_create(&tid, NULL, &echoFunction, iptrEcho);
// printf("echo server thread started, thread id: %d \n\n",tid);
}
if (FD_ISSET(listenfdTime, &rset)) { /* new client connection */
lenTime = addrlenTime;
iptrTime = Malloc(sizeof(int));
*iptrTime = Accept(listenfdTime, cliaddrTime, &lenTime);
Pthread_create(&tid, NULL, &timeFunction, iptrTime);
// printf("time server thread started, thread id: %d \n\n",tid);
}
}
}
示例9: HMQHash
unsigned int HMQHash(register const char *str)
{
static unsigned char hmqHashArray[] =
{
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 0, 262, 262, 262, 262, 40, 262, 262, 262,
262, 0, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 0, 20, 115,
12, 40, 0, 35, 10, 30, 262, 10, 0, 85,
5, 25, 0, 105, 15, 90, 5, 45, 262, 55,
0, 15, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262, 262, 262, 262, 262,
262, 262, 262, 262, 262, 262
};
register unsigned int len = strlen(str);
switch (len)
{
default:
len += hmqHashArray[(unsigned char)(str[15]>64 && str[15]<91?(str[15]|0x20):str[15])];
case 15:
case 14:
len += hmqHashArray[(unsigned char)(str[13]>64 && str[13]<91?(str[13]|0x20):str[13])];
case 13:
case 12:
case 11:
len += hmqHashArray[(unsigned char)(str[10]>64 && str[10]<91?(str[10]|0x20):str[10])];
case 10:
len += hmqHashArray[(unsigned char)(str[9]>64 && str[9]<91?(str[9]|0x20):str[9])];
case 9:
break;
case 8:
case 7:
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
;
}
register unsigned int i = len & hmqHashFactor;
for(;;)
{
if (hmqHashString[i] == NULL)
{
hmqHashString[i]=(char*)Malloc(len+1);
for(int x=0;;x++)
{
if ((hmqHashString[i][x]=str[x])==NULL)
return i;
}
}
else
for(int x=0;(str[x]|0x20)==(hmqHashString[i][x]|0x20);x++)
{
if (str[x]==NULL)
return i;
}
i++;
}
}
示例10: _xioopen_proxy_connect
int _xioopen_proxy_connect(struct single *xfd,
struct proxyvars *proxyvars,
int level) {
size_t offset;
char request[CONNLEN];
char buff[BUFLEN+1];
#if CONNLEN > BUFLEN
#error not enough buffer space
#endif
char textbuff[2*BUFLEN+1]; /* just for sanitizing print data */
char *eol = buff;
int state;
ssize_t sresult;
/* generate proxy request header - points to final target */
sprintf(request, "CONNECT %s:%u HTTP/1.0\r\n",
proxyvars->targetaddr, proxyvars->targetport);
/* send proxy CONNECT request (target addr+port) */
* xiosanitize(request, strlen(request), textbuff) = '\0';
Info1("sending \"%s\"", textbuff);
/* write errors are assumed to always be hard errors, no retry */
do {
sresult = Write(xfd->wfd, request, strlen(request));
} while (sresult < 0 && errno == EINTR);
if (sresult < 0) {
Msg4(level, "write(%d, %p, "F_Zu"): %s",
xfd->wfd, request, strlen(request), strerror(errno));
if (Close(xfd->wfd) < 0) {
Info2("close(%d): %s", xfd->wfd, strerror(errno));
}
return STAT_RETRYLATER;
}
if (proxyvars->authstring) {
/* send proxy authentication header */
# define XIOAUTHHEAD "Proxy-authorization: Basic "
# define XIOAUTHLEN 27
static const char *authhead = XIOAUTHHEAD;
# define HEADLEN 256
char *header, *next;
/* ...\r\n\0 */
if ((header =
Malloc(XIOAUTHLEN+((strlen(proxyvars->authstring)+2)/3)*4+3))
== NULL) {
return -1;
}
strcpy(header, authhead);
next = xiob64encodeline(proxyvars->authstring,
strlen(proxyvars->authstring),
strchr(header, '\0'));
*next = '\0';
Info1("sending \"%s\\r\\n\"", header);
*next++ = '\r'; *next++ = '\n'; *next++ = '\0';
do {
sresult = Write(xfd->wfd, header, strlen(header));
} while (sresult < 0 && errno == EINTR);
if (sresult < 0) {
Msg4(level, "write(%d, %p, "F_Zu"): %s",
xfd->wfd, header, strlen(header), strerror(errno));
if (Close(xfd->wfd/*!*/) < 0) {
Info2("close(%d): %s", xfd->wfd, strerror(errno));
}
return STAT_RETRYLATER;
}
free(header);
}
Info("sending \"\\r\\n\"");
do {
sresult = Write(xfd->wfd, "\r\n", 2);
} while (sresult < 0 && errno == EINTR);
/*! */
/* request is kept for later error messages */
*strstr(request, " HTTP") = '\0';
/* receive proxy answer; looks like "HTTP/1.0 200 .*\r\nHeaders..\r\n\r\n" */
/* socat version 1 depends on a valid fd for data transfer; address
therefore cannot buffer data. So, to prevent reading beyond the end of
the answer headers, only single bytes are read. puh. */
state = XIOSTATE_HTTP1;
offset = 0; /* up to where the buffer is filled (relative) */
/*eol;*/ /* points to the first lineterm of the current line */
do {
sresult = xioproxy_recvbytes(xfd, buff+offset, 1, level);
if (sresult <= 0) {
state = XIOSTATE_ERROR;
break; /* leave read cycles */
}
switch (state) {
case XIOSTATE_HTTP1:
/* 0 or more bytes of first line received, no '\r' yet */
if (*(buff+offset) == '\r') {
eol = buff+offset;
state = XIOSTATE_HTTP2;
//.........这里部分代码省略.........
示例11: main
/* Code Principal */
int main(void)
{
int ability,i,fhandle;
char buffer[2000];
DTA *mydta;
char *pmodule;
if ((mydta = (long)(Malloc(44))) == NULL)
{
printf("Erreur Reservation memoire !!!");
return -4;
}
Fsetdta(mydta);
printf("\033E");
/* Initialisation du DSP */
ability=xbios(113);
if ((Dsp_LoadProg(DSP_CODE,ability,buffer))==0)
printf("Chargement du code DSP = OK !!!\n");
else
{
printf("Erreur de chargement du programme DSP !!!\n");
i=getchar();
return -1;
}
/* Chargement du module */
if (Fsfirst(MODULE,0) == 0)
if ((pmodule=Malloc(TAILLE_BUFF+(mydta->d_length))) != NULL)
{
fhandle=Fopen(MODULE,0 );
Fread(fhandle,mydta->d_length,pmodule);
Fclose(fhandle);
}
else
{
printf("Pas assez de memoire !!!\n");
i=getchar();
return -2;
}
else
{
printf("Module introuvable\n");
i=getchar();
return -3;
}
/* Initialisation du player */
printf("Un petit moment SVP...\n");
if (Player_dtm(0,pmodule,pmodule+mydta->d_length)==-1)
{
printf("Erreur initialisation du module !!!");
i=getchar();
return -2;
}
printf("Appuyez sur une RETURN...\n");
示例12: Malloc
static void *OpenSslMallocFun(size_t size, const char *file, int line) {
return Malloc(size);
}
示例13: pmemlog_map_common
//.........这里部分代码省略.........
if ((hdr_write > hdr_end) || (hdr_write < hdr_start)) {
LOG(1, "wrong write offset "
"(start: %ju end: %ju write: %ju)",
hdr_start, hdr_end, hdr_write);
errno = EINVAL;
goto err;
}
LOG(3, "start: %ju, end: %ju, write: %ju",
hdr_start, hdr_end, hdr_write);
int retval = util_feature_check(&hdr, LOG_FORMAT_INCOMPAT,
LOG_FORMAT_RO_COMPAT,
LOG_FORMAT_COMPAT);
if (retval < 0)
goto err;
else if (retval == 0)
rdonly = 1;
} else {
/*
* no valid header was found
*/
if (rdonly) {
LOG(1, "read-only and no header found");
errno = EROFS;
goto err;
}
LOG(3, "creating new log memory pool");
struct pool_hdr *hdrp = &plp->hdr;
memset(hdrp, '\0', sizeof (*hdrp));
strncpy(hdrp->signature, LOG_HDR_SIG, POOL_HDR_SIG_LEN);
hdrp->major = htole32(LOG_FORMAT_MAJOR);
hdrp->compat_features = htole32(LOG_FORMAT_COMPAT);
hdrp->incompat_features = htole32(LOG_FORMAT_INCOMPAT);
hdrp->ro_compat_features = htole32(LOG_FORMAT_RO_COMPAT);
uuid_generate(hdrp->uuid);
hdrp->crtime = htole64((uint64_t)time(NULL));
util_checksum(hdrp, sizeof (*hdrp), &hdrp->checksum, 1);
hdrp->checksum = htole64(hdrp->checksum);
/* store pool's header */
libpmem_persist(is_pmem, hdrp, sizeof (*hdrp));
/* create rest of required metadata */
plp->start_offset = htole64(roundup(sizeof (*plp),
LOG_FORMAT_DATA_ALIGN));
plp->end_offset = htole64(stbuf.st_size);
plp->write_offset = plp->start_offset;
/* store non-volatile part of pool's descriptor */
libpmem_persist(is_pmem, &plp->start_offset,
3 * sizeof (uint64_t));
}
/*
* Use some of the memory pool area for run-time info. This
* run-time state is never loaded from the file, it is always
* created here, so no need to worry about byte-order.
*/
plp->addr = addr;
plp->size = stbuf.st_size;
plp->rdonly = rdonly;
plp->is_pmem = is_pmem;
if ((plp->rwlockp = Malloc(sizeof (*plp->rwlockp))) == NULL) {
LOG(1, "!Malloc for a RW lock");
goto err;
}
if (pthread_rwlock_init(plp->rwlockp, NULL)) {
LOG(1, "!pthread_rwlock_init");
goto err_free;
}
/*
* If possible, turn off all permissions on the pool header page.
*
* The prototype PMFS doesn't allow this when large pages are in
* use. It is not considered an error if this fails.
*/
util_range_none(addr, sizeof (struct pool_hdr));
/* the rest should be kept read-only (debug version only) */
RANGE_RO(addr + sizeof (struct pool_hdr),
stbuf.st_size - sizeof (struct pool_hdr));
LOG(3, "plp %p", plp);
return plp;
err_free:
Free((void *)plp->rwlockp);
err:
LOG(4, "error clean up");
int oerrno = errno;
util_unmap(addr, stbuf.st_size);
errno = oerrno;
return NULL;
}
示例14: Zero
//.........这里部分代码省略.........
*error_code = ERR_PROXY_AUTH_FAILED;
break;
case 404:
// 404 File Not Found
*error_code = ERR_OBJECT_NOT_FOUND;
break;
case 100:
// Continue
num_continue++;
if (num_continue >= 10)
{
goto DEF;
}
FreeHttpHeader(h);
goto CONT;
case 200:
// Success
break;
default:
// Protocol error
DEF:
*error_code = ERR_PROTOCOL_ERROR;
break;
}
if (*error_code != ERR_NO_ERROR)
{
// An error has occured
Disconnect(s);
ReleaseSock(s);
FreeHttpHeader(h);
return NULL;
}
// Get the length of the content
content_len = GetContentLength(h);
if (max_recv_size != 0)
{
content_len = MIN(content_len, max_recv_size);
}
FreeHttpHeader(h);
socket_buffer = Malloc(socket_buffer_size);
// Receive the content
recv_buf = NewBuf();
while (true)
{
UINT recvsize = MIN(socket_buffer_size, content_len - recv_buf->Size);
UINT size;
if (recv_callback != NULL)
{
if (recv_callback(recv_callback_param,
content_len, recv_buf->Size, recv_buf) == false)
{
// Cancel the reception
*error_code = ERR_USER_CANCEL;
goto RECV_CANCEL;
}
}
if (recvsize == 0)
{
break;
}
size = Recv(s, socket_buffer, recvsize, s->SecureMode);
if (size == 0)
{
// Disconnected
*error_code = ERR_DISCONNECTED;
RECV_CANCEL:
FreeBuf(recv_buf);
Free(socket_buffer);
Disconnect(s);
ReleaseSock(s);
return NULL;
}
WriteBuf(recv_buf, socket_buffer, size);
}
SeekBuf(recv_buf, 0, 0);
Free(socket_buffer);
Disconnect(s);
ReleaseSock(s);
// Transmission
return recv_buf;
}
示例15: Malloc
/*
* make_trans -- Construct a single transform payload
*
* Inputs:
*
* length (output) length of entire transform payload.
* next Next Payload Type (3 = More transforms; 0=No more transforms)
* number Transform number
* cipher The encryption algorithm
* keylen Key length for variable length keys (0=fixed key length)
* hash Hash algorithm
* auth Authentication method
* group DH Group number
* lifetime Lifetime in seconds (0=no lifetime)
* lifesize Life in kilobytes (0=no life)
*
* Returns:
*
* Pointer to transform payload.
*
* This constructs a single transform payload.
* Most of the values are defined in RFC 2409 Appendix A.
*/
unsigned char*make_trans(size_t *length, unsigned next, unsigned number,
unsigned cipher,
unsigned keylen, unsigned hash, unsigned auth,
unsigned group,
unsigned lifetime, unsigned lifesize, int gss_id_flag,
unsigned char *gss_data, size_t gss_data_len)
{
struct isakmp_transform* hdr; /* Transform header */
unsigned char *payload;
unsigned char *attr;
unsigned char *cp;
size_t attr_len; /* Attribute Length */
size_t len; /* Payload Length */
/* Allocate and initialise the transform header */
hdr = Malloc(sizeof(struct isakmp_transform));
memset(hdr, '\0', sizeof(struct isakmp_transform));
hdr->isat_np = next; /* Next payload type */
hdr->isat_transnum = number; /* Transform Number */
hdr->isat_transid = KEY_IKE;
/* Allocate and initialise the mandatory attributes */
add_attr(0, NULL, 'B', OAKLEY_ENCRYPTION_ALGORITHM, 0, cipher, NULL);
add_attr(0, NULL, 'B', OAKLEY_HASH_ALGORITHM, 0, hash, NULL);
add_attr(0, NULL, 'B', OAKLEY_AUTHENTICATION_METHOD, 0, auth, NULL);
add_attr(0, NULL, 'B', OAKLEY_GROUP_DESCRIPTION, 0, group, NULL);
/* Allocate and initialise the optional attributes */
if (keylen)
add_attr(0, NULL, 'B', OAKLEY_KEY_LENGTH, 0, keylen, NULL);
if (lifetime) {
uint32_t lifetime_n = htonl(lifetime);
add_attr(0, NULL, 'B', OAKLEY_LIFE_TYPE, 0,
SA_LIFE_TYPE_SECONDS, NULL);
add_attr(0, NULL, 'V', OAKLEY_LIFE_DURATION, 4, 0,
&lifetime_n);
}
if (lifesize) {
uint32_t lifesize_n = htonl(lifesize);
add_attr(0, NULL, 'B', OAKLEY_LIFE_TYPE, 0,
SA_LIFE_TYPE_KBYTES, NULL);
add_attr(0, NULL, 'V', OAKLEY_LIFE_DURATION, 4, 0,
&lifesize_n);
}
if (gss_id_flag)
add_attr(0, NULL, 'V', OAKLEY_GSS_ID, gss_data_len, 0,
gss_data);
/* Finalise attributes and fill in length value */
attr = add_attr(1, &attr_len, '\0', 0, 0, 0, NULL);
len = attr_len + sizeof(struct isakmp_transform);
hdr->isat_length = htons(len); /* Transform length */
*length = len;
/* Allocate memory for payload and copy structures to payload */
payload = Malloc(len);
cp = payload;
memcpy(cp, hdr, sizeof(struct isakmp_transform));
free(hdr);
cp += sizeof(struct isakmp_transform);
memcpy(cp, attr, attr_len);
free(attr);
return payload;
//.........这里部分代码省略.........