int afscp_GetStatus(const struct afscp_venusfid *fid, struct AFSFetchStatus *s) { struct afscp_volume *v; struct afscp_server *server; struct AFSCallBack cb; struct AFSVolSync vs; struct AFSFid tf = fid->fid; struct afscp_statent *stored, key; void *cached; int code, i, j; time_t now; v = afscp_VolumeById(fid->cell, fid->fid.Volume); if (v == NULL) { return -1; } memset(&key, 0, sizeof(key)); memcpy(&key.me, fid, sizeof(*fid)); cached = tfind(&key, &v->statcache, statcompare); if (cached != NULL) { stored = *(struct afscp_statent **)cached; pthread_mutex_lock(&(stored->mtx)); memmove(s, &stored->status, sizeof(*s)); afs_dprintf(("Stat %u.%lu.%lu.%lu returning cached result\n", fid->cell->id, fid->fid.Volume, fid->fid.Vnode, fid->fid.Unique)); if (stored->nwaiters) pthread_cond_broadcast(&(stored->cv)); pthread_mutex_unlock(&(stored->mtx)); return 0; } code = ENOENT; for (i = 0; i < v->nservers; i++) { server = afscp_ServerByIndex(v->servers[i]); if (server && server->naddrs > 0) { for (j = 0; j < server->naddrs; j++) { time(&now); code = RXAFS_FetchStatus(server->conns[j], &tf, s, &cb, &vs); if (code == 0) { afscp_AddCallBack(server, &fid->fid, s, &cb, now); /* calls _StatStuff */ afs_dprintf(("Stat %d.%lu.%lu.%lu" " ok: type %ld size %ld\n", fid->cell->id, afs_printable_uint32_lu(fid->fid.Volume), afs_printable_uint32_lu(fid->fid.Vnode), afs_printable_uint32_lu(fid->fid.Unique), afs_printable_int32_ld(s->FileType), afs_printable_int32_ld(s->Length))); return 0; } } } } afscp_errno = code; return -1; }
char* sp_rtrace_tracker_query_symbol(sp_rtrace_tracker_t* tracker, const char* name) { char* demangled_name = (char*)cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS); if (!tfind(demangled_name ? demangled_name : name, &tracker->symbols, (int (*)(const void *, const void *))_strcmpp)) { return NULL; } return demangled_name ? demangled_name : strdup(name); }
DfsFile *findFile(char *path) { if (!path[0] || !strcmp(path, "/")) return root; DfsFile **fh = tfind(path, &pathRoot, file_compare); return fh ? *fh : NULL; }
/* find existing service queue */ struct tpservice *fnd_service(char *svcname) { assert(svcname); debug(1, "fnd_service(%.*s)", XATMI_SERVICE_NAME_LENGTH, svcname); struct tpservice **svc = tfind(svcname, &services, cmp_service); debug(2, "fnd_service(%.*s) -> 0x%x", XATMI_SERVICE_NAME_LENGTH, svcname, svc ? *svc : 0); return svc ? *svc : 0; }
int __pmUnpinPDUBuf(void *handle) { bufctl_t *pcp, pcp_search; void *bcp; assert(((__psint_t)handle % sizeof(int)) == 0); PM_INIT_LOCKS(); PM_LOCK(__pmLock_libpcp); /* * Initialize a dummy bufctl_t to use only as search key; * only its bc_buf & bc_size fields need to be set, as that's * all that bufctl_t_compare will look at. */ pcp_search.bc_buf = handle; pcp_search.bc_size = 1; bcp = tfind(&pcp_search, &buf_tree, &bufctl_t_compare); /* * NB: don't release the lock until final disposition of this object; * we don't want to play TOCTOU. */ if (likely(bcp != NULL)) { pcp = *(bufctl_t **)bcp; } else { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_PDUBUF) { fprintf(stderr, "__pmUnpinPDUBuf(" PRINTF_P_PFX "%p) -> fails\n", handle); pdubufdump(); } #endif PM_UNLOCK(__pmLock_libpcp); return 0; } #ifdef PCP_DEBUG if (unlikely(pmDebug & DBG_TRACE_PDUBUF)) fprintf(stderr, "__pmUnpinPDUBuf(" PRINTF_P_PFX "%p) -> pdubuf=" PRINTF_P_PFX "%p, pincnt=%d\n", handle, pcp->bc_buf, pcp->bc_pincnt - 1); #endif assert((&pcp->bc_buf[0] <= (char*)handle) && ((char*)handle < &pcp->bc_buf[pcp->bc_size])); if (likely(--pcp->bc_pincnt == 0)) { tdelete(pcp, &buf_tree, &bufctl_t_compare); PM_UNLOCK(__pmLock_libpcp); free(pcp); } else { PM_UNLOCK(__pmLock_libpcp); } return 1; }
int cps_contains( pid_t pid) { return root == NULL ? 0 : tfind(&pid, &root, compare) != NULL; }
// return true only if the device and inode information has not been added before static inline int find_object(struct stat *st) { struct dev_and_inode obj; void *res; obj.dev = st->st_dev; obj.ino = st->st_ino; res = (void *) tfind(&obj, &seen_inodes, compare_func); return res != (void *) NULL; }
node_t* dict_find(struct dict* d, uint64_t k){ dictPair* p = malloc(sizeof(dictPair)); p->key = k; dictPair* r = (dictPair*) tfind(p, &d->root, compar); if (r == NULL) return NULL; else return (*(dictPair **)r)->value; }
static variable_t *Lookup( vlc_object_t *obj, const char *psz_name ) { vlc_object_internals_t *priv = vlc_internals( obj ); variable_t **pp_var; vlc_mutex_lock(&priv->var_lock); pp_var = tfind( &psz_name, &priv->var_root, varcmp ); return (pp_var != NULL) ? *pp_var : NULL; }
HTokenType h_get_token_type_number(const char* name) { Entry e; e.name = name; Entry **ret = (Entry**)tfind(&e, &tt_registry, compare_entries); if (ret == NULL) return 0; else return (*ret)->value; }
static cometd_client_subscription* cometd_find_subscription(cometd_client_t * client, const char * channel) { if (!client || !channel) return 0; cometd_client_impl* cli = (cometd_client_impl*)client; cometd_client_subscription test; test.channel = channel; void ** found = tfind(&test, &cli->subscriptions, &compare_subs); return found ? *(cometd_client_subscription**)found : 0; }
/** Internal use only. */ static dictionary_entry_t *dictionary_tfind(dictionary_t *d, const char *key) { dictionary_entry_t tentry = {key, NULL}; void *tresult = tfind((void *)&tentry, &d->root, compare); if (tresult == NULL) return NULL; else return *((dictionary_entry_t **)tresult); }
metafield_t* metafield_search(const char * name) { metafield_t **metafield, search; if (!name) return NULL; search.name = name; metafield = tfind(&search, &metafields_root, (ELEMENT_COMPARE) metafield_compare); return metafield ? *metafield : NULL; }
datastore_entry_t *dictionary_tfind(datastore_t *ds, const char *key) { datastore_entry_t tentry = {key, NULL, 0}; void *tresult = tfind((void *)&tentry, &ds->root, compare); if (tresult == NULL) return NULL; else return *((datastore_entry_t **)tresult); }
algorithm_t * algorithm_search(const char * name) { algorithm_t ** algorithm, search; if (!name) return NULL; search.name = name; algorithm = tfind(&search, &algorithms_root, (ELEMENT_COMPARE) algorithm_compare); return algorithm ? *algorithm : NULL; }
// Returns 1 if the proper function name of cur_entry is found in // prog_pts_tree and 0 otherwise. Always look for cur_entry->fjalar_name. Bool prog_pts_tree_entry_found(FunctionEntry* cur_entry) { if (tfind((void*)cur_entry->fjalar_name, (void**)&prog_pts_tree, compareStrings)) { return 1; } else { return 0; } }
/* Look in caches, 0=found and valid, 1=not or uncachable in the first place */ static enum cache_task_return Cache_Get_Common_Dir(struct dirblob *db, time_t * duration, const struct tree_node *tn) { enum cache_task_return ctr_ret; time_t now = NOW_TIME; size_t size; struct tree_opaque *opaque; LEVEL_DEBUG("Get from cache sn " SNformat " pointer=%p extension=%d", SNvar(tn->tk.sn), tn->tk.p, tn->tk.extension); CACHE_RLOCK; opaque = tfind(tn, &cache.temporary_tree_new, tree_compare) ; if ( opaque == NULL ) { // not found in new tree if ( cache.time_retired + duration[0] > now ) { // old tree could be new enough opaque = tfind(tn, &cache.temporary_tree_old, tree_compare) ; } } if ( opaque != NULL ) { duration[0] = opaque->key->expires - now ; if (duration[0] >= 0) { LEVEL_DEBUG("Dir found in cache"); size = opaque->key->dsize; if (DirblobRecreate(TREE_DATA(opaque->key), size, db) == 0) { //printf("Cache: snlist=%p, devices=%lu, size=%lu\n",*snlist,devices[0],size) ; ctr_ret = ctr_ok; } else { ctr_ret = ctr_size_mismatch; } } else { //char b[26]; //printf("GOT DEAD now:%s",ctime_r(&now,b)) ; //printf(" then:%s",ctime_r(&opaque->key->expires,b)) ; LEVEL_DEBUG("Dir expired in cache"); ctr_ret = ctr_expired; } } else { LEVEL_DEBUG("Dir not found in cache"); ctr_ret = ctr_not_found; } CACHE_RUNLOCK; return ctr_ret; }
/** * Removes a source (if present) by index. */ static void RemoveSource (services_discovery_t *sd, uint32_t idx) { services_discovery_sys_t *sys = sd->p_sys; struct device **dp = tfind (&idx, &sys->root, cmpsrc); if (dp == NULL) return; struct device *d = *dp; tdelete (d, &sys->root, cmpsrc); DestroySource (d); }
/* * Returns the unit-and-identifier whose ASCII identifier corresponding to a * unit. * * Arguments: * map The unit-to-identifier map. * unit The unit to be used as the key in the search. * Returns: * NULL The map doesn't contain an entry corresponding to "unit" whose * identifier is in ASCII. * else Pointer to the entry corresponding to "unit" whose identifier is * in ASCII. */ static UnitAndId* utimFindAsciiByUnit( UnitToIdMap* const map, const ut_unit* const unit) { UnitAndId targetEntry; UnitAndId** treeEntry; targetEntry.unit = (ut_unit*)unit; treeEntry = tfind(&targetEntry, &map->ascii, compareUnits); return treeEntry == NULL ? NULL : *treeEntry; }
/* look in persistent alias->sn tree */ static void Cache_Del_Alias_Persistent( struct alias_tree_node * atn) { struct tree_opaque *opaque; struct alias_tree_node *atn_found = NULL; PERSISTENT_RLOCK; opaque = tfind(atn, &cache.persistent_alias_tree, alias_tree_compare) ; if ( opaque != NULL ) { atn_found = (struct alias_tree_node *) (opaque->key); } PERSISTENT_RUNLOCK; owfree(atn_found) ; }
/** * Removes a udev device (if present). */ static void RemoveDevice (services_discovery_t *sd, struct udev_device *dev) { services_discovery_sys_t *p_sys = sd->p_sys; dev_t num = udev_device_get_devnum (dev); struct device **dp = tfind (&(dev_t){ num }, &p_sys->root, cmpdev); if (dp == NULL) return; struct device *d = *dp; tdelete (d, &p_sys->root, cmpdev); DestroyDevice (d); }
xtreePos_t xtreeFind(void *treehandle, char *key) { xtree_t *tree = treehandle; treerec_t **result, rec; if (!tree) return NULL; rec.key = key; rec.userdata = NULL; rec.compare = tree->compare; result = tfind(&rec, &tree->root, xtree_i_compare); return (result ? *result : NULL); }
char * grdx_scgi_get_header(const char * __name, const scgi_t * __scgi) { struct header_s _header_key; void * _tfind_ret; _header_key.name = __name; _header_key.value = NULL; _tfind_ret = tfind(&_header_key, &(__scgi->tree_header), compare_header); if(_tfind_ret == NULL) { return NULL; } return (*((struct header_s**)_tfind_ret))->value; }
/* * Stage 1: Input * * filename should either be `-' for `stdin' else an accessible * disk file. */ uint32_t inhx32_tree_input(void **root, const char *filename, uint32_t *count) { FILE *fp = stdin; uint32_t nbytes = 0; void *entry; pic_data *data; *count = 0; /* Open file or stdin */ if (strcmp(filename, "-") && (fp = fopen(filename, "rb")) == NULL) { printf("%s: error: fopen failed [%s] [%s]\n", __func__, filename, strerror(errno)); return 0; /* Empty */ } /* While not EOF, process data */ while ((data = inhx32_get(fp)) != NULL) { /* Detect duplicate data in tree */ entry = tfind((void *)data, root, inhx32_tree_compare); if (entry != NULL) { printf("%s: fatal error: duplicate address [%08X]\n", __func__, data->address); io_exit(EX_SOFTWARE); /* Panic */ } /* Add new data to tree */ entry = tsearch((void *)data, root, inhx32_tree_compare); if (entry == NULL) { printf("%s: fatal error: tsearch failed\n", __func__); io_exit(EX_OSERR); /* Panic */ } /* Update counters */ (*count)++; nbytes += data->nbytes; } /* Close file or stdin */ if (strcmp(filename, "-")) fclose(fp); /* Information */ if (nbytes == 0) printf("%s: information: no valid input data\n", __func__); /* Return number of bytes */ return nbytes; }
/** * Ensures that a PID doesn't exist. * * @param pid [in] The PID to not exist. */ void cps_remove( pid_t pid) { void *node = tfind(&pid, &root, compare); if (node != NULL) { pid_t *elt = *(pid_t**)node; (void)tdelete(&pid, &root, compare); free(elt); count--; } }
int delString(struct StringTable *st, const char *key) { struct StringTableNode *result; char *toFree; result = (struct StringTableNode *) tfind(&key, &st->stringTableNodeTab, compare); if (result == NULL) return ERR_NOSTRING; result = * (struct StringTableNode **) result; toFree = result->key; tdelete(result, &st->stringTableNodeTab, compare); free(toFree); free(result); return 0; }
int iol_del_event(int fd) { struct ioloop_event_desc tmpdesc = {.iol_fd = fd}; struct epoll_event tmpev; struct epoll_event **ev = NULL; tmpev.data.ptr = &tmpdesc; ev = tfind(&tmpev, &_iol_manager.root, _iol_cmp); if(ev){ return _iol_del_internal_event(fd, *ev); } return -1; }
static INDEX_OR_ERROR Cache_Get_Alias_Common( struct alias_tree_node * atn) { INDEX_OR_ERROR bus = INDEX_BAD; time_t now = NOW_TIME; struct tree_opaque *opaque; CACHE_RLOCK; opaque = tfind(atn, &cache.temporary_alias_tree_new, alias_tree_compare) ; if ( opaque == NULL ) { // try old tree opaque = tfind(atn, &cache.temporary_alias_tree_old, alias_tree_compare) ; } if ( opaque != NULL ) { // test expiration if ( ((struct alias_tree_node *)(opaque->key))->expires > now) { bus = ((struct alias_tree_node *)(opaque->key))->bus ; LEVEL_DEBUG("Found %s on bus.%d",ALIAS_TREE_DATA(atn),bus) ; } } CACHE_RUNLOCK; LEVEL_DEBUG("Finding %s unsuccessful",ALIAS_TREE_DATA(atn)) ; owfree(atn) ; return bus; }
static struct perf_apm *find_or_add_perf(const char *name) { struct perf_apm perf, *ret; perf.name = strdup(name); ret = tfind(&perf, &root, compare); free(perf.name); if (!ret) { ret = new_perf(name); } else { ret = *((void **)ret); } return ret; }
static GOOD_OR_BAD Cache_Del_Common(const struct tree_node *tn) { struct tree_opaque *opaque; time_t now = NOW_TIME; GOOD_OR_BAD ret = gbBAD; LEVEL_DEBUG("Delete from cache sn " SNformat " in=%p index=%d", SNvar(tn->tk.sn), tn->tk.p, tn->tk.extension); CACHE_WLOCK; opaque = tfind(tn, &cache.temporary_tree_new, tree_compare) ; if ( opaque == NULL ) { // not in new tree if ( cache.time_to_kill > now ) { // old tree still alive opaque = tfind(tn, &cache.temporary_tree_old, tree_compare) ; } } if ( opaque != NULL ) { opaque->key->expires = now - 1; ret = gbGOOD; } CACHE_WUNLOCK; return ret; }