struct zinfo_t* zinfo_create(void) { struct zinfo_t* zinfo = (struct zinfo_t*)calloc(1, sizeof(*zinfo)); zinfo->is_present = 0; ldns_rbtree_init(&zinfo->vs, cmp_version); ldns_rbtree_init(&zinfo->zone, cmp_domain); return zinfo; }
/* * Creates a new red black tree, intializes and returns a pointer to it. * * Return NULL on failure. * */ ldns_rbtree_t * ldns_rbtree_create (int (*cmpf)(const void *, const void *)) { ldns_rbtree_t *rbtree; /* Allocate memory for it */ rbtree = (ldns_rbtree_t *) malloc(sizeof(ldns_rbtree_t)); if (!rbtree) { return NULL; } /* Initialize it */ ldns_rbtree_init(rbtree, cmpf); return rbtree; }
static HRESULT MV_SHM_Init_Base(shm_dev_t *shm_dev, int mem_type) { HRESULT res = 0; int fd_cache; ldns_rbtree_init(&shm_dev->addr.m_phyaddr_root, shm_compare_v); ldns_rbtree_init(&shm_dev->addr.m_virtaddr_root, shm_compare_v); shm_dev->mem_type = mem_type; res = pthread_rwlock_init(&shm_dev->addr.m_rb_rwlock, NULL); if (res != 0) { MV_SHM_Print("MV_SHM_Init_Base pthread_rwlock_init" " shm_type[%d] fail:\n", mem_type); goto rwlock_err; } if (mem_type == SHM_CACHE) { fd_cache = open( SHM_DEVICE_PATH_CACHE, O_RDWR); if (fd_cache == -1) { MV_SHM_Print("MV_SHM_Init_Base open shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto open_err; } res = ioctl(fd_cache, SHM_DEVICE_CMD_GET_DEVINFO, &shm_dev->base); if (res == -1) { MV_SHM_Print("MV_SHM_Init_Base ioctl shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto ioctl_err; } } else if (mem_type == SHM_NONCACHE) { fd_cache = open( SHM_DEVICE_PATH_NONCACHE, O_RDWR); if (fd_cache == -1) { MV_SHM_Print("MV_SHM_Init_Base open shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto open_err; } res = ioctl(fd_cache, SHM_DEVICE_CMD_GET_DEVINFO, &shm_dev->base); if (res == -1) { MV_SHM_Print("MV_SHM_Init_Base ioctl shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto ioctl_err; } } else if (mem_type == SHM_SECURE_CACHE) { fd_cache = open( SHM_DEVICE_PATH_SECURE_CACHE, O_RDWR); if (fd_cache == -1) { MV_SHM_Print("MV_SHM_Init_Base open shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto open_err; } res = ioctl(fd_cache, SHM_DEVICE_CMD_GET_DEVINFO, &shm_dev->base); if (res == -1) { MV_SHM_Print("MV_SHM_Init_Base ioctl shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto ioctl_err; } } else if (mem_type == SHM_SECURE_NONCACHE) { fd_cache = open( SHM_DEVICE_PATH_SECURE_NONCACHE, O_RDWR); if (fd_cache == -1) { MV_SHM_Print("MV_SHM_Init_Base open shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto open_err; } res = ioctl(fd_cache, SHM_DEVICE_CMD_GET_DEVINFO, &shm_dev->base); if (res == -1) { MV_SHM_Print("MV_SHM_Init_Base ioctl shm_type[%d]" " fail: errno:%d %s\n",mem_type,errno, strerror(errno)); goto ioctl_err; } } else { return -1; } shm_dev->base.m_fd = fd_cache; return S_OK; ioctl_err: close(shm_dev->base.m_fd); shm_dev->base.m_fd = -1; open_err: pthread_rwlock_destroy(&shm_dev->addr.m_rb_rwlock); rwlock_err: return -1; }