本文整理汇总了C++中os_realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ os_realloc函数的具体用法?C++ os_realloc怎么用?C++ os_realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了os_realloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fd_log_debug
struct radius_attr_hdr *radius_msg_add_attr(struct radius_msg *msg, u8 type,
const u8 *data, size_t data_len)
{
size_t buf_needed;
struct radius_attr_hdr *attr;
if (data_len > RADIUS_MAX_ATTR_LEN) {
fd_log_debug("radius_msg_add_attr: too long attribute (%lu bytes)",
(unsigned long) data_len);
return NULL;
}
buf_needed = msg->buf_used + sizeof(*attr) + data_len;
if (msg->buf_size < buf_needed) {
/* allocate more space for message buffer */
unsigned char *nbuf;
size_t nlen = msg->buf_size;
while (nlen < buf_needed)
nlen *= 2;
nbuf = os_realloc(msg->buf, nlen);
if (nbuf == NULL)
return NULL;
msg->buf = nbuf;
msg->hdr = (struct radius_hdr *) msg->buf;
os_memset(msg->buf + msg->buf_size, 0, nlen - msg->buf_size);
msg->buf_size = nlen;
}
attr = (struct radius_attr_hdr *) (msg->buf + msg->buf_used);
attr->type = type;
attr->length = sizeof(*attr) + data_len;
if (data_len > 0)
os_memcpy(attr + 1, data, data_len);
msg->buf_used += sizeof(*attr) + data_len;
if (radius_msg_add_attr_to_array(msg, attr))
return NULL;
return attr;
}
示例2: radius_msg_add_attr_to_array
static int radius_msg_add_attr_to_array(struct radius_msg *msg,
struct radius_attr_hdr *attr)
{
if (msg->attr_used >= msg->attr_size) {
struct radius_attr_hdr **nattrs;
int nlen = msg->attr_size * 2;
nattrs = os_realloc(msg->attrs, nlen * sizeof(*msg->attrs));
if (nattrs == NULL)
return -1;
msg->attrs = nattrs;
msg->attr_size = nlen;
}
msg->attrs[msg->attr_used++] = attr;
return 0;
}
示例3: OS_MarkGroup
/* Mark rules that match specific group (for if_matched_group) */
int OS_MarkGroup(RuleNode *r_node, RuleInfo *orig_rule)
{
/* If no r_node is given, get first node */
if (r_node == NULL) {
r_node = OS_GetFirstRule();
}
while (r_node) {
if (OSMatch_Execute(r_node->ruleinfo->group,
strlen(r_node->ruleinfo->group),
orig_rule->if_matched_group)) {
unsigned int rule_g = 0;
if (r_node->ruleinfo->group_prev_matched) {
while (r_node->ruleinfo->group_prev_matched[rule_g]) {
rule_g++;
}
}
os_realloc(r_node->ruleinfo->group_prev_matched,
(rule_g + 2)*sizeof(OSList *),
r_node->ruleinfo->group_prev_matched);
r_node->ruleinfo->group_prev_matched[rule_g] = NULL;
r_node->ruleinfo->group_prev_matched[rule_g + 1] = NULL;
/* Set the size */
r_node->ruleinfo->group_prev_matched_sz = rule_g + 1;
r_node->ruleinfo->group_prev_matched[rule_g] =
orig_rule->group_search;
}
/* Check if the child has a rule */
if (r_node->child) {
OS_MarkGroup(r_node->child, orig_rule);
}
r_node = r_node->next;
}
return (0);
}
示例4: add_str
static void add_str(void *ctx_ptr, const char *fmt, ...)
{
struct str_buf *str = ctx_ptr;
va_list ap;
char *n;
int len;
n = os_realloc(str->buf, str->len + MAX_STR + 2);
if (n == NULL)
return;
str->buf = n;
va_start(ap, fmt);
len = vsnprintf(str->buf + str->len, MAX_STR, fmt, ap);
va_end(ap);
if (len >= MAX_STR)
len = MAX_STR - 1;
str->len += len;
str->buf[str->len] = '\0';
}
示例5: nss_io_send
static PRInt32 nss_io_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
PRIntn flags, PRIntervalTime timeout) {
struct tls_connection *conn = (struct tls_connection *) fd->secret;
u8 *nbuf;
wpa_printf(MSG_DEBUG, "NSS: I/O %s", __func__);
wpa_hexdump(MSG_MSGDUMP, "NSS: I/O send data", buf, amount);
nbuf = os_realloc(conn->push_buf, conn->push_buf_len + amount);
if (nbuf == NULL) {
wpa_printf(MSG_ERROR, "NSS: Failed to allocate memory for the "
"data to be sent");
return PR_FAILURE;
}
os_memcpy(nbuf + conn->push_buf_len, buf, amount);
conn->push_buf = nbuf;
conn->push_buf_len += amount;
return amount;
}
示例6: radius_msg_add_attr_to_array
int radius_msg_add_attr_to_array(struct radius_msg *msg,
struct radius_attr_hdr *attr)
{
if (msg->attr_used >= msg->attr_size) {
size_t *nattr_pos;
int nlen = msg->attr_size * 2;
nattr_pos = os_realloc(msg->attr_pos,
nlen * sizeof(*msg->attr_pos));
if (nattr_pos == NULL)
return -1;
msg->attr_pos = nattr_pos;
msg->attr_size = nlen;
}
msg->attr_pos[msg->attr_used++] = (unsigned char *) attr - msg->buf;
return 0;
}
示例7: eloop_register_read_sock
int eloop_register_read_sock(int sock, eloop_sock_handler handler,
void *eloop_data, void *user_data)
{
WSAEVENT event;
struct eloop_sock *tmp;
if (eloop_prepare_handles())
return -1;
event = WSACreateEvent();
if (event == WSA_INVALID_EVENT) {
printf("WSACreateEvent() failed: %d\n", WSAGetLastError());
return -1;
}
if (WSAEventSelect(sock, event, FD_READ)) {
printf("WSAEventSelect() failed: %d\n", WSAGetLastError());
WSACloseEvent(event);
return -1;
}
tmp = os_realloc(eloop.readers,
(eloop.reader_count + 1) * sizeof(struct eloop_sock));
if (tmp == NULL) {
WSAEventSelect(sock, event, 0);
WSACloseEvent(event);
return -1;
}
tmp[eloop.reader_count].sock = sock;
tmp[eloop.reader_count].eloop_data = eloop_data;
tmp[eloop.reader_count].user_data = user_data;
tmp[eloop.reader_count].handler = handler;
tmp[eloop.reader_count].event = event;
eloop.reader_count++;
eloop.readers = tmp;
if (sock > eloop.max_sock)
eloop.max_sock = sock;
eloop.reader_table_changed = 1;
return 0;
}
示例8: eloop_register_signal
int eloop_register_signal(int sig, eloop_signal_handler handler,
void *user_data) {
struct eloop_signal *tmp;
tmp = (struct eloop_signal *)
os_realloc(eloop.signals,
(eloop.signal_count + 1) *
sizeof (struct eloop_signal));
if (tmp == NULL)
return -1;
tmp[eloop.signal_count].sig = sig;
tmp[eloop.signal_count].user_data = user_data;
tmp[eloop.signal_count].handler = handler;
tmp[eloop.signal_count].signaled = 0;
eloop.signal_count++;
eloop.signals = tmp;
signal(sig, eloop_handle_signal);
return 0;
}
示例9: wpa_config_add_prio_network
/**
* wpa_config_add_prio_network - Add a network to priority lists
* @config: Configuration data from wpa_config_read()
* @ssid: Pointer to the network configuration to be added to the list
* Returns: 0 on success, -1 on failure
*
* This function is used to add a network block to the priority list of
* networks. This must be called for each network when reading in the full
* configuration. In addition, this can be used indirectly when updating
* priorities by calling wpa_config_update_prio_list().
*/
int wpa_config_add_prio_network(struct wpa_config *config,
struct wpa_ssid *ssid)
{
int prio;
struct wpa_ssid *prev, **nlist;
/*
* Add to an existing priority list if one is available for the
* configured priority level for this network.
*/
for (prio = 0; prio < config->num_prio; prio++) {
prev = config->pssid[prio];
if (prev->priority == ssid->priority) {
while (prev->pnext)
prev = prev->pnext;
prev->pnext = ssid;
return 0;
}
}
/* First network for this priority - add a new priority list */
nlist = os_realloc(config->pssid,
(config->num_prio + 1) * sizeof(struct wpa_ssid *));
if (nlist == NULL)
return -1;
for (prio = 0; prio < config->num_prio; prio++) {
if (nlist[prio]->priority < ssid->priority)
break;
}
os_memmove(&nlist[prio + 1], &nlist[prio],
(config->num_prio - prio) * sizeof(struct wpa_ssid *));
nlist[prio] = ssid;
config->num_prio++;
config->pssid = nlist;
return 0;
}
示例10: circle_register_signal
int circle_register_signal(int sig, circle_signal_handler handler,
void *user_data)
{
struct circle_signal *tmp;
tmp = (struct circle_signal *)
os_realloc(circle.signals,
(circle.signal_count + 1) *
sizeof(struct circle_signal));
if (tmp == NULL)
return -1;
tmp[circle.signal_count].sig = sig;
tmp[circle.signal_count].user_data = user_data;
tmp[circle.signal_count].handler = handler;
tmp[circle.signal_count].signaled = 0;
circle.signal_count++;
circle.signals = tmp;
signal(sig, circle_handle_signal);
return 0;
}
示例11: idl_constExpressionImage
char *
idl_constExpressionImage (
idl_constExpression constExpression)
{
char *image = NULL;
char *operandImage = NULL;
int i;
int newLen;
if (c_iterLength (constExpression->operands) == 1) {
/* Unary operator */
operandImage = idl_operandImage (idl_operand(c_iterObject (constExpression->operands, 0)));
newLen = strlen (operatorImage(constExpression->kind)) + strlen (operandImage) + 3;
image = os_malloc (newLen);
snprintf (image, newLen, "(%s%s)", operatorImage(constExpression->kind), operandImage);
os_free (operandImage);
} else {
/* Binary operator */
for (i = 0; i < c_iterLength (constExpression->operands); i++) {
operandImage = idl_operandImage (idl_operand(c_iterObject (constExpression->operands, i)));
if (image == NULL) {
newLen = strlen (operandImage) + 2;
image = os_malloc (newLen);
os_strncpy (image, "(", newLen);
} else {
newLen = strlen (image) + strlen (operatorImage(constExpression->kind)) + strlen (operandImage) + 4;
image = os_realloc (image, newLen);
strncat (image, " ", newLen);
os_strncat (image, operatorImage(constExpression->kind), newLen);
strncat (image, " ", newLen);
}
os_strncat (image, operandImage, newLen);
os_free (operandImage);
}
strncat (image, ")", newLen);
}
return image;
}
示例12: storage_add_spof_group
int storage_add_spof_group(storage_t *storage, spof_id_t spof_id,
spof_group_t **sg)
{
uint32_t i;
spof_group_t *new_spof_groups;
EXA_ASSERT(storage != NULL);
EXA_ASSERT(sg != NULL);
*sg = NULL;
if (!SPOF_ID_IS_VALID(spof_id))
return -EINVAL;
for (i = 0; i < storage->num_spof_groups; i++)
if (storage->spof_groups[i].spof_id == spof_id)
return -EEXIST;
if (storage->num_spof_groups == EXA_MAX_NODES_NUMBER)
return -ENOSPC;
new_spof_groups = os_realloc(storage->spof_groups,
(storage->num_spof_groups + 1) * sizeof(spof_group_t));
if (new_spof_groups == NULL)
return -ENOMEM;
spof_group_init(&new_spof_groups[storage->num_spof_groups]);
new_spof_groups[storage->num_spof_groups].spof_id = spof_id;
*sg = &new_spof_groups[storage->num_spof_groups];
storage->spof_groups = new_spof_groups;
storage->num_spof_groups++;
return 0;
}
示例13: ap_sa_query_timer
static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
{
struct hostapd_data *hapd = eloop_ctx;
struct sta_info *sta = timeout_ctx;
unsigned int timeout, sec, usec;
u8 *trans_id, *nbuf;
if (sta->sa_query_count > 0 &&
ap_check_sa_query_timeout(hapd, sta))
return;
nbuf = os_realloc(sta->sa_query_trans_id,
(sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
if (nbuf == NULL)
return;
if (sta->sa_query_count == 0) {
/* Starting a new SA Query procedure */
os_get_time(&sta->sa_query_start);
}
trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
sta->sa_query_trans_id = nbuf;
sta->sa_query_count++;
os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
timeout = hapd->conf->assoc_sa_query_retry_timeout;
sec = ((timeout / 1000) * 1024) / 1000;
usec = (timeout % 1000) * 1024;
eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"association SA Query attempt %d", sta->sa_query_count);
#ifdef NEED_AP_MLME
ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
#endif /* NEED_AP_MLME */
}
示例14: hostapd_register_probereq_cb
int hostapd_register_probereq_cb(struct hostapd_data *hapd,
int (*cb)(void *ctx, const u8 *sa,
const u8 *da, const u8 *bssid,
const u8 *ie, size_t ie_len,
int ssi_signal),
void *ctx)
{
struct hostapd_probereq_cb *n;
n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) *
sizeof(struct hostapd_probereq_cb));
if (n == NULL)
return -1;
hapd->probereq_cb = n;
n = &hapd->probereq_cb[hapd->num_probereq_cb];
hapd->num_probereq_cb++;
n->cb = cb;
n->ctx = ctx;
return 0;
}
示例15: dump_syscheck_entry
int dump_syscheck_entry(syscheck_config *syscheck, const char *entry, int vals, int reg, const char *restrictfile)
{
unsigned int pl = 0;
if (reg == 1) {
#ifdef WIN32
if (syscheck->registry == NULL) {
os_calloc(2, sizeof(registry), syscheck->registry);
syscheck->registry[pl + 1].entry = NULL;
syscheck->registry[pl].arch = vals;
os_strdup(entry, syscheck->registry[pl].entry);
} else {
while (syscheck->registry[pl].entry != NULL) {
pl++;
}
os_realloc(syscheck->registry, (pl + 2) * sizeof(registry),
syscheck->registry);
syscheck->registry[pl + 1].entry = NULL;
syscheck->registry[pl].arch = vals;
os_strdup(entry, syscheck->registry[pl].entry);
}
#endif
}
else {
if (syscheck->dir == NULL) {
os_calloc(2, sizeof(char *), syscheck->dir);
syscheck->dir[pl + 1] = NULL;
os_strdup(entry, syscheck->dir[pl]);
os_calloc(2, sizeof(int), syscheck->opts);
syscheck->opts[pl + 1] = 0;
syscheck->opts[pl] = vals;
os_calloc(2, sizeof(OSMatch *), syscheck->filerestrict);
syscheck->filerestrict[pl] = NULL;
syscheck->filerestrict[pl + 1] = NULL;
} else {
while (syscheck->dir[pl] != NULL) {
pl++;
}
os_realloc(syscheck->dir, (pl + 2) * sizeof(char *),
syscheck->dir);
syscheck->dir[pl + 1] = NULL;
os_strdup(entry, syscheck->dir[pl]);
os_realloc(syscheck->opts, (pl + 2) * sizeof(int),
syscheck->opts);
syscheck->opts[pl + 1] = 0;
syscheck->opts[pl] = vals;
os_realloc(syscheck->filerestrict, (pl + 2) * sizeof(OSMatch *),
syscheck->filerestrict);
syscheck->filerestrict[pl] = NULL;
syscheck->filerestrict[pl + 1] = NULL;
}
if (restrictfile) {
os_calloc(1, sizeof(OSMatch), syscheck->filerestrict[pl]);
if (!OSMatch_Compile(restrictfile, syscheck->filerestrict[pl], 0)) {
OSMatch *ptm;
ptm = syscheck->filerestrict[pl];
merror(REGEX_COMPILE, __local_name, restrictfile,
ptm->error);
free(syscheck->filerestrict[pl]);
syscheck->filerestrict[pl] = NULL;
}
}
}
return (1);
}