static gnrc_pktsnip_t *_build_ipv6_packet(const ipv6_addr_t *src, const ipv6_addr_t *dst, uint8_t nh, void *data, size_t data_len, uint16_t netif) { gnrc_pktsnip_t *netif_hdr, *ipv6, *payload; ipv6_hdr_t *ipv6_hdr; if ((netif > INT16_MAX) || (data_len > UINT16_MAX)) { return NULL; } payload = gnrc_pktbuf_add(NULL, data, data_len, GNRC_NETTYPE_UNDEF); if (payload == NULL) { return NULL; } ipv6 = gnrc_ipv6_hdr_build(NULL, src, dst); if (ipv6 == NULL) { return NULL; } ipv6_hdr = ipv6->data; ipv6_hdr->len = byteorder_htons((uint16_t)payload->size); ipv6_hdr->nh = nh; ipv6_hdr->hl = 64; LL_APPEND(payload, ipv6); netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0); if (netif_hdr == NULL) { return NULL; } ((gnrc_netif_hdr_t *)netif_hdr->data)->if_pid = (kernel_pid_t)netif; LL_APPEND(payload, netif_hdr); return payload; }
int main() { int i; el els[10], *e, *tmp, *tmp2; for(i=0;i<10;i++) els[i].id='a'+i; /* test LL macros */ printf("LL macros\n"); LL_APPEND(head,&els[0]); LL_APPEND(head,&els[1]); LL_APPEND(head,&els[2]); LL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); LL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); LL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); LL_FOREACH_SAFE(head,e,tmp) LL_DELETE(head,e); printf("\n"); /* test DL macros */ printf("DL macros\n"); DL_APPEND(head,&els[0]); DL_APPEND(head,&els[1]); DL_APPEND(head,&els[2]); DL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); DL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); DL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); DL_FOREACH_SAFE(head,e,tmp) DL_DELETE(head,e); printf("\n"); /* test CDL macros */ printf("CDL macros\n"); CDL_PREPEND(head,&els[0]); CDL_PREPEND(head,&els[1]); CDL_PREPEND(head,&els[2]); CDL_FOREACH(head,e) printf("%c ", e->id); printf("\n"); CDL_SEARCH_SCALAR(head, e, id, 'b'); if (e) printf("search scalar found b\n"); CDL_SEARCH(head, e, &els[0], eltcmp); if (e) printf("search found %c\n",e->id); CDL_FOREACH_SAFE(head,e,tmp,tmp2) CDL_DELETE(head,e); return 0; }
int db_change_parent(Objid oid, Objid parent) { Objid old_parent; if (!dbpriv_check_properties_for_chparent(oid, parent)) return 0; if (objects[oid]->child == NOTHING && objects[oid]->verbdefs == NULL) { /* Since this object has no children and no verbs, we know that it can't have had any part in affecting verb lookup, since we use first parent with verbs as a key in the verb lookup cache. */ /* The "no kids" rule is necessary because potentially one of the kids could have verbs on it--and that kid could have cache entries for THIS object's parentage. */ /* In any case, don't clear the cache. */ ; } else { db_priv_affected_callable_verb_lookup(); } old_parent = objects[oid]->parent; if (old_parent != NOTHING) LL_REMOVE(old_parent, child, oid, sibling); if (parent != NOTHING) LL_APPEND(parent, child, oid, sibling); objects[oid]->parent = parent; dbpriv_fix_properties_after_chparent(oid, old_parent); return 1; }
void nitro_async_schedule(nitro_async_t *a) { pthread_mutex_lock(&the_runtime->l_async); LL_APPEND(the_runtime->async_queue, a); pthread_mutex_unlock(&the_runtime->l_async); ev_async_send(the_runtime->the_loop, &the_runtime->thread_wake); }
static void gethttpmirrors(struct pkg_repo *repo, const char *url) { FILE *f; char *line = NULL; size_t linecap = 0; ssize_t linelen; struct http_mirror *m; struct url *u; if ((f = fetchGetURL(url, "")) == NULL) return; while ((linelen = getline(&line, &linecap, f)) > 0) { if (strncmp(line, "URL:", 4) == 0) { /* trim '\n' */ if (line[linelen - 1] == '\n') line[linelen - 1 ] = '\0'; line += 4; while (isspace(*line)) { line++; } if (*line == '\0') continue; if ((u = fetchParseURL(line)) != NULL) { m = malloc(sizeof(struct http_mirror)); m->url = u; LL_APPEND(repo->http, m); } } } fclose(f); return; }
void gnrc_sixlowpan_frag_rbuf_dispatch_when_complete(gnrc_sixlowpan_rbuf_t *rbuf, gnrc_netif_hdr_t *netif_hdr) { assert(rbuf); assert(netif_hdr); if (rbuf->current_size == rbuf->pkt->size) { gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(rbuf->src, rbuf->src_len, rbuf->dst, rbuf->dst_len); if (netif == NULL) { DEBUG("6lo rbuf: error allocating netif header\n"); gnrc_pktbuf_release(rbuf->pkt); gnrc_sixlowpan_frag_rbuf_remove(rbuf); return; } /* copy the transmit information of the latest fragment into the newly * created header to have some link_layer information. The link_layer * info of the previous fragments is discarded. */ gnrc_netif_hdr_t *new_netif_hdr = netif->data; new_netif_hdr->if_pid = netif_hdr->if_pid; new_netif_hdr->flags = netif_hdr->flags; new_netif_hdr->lqi = netif_hdr->lqi; new_netif_hdr->rssi = netif_hdr->rssi; LL_APPEND(rbuf->pkt, netif); gnrc_sixlowpan_dispatch_recv(rbuf->pkt, NULL, 0); gnrc_sixlowpan_frag_rbuf_remove(rbuf); } }
static Interface* loadInterfaces(Env* env, Class* clazz) { ClassInfoHeader* header = lookupClassInfo(env, clazz->name, !clazz->classLoader || !clazz->classLoader->parent ? _bcBootClassesHash : _bcClassesHash); if (!header) return NULL; ClassInfo ci; jint i; void* p = header; readClassInfo(&p, &ci); Interface* first = NULL; for (i = 0; i < ci.interfaceCount; i++) { const char* interfaceName = readInterfaceName(&p); Class* interfaceClass = rvmFindClassUsingLoader(env, interfaceName, clazz->classLoader); if (!interfaceClass) goto error; Interface* interf = rvmAllocateInterface(env, interfaceClass); if (!interf) goto error; LL_APPEND(first, interf); // Interfaces has to be in the correct order so we need to use the slower LL_APPEND } return first; error: while (first) { Interface* next = first->next; rvmFreeMemoryUncollectable(env, first); first = next; } return NULL; }
ControlledLeds newControlledLed(Led led) { struct LedGroup group = (struct LedGroup){ &led, 1 }; return newControlledLedGroup(&group); } ControlledLeds newControlledLedGroup(LedGroup group) { if (group == NULL) return Invalid(ControlledLeds); _ControlledLeds leds = kalloc(sizeof(struct _ControlledLeds)); if (!leds) return Invalid(ControlledLeds); LedList *underlying = addNewLedsToList(group); if (!underlying) { free(leds); return Invalid(ControlledLeds); } leds->mask = 0; leds->leds = underlying; leds->count = group->count; leds->next = NULL; ControlledLeds result = As(ControlledLeds, leds); controlLeds(result, LedsDisabled); LL_APPEND(controlled_leds, leds); return result; } static void cleanUnderlyingLeds(ControlledLeds leds) { LedList elem = NULL, tmp = NULL; LL_FOREACH_SAFE(underlying_leds, elem, tmp) { for (int i = 0; i < LEDS->count; i++) { if (elem == LEDS->leds[i]) { reduceRefcount(elem); } } } }
static LedList *addNewLedsToList(LedGroup group) { for (uint8_t i = 0; i < group->count; i++) { if (!ledValid(group->leds[i])) return NULL; } LedList *list = kalloc(group->count * sizeof(LedList)); if (!list) return NULL; for (int i = 0; i < group->count; i++) { Led led = group->leds[i]; LedList existing = NULL; LL_FOREACH(underlying_leds, existing) { if (Equal(existing->led, led)) break; } if (existing == NULL) { existing = kalloc(sizeof(struct LedList)); if (!existing) { // Cleanup all leds added so far... for (int j = 0; j < i; j++) { reduceRefcount(list[j]); } free(list); return NULL; } existing->led = led; existing->next = NULL; existing->enabled = FALSE; existing->references = 0; LL_APPEND(underlying_leds, existing); } existing->references++; list[i] = existing; } return list; }
/** * Add a server response to the server response list * * @param response initialized server response that is created by this function * @param requestHandle - handle of the response * * @return * OCStackResult */ static OCStackResult AddServerResponse (OCServerResponse ** response, OCRequestHandle requestHandle) { if (!response) { return OC_STACK_INVALID_PARAM; } OCServerResponse * serverResponse = NULL; serverResponse = (OCServerResponse *) OICCalloc(1, sizeof(OCServerResponse)); VERIFY_NON_NULL(serverResponse); serverResponse->payload = NULL; serverResponse->requestHandle = requestHandle; *response = serverResponse; OIC_LOG(INFO, TAG, "Server Response Added!!"); LL_APPEND (serverResponseList, serverResponse); return OC_STACK_OK; exit: if (serverResponse) { OICFree(serverResponse); serverResponse = NULL; } *response = NULL; return OC_STACK_NO_MEMORY; }
void pthread_scheduler_push_kernel (kernel_run_command *run_cmd) { PTHREAD_LOCK (&scheduler.wq_lock, NULL); LL_APPEND (scheduler.kernel_queue, run_cmd); pthread_cond_broadcast (&scheduler.wake_pool); PTHREAD_UNLOCK (&scheduler.wq_lock); }
OCStackResult AddPlugin (PIPluginBase * plugin) { if (!plugin) { return OC_STACK_INVALID_PARAM; } LL_APPEND(pluginList, plugin); return OC_STACK_OK; }
static int rpcfg_string(void *data, const unsigned char *s, size_t len) { struct rp_json_ctx *ctx = (struct rp_json_ctx *)data; switch (ctx->state) { case ROOT_CONFIG_IDENTITY_NICKS_ITEMS: { rp_str_list_t *l = rp_palloc(ctx->pool, sizeof(*l)); rpcfg_mkstr(ctx->pool, &l->str, (const char *)s, len); LL_APPEND(ctx->cfg->identity.nicks, l); return 1; } case ROOT_CONFIG_IDENTITY_NAME: rpcfg_mkstr(ctx->pool, &ctx->cfg->identity.name, (const char *)s, len); ctx->state = ROOT_CONFIG_IDENTITY; return 1; case ROOT_CONFIG_IDENTITY_LOGIN: rpcfg_mkstr(ctx->pool, &ctx->cfg->identity.login, (const char *)s, len); ctx->state = ROOT_CONFIG_IDENTITY; return 1; break; case ROOT_CONFIG_SERVERS_ITEMS_HOST: rpcfg_mkstr(ctx->pool, &ctx->server->host, (const char *)s, len); ctx->state = ROOT_CONFIG_SERVERS_ITEMS; return 1; case ROOT_CONFIG_SERVERS_ITEMS_PORT: rpcfg_mkstr(ctx->pool, &ctx->server->port, (const char *)s, len); ctx->state = ROOT_CONFIG_SERVERS_ITEMS; return 1; case ROOT_CONFIG_CHANNELS_ITEMS: ctx->channel = rp_pcalloc(ctx->pool, sizeof(*ctx->channel)); ctx->channel->key.len = 0; rpcfg_mkstr(ctx->pool, &ctx->channel->name, (const char *)s, len); LL_APPEND(ctx->cfg->channels, ctx->channel); return 1; default: return 0; } return 1; }
int pubsub_url_cb(char *value) { struct pubsub_url *ps_url; ps_url = malloc(sizeof(struct pubsub_url)); ps_url->address = strdup(value); ps_url->id = num_pubsub_urls; LL_APPEND(pubsub_urls, ps_url); num_pubsub_urls++; return 1; }
/* Loads a list of allowed hostnames and ports from file. Format is hostname:port*/ void load_rules() { char *ahost=NULL; int aport=0; char line[100 + 1] = ""; FILE *file = NULL; rule *rule_obj = NULL; int valid_rules = 0; file = fopen(rules_file, "r"); if (file == NULL) { log_printf(L_WARNING, "Could not open rules file (%s)\n", rules_file); return; } while (fgets(line, sizeof(line), file)) { /* allow comments & white lines */ if (line[0]=='#'||line[0]=='\n') { continue; } if (parse_pipe_port_forward(line, &ahost, &aport) >= 0) { if (aport > 0 && aport < 65535) { rule_obj = (rule *)calloc(sizeof(rule), 1); if(!rule_obj) { log_printf(L_ERROR, "Could not allocate memory for rule"); exit(1); } rule_obj->port = aport; rule_obj->host = strdup(ahost); LL_APPEND(rules, rule_obj); valid_rules++; } else { log_printf(L_WARNING, "Invalid port in line: %s\n", line); } } else { log_printf(L_WARNING, "Could not parse line: %s\n", line); } } fclose(file); /* save valid rules in global variable */ nrules = valid_rules; log_printf(L_INFO, "Loaded %d rules\n", nrules); if (nrules==0 && rules_policy != NONE){ log_printf(L_WARNING, "No rules loaded! NO CONNECTIONS WILL BE ALLOWED!\n"); } }
int coap_insert(coap_list_t **head, coap_list_t *node) { if (!node) { coap_log(LOG_WARNING, "cannot create option Proxy-Uri\n"); } else { /* must append at the list end to avoid re-ordering of * options during sort */ LL_APPEND((*head), node); } return node != NULL; }
static jboolean initClasspathEntries(Env* env, char* basePath, char** raw, ClasspathEntry** first) { jint i = 0; while (raw[i]) { ClasspathEntry* entry = rvmAllocateMemoryAtomicUncollectable(env, sizeof(ClasspathEntry)); if (!entry) return FALSE; absolutize(basePath, raw[i], entry->jarPath); LL_APPEND(*first, entry); i++; } return TRUE; }
void db_change_location(Objid oid, Objid location) { Objid old_location = objects[oid]->location; if (valid(old_location)) LL_REMOVE(old_location, contents, oid, next); if (valid(location)) LL_APPEND(location, contents, oid, next); objects[oid]->location = location; }
void pocl_command_enqueue (cl_command_queue command_queue, _cl_command_node *node) { POCL_LOCK_OBJ(command_queue); LL_APPEND (command_queue->root, node); POCL_UNLOCK_OBJ(command_queue); #ifdef POCL_DEBUG_BUILD if (pocl_is_option_set("POCL_IMPLICIT_FINISH")) POclFinish (command_queue); #endif POCL_UPDATE_EVENT_QUEUED (&node->event); }
TWResultCode TWAddTWSock(TWSock * sock, PIPlugin_Zigbee * plugin, const char * fileLoc) { if(!sock || !plugin || !fileLoc) { return TW_RESULT_ERROR_INVALID_PARAMS; } TWSock * out = NULL; TWSock * temp = NULL; LL_FOREACH_SAFE(g_twSockList, out, temp) { if(out == sock) { // Ignore requests to add a socket that's already in the queue. return TW_RESULT_OK; } } sock->plugin = plugin; sock->fd = open(fileLoc, O_RDWR | O_NOCTTY | O_SYNC); if(sock->fd <= 0) { OC_LOG_V(INFO, TAG, "Could not open port. Errno is: %d\n", errno); return TW_RESULT_ERROR; } // set speed to 19,200 bps, 8n1 (no parity), no blocking. int ret = SetTerminalInfo(sock->fd, DEVICE_BAUDRATE, 0, 0); if(ret != 0) { TWResultCode result = TWCloseTWSock(sock); if(result != TW_RESULT_OK) { return result; } return TW_RESULT_ERROR; } sock->buffer = NULL; sock->queue = NULL; pthread_mutexattr_t mutexAttr; pthread_mutexattr_init(&mutexAttr); pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_ERRORCHECK); pthread_mutex_init(&(sock->mutex), &mutexAttr); // TODO: Use OIC_MUTEX instead. pthread_cond_init(&(sock->queueCV), NULL); sock->next = NULL; sock->isActive = true; LL_APPEND(g_twSockList, sock); return TW_RESULT_OK; }
int process_list_processes(process_list_t **result) { proc_t proc_info; #ifdef COLLECT_STATS size_t proc_count = 0; extern stats_t stats; struct timeval tv1; gettimeofday(&tv1, NULL); #endif PROCTAB *proc = openproc(PROC_FILLMEM | PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLCOM); memset(&proc_info, 0, sizeof(proc_info)); while (readproc(proc, &proc_info) != NULL) { process_t *to_add = calloc(1, sizeof(process_t)); to_add->tgid = proc_info.tgid; to_add->name = proc_info.cmd; if (proc_info.cmdline != NULL) { to_add->cmdline = strjoinv(" ", proc_info.cmdline); } to_add->vms = proc_info.vm_size; to_add->rss = proc_info.vm_rss; to_add->threads_num = proc_info.nlwp; to_add->utime = proc_info.utime; to_add->stime = proc_info.stime; to_add->user = proc_info.euid; #ifdef COLLECT_STATS proc_count++; #endif LL_APPEND((*result)->processes, to_add); // printf("%20s:\t%5ld\t%5lld\t%5lld\n", proc_info.cmd, proc_info.resident, // proc_info.utime, proc_info.stime); } closeproc(proc); struct timeval tv; gettimeofday(&tv, NULL); (*result)->timestamp = 1000000 * tv.tv_sec + tv.tv_usec; #ifdef COLLECT_STATS uint64_t t1 = 1000000 * tv1.tv_sec + tv1.tv_usec; stats.ps_dur = (*result)->timestamp - t1; stats.ps_times_count += 1; stats.ps_last_count = proc_count; #endif return 1; }
OCStackResult AddObserver (const char *resUri, const char *query, OCObservationId obsId, OCCoAPToken *token, OCDevAddr *addr, OCResource *resHandle, OCQualityOfService qos) { ResourceObserver *obsNode = NULL; obsNode = (ResourceObserver *) OCCalloc(1, sizeof(ResourceObserver)); if (obsNode) { obsNode->observeId = obsId; obsNode->resUri = (unsigned char *)OCMalloc(strlen(resUri)+1); VERIFY_NON_NULL (obsNode->resUri); memcpy (obsNode->resUri, resUri, strlen(resUri)+1); obsNode->qos = qos; if(query) { obsNode->query = (unsigned char *)OCMalloc(strlen(query)+1); VERIFY_NON_NULL (obsNode->query); memcpy (obsNode->query, query, strlen(query)+1); } obsNode->token.tokenLength = token->tokenLength; memcpy (obsNode->token.token, token->token, token->tokenLength); obsNode->addr = (OCDevAddr *)OCMalloc(sizeof(OCDevAddr)); VERIFY_NON_NULL (obsNode->addr); memcpy (obsNode->addr, addr, sizeof(OCDevAddr)); obsNode->resource = resHandle; LL_APPEND (serverObsList, obsNode); return OC_STACK_OK; } exit: if (obsNode) { OCFree(obsNode->resUri); OCFree(obsNode->query); OCFree(obsNode->addr); OCFree(obsNode); } return OC_STACK_NO_MEMORY; }
void genQuad(enum code_ops *operation, struct symbol *address_0, struct symbol *address_1, struct symbol *address_2, int jmpTo) { /**Quadrupel Code Generation**/ ir_code *c = NULL; c = (struct ir_code*) malloc(sizeof(struct ir_code)); c->code.counter_id = num_of_codes; c->code.operation = operation; c->code.address_0 = address_0; c->code.address_1 = address_1; c->code.address_2 = address_2; c->code.jmpTo = jmpTo; LL_APPEND(code_list,c); num_of_codes++; }
int Mavlink::configure_stream(const char *stream_name, const float rate) { /* calculate interval in us, 0 means disabled stream */ unsigned int interval = (rate > 0.0f) ? (1000000.0f / rate) : 0; /* search if stream exists */ MavlinkStream *stream; LL_FOREACH(_streams, stream) { if (strcmp(stream_name, stream->get_name()) == 0) { if (interval > 0) { /* set new interval */ stream->set_interval(interval); } else { /* delete stream */ LL_DELETE(_streams, stream); delete stream; warnx("deleted stream %s", stream->get_name()); } return OK; } } if (interval == 0) { /* stream was not active and is requested to be disabled, do nothing */ return OK; } /* search for stream with specified name in supported streams list */ for (unsigned int i = 0; streams_list[i] != nullptr; i++) { if (strcmp(stream_name, streams_list[i]->get_name()) == 0) { /* create new instance */ stream = streams_list[i]->new_instance(); stream->set_channel(get_channel()); stream->set_interval(interval); stream->subscribe(this); LL_APPEND(_streams, stream); return OK; } } /* if we reach here, the stream list does not contain the stream */ warnx("stream %s not found", stream_name); return ERROR; }
int cpw_process_add_arg(cpwprocess *process, const char *arg) { cpwcommandarg *newarg; newarg = cpw_commandarg_new(); if ( newarg ) { strncpy(newarg->arg, arg, CPW_COMMAND_MAX_ARG_LENGTH - 1); newarg->arg[CPW_COMMAND_MAX_ARG_LENGTH - 1] = '\0'; LL_APPEND(process->args, newarg); CPW_DEBUG("cpwprocess: adding value '%s' to arglist\n", arg); return 1; } else { CPW_LOG_ERROR("error getting mem for processarg\n"); return 0; } }
texture_t *texture_new_surface(int w, int h, int flags) { texture_t *tex; tex = calloc(1, sizeof(*tex)); tex->tex_w = next_pow2(w); tex->tex_h = next_pow2(h); tex->w = w; tex->h = h; tex->flags = flags | TF_HAS_TEX; tex->format = (flags & TF_RGB) ? GL_RGB : GL_RGBA; texture_create_empty(tex); tex->ref = 1; LL_APPEND(g_textures, tex); return tex; }
jboolean rvmAddInterface(Env* env, Class* clazz, Class* interf) { if (!CLASS_IS_INTERFACE(interf)) { // TODO: Message should look like ? rvmThrowIncompatibleClassChangeError(env, ""); return FALSE; } Interface* interface = rvmAllocateMemory(env, sizeof(Interface)); if (!interface) return FALSE; interface->interface = interf; if (clazz->_interfaces == &INTERFACES_NOT_LOADED) { clazz->_interfaces = NULL; } LL_APPEND(clazz->_interfaces, interface); return TRUE; }
/** * 返回controller的ID */ int swFactoryProcess_controller(swFactory *factory, swEventCallback cb) { swFactoryProcess *object = factory->object; swServer *serv = factory->ptr; swController *controller = sw_malloc(sizeof(swController)); if (controller == NULL) { swWarn("malloc fail\n"); return SW_ERR; } controller->onEvent = cb; LL_APPEND(manager_controller_list, controller); controller->id = manager_controller_count; manager_controller_count ++; return controller->id; }
void tunnel_queue_delete(tunnel *t) { tunnel_list *tunnel_list_entry = NULL; if(tunnel_in_delete_queue(t)) { log_printf(L_DEBUG2, "Did not queue deleting tunnel #%d ptr %p - already queued\n", t->connid, t); return; } log_printf(L_DEBUG2, "Queued deleting tunnel #%d ptr %p\n", t->connid, t); tunnel_list_entry = calloc(sizeof(tunnel_list), 1); tunnel_list_entry->tun = t; LL_APPEND(tunnels_to_delete, tunnel_list_entry); }
void handle_shape(cpShape *shape, void *data) { cpBody *body = cpShapeGetBody(shape); // get the static body that comes with the space cpSpace *space = cpBodyGetSpace(body); cpBody *static_body = cpSpaceGetStaticBody(space); // ignore the static body if (static_body == body) return; element *el = (element *) malloc(sizeof(element)); el->body = body; element **l = (element **) data; LL_APPEND(*l, el); }