int capn_init_mem(struct capn *c, const uint8_t *p, size_t sz, int packed) { struct capn_stream z; memset(&z, 0, sizeof(z)); z.next_in = p; z.avail_in = sz; return init_fp(c, NULL, &z, packed); }
int gen_cnode_module_load_init( gen_cnode_module_t* module ){ int rc = 0; gboolean is_sym; gen_cnode_init_fp init_fp; gen_cnode_state_new_fp state_new_fp; //Create global library state is_sym = g_module_symbol( module->lib, "GEN_CNODE_STATE_NEW", ((gpointer*)&state_new_fp) ); if( is_sym ){ module->state = state_new_fp(); } else { module->state = NULL; } //Look for GEN_CNODE_INIT is_sym = g_module_symbol( module->lib, "GEN_CNODE_INIT", ((gpointer*)&init_fp) ); if( is_sym && init_fp ){ //Insert init_fp into our hashtable (Not really needed) g_hash_table_insert( module->funcs, (void*)"GEN_CNODE_INIT", (void*)init_fp ); //Call the init fuction and record the result rc = init_fp( module->state ); } return rc; }
struct filp* random_fp_get(void) { struct filp *fp; fp = malloc(sizeof (*fp)); if (!fp) return NULL; init_fp(fp, &random_ops); dprintf("random fd -> %p\n", fp); return fp; }
/* * Call the remote procedure and get the file */ int get_file_rpc(char *host, char *f_name) { init_fp(f_name); init_clnt(host); size_t offset = 0; size_t written = 0; get_file_ret *ret; request req; memset(req.f_name, 0, MAX_FNAME_LEN); memcpy(req.f_name, f_name, (strlen(f_name) <= MAX_FNAME_LEN ? strlen(f_name): MAX_FNAME_LEN)); while (1) { req.offset = offset; ret = get_file_1(&req, clnt); // connection error if (ret == NULL) { clnt_perror(clnt, host); fclose(fp); exit(1); } // file name does not exist if (ret->errno != 0) { errno = ret->errno; perror(f_name); fclose(fp); exit(1); } // successfully got a file chunk if (ret->get_file_ret_u.f_chunk.offset == offset) { printf("Write a chunk\n"); written = fwrite(ret->get_file_ret_u.f_chunk.data, 1, ret->get_file_ret_u.f_chunk.bytes, fp); if (written < 0) { perror("Error in writing\n"); exit(1); } offset += ret->get_file_ret_u.f_chunk.bytes; } if (ret->get_file_ret_u.f_chunk.end) break; } fclose(fp); return 0; }
MPQCInit::MPQCInit(int &argc, char **argv, std::shared_ptr<GetLongOpt> opt, const madness::World &top_world, singleton_ctor_tag) : opt_(opt), argv_(argv), argc_(argc), input_format_(InputFormat::invalid) { if (opt_) opt_->enroll("max_memory", GetLongOpt::MandatoryValue, "the available memory"); atexit(mpqc::finalize); ExEnv::init(argc_, argv_); init_fp(); init_limits(); init_work_dir(); const auto libint_is_verbose = false; libint2::initialize(!libint_is_verbose); // turns off Libint diagnostics init_io(top_world); // init_resources(keyval); }
void module_load_callback(void * data) { char * file_name; char file_full_path[250]; void * mod; void * initializer; void (* init_fp) (void ** fp_list, char ***); void * fp_list[3]; char * t; struct mod_c_t * mod_c; char ** keywords; int k; file_name = (char *) data; #ifndef _WIN32 if (!strstr(file_name, ".so")) #else if (!strstr(file_name, ".dll")) #endif return; snprintf(file_full_path, 250, "%s/%s", mod_dir, file_name); #ifdef _WIN32 mod = LoadLibrary(file_full_path); #else mod = dlopen(file_full_path, RTLD_LAZY); #endif if (!mod) { fprintf(stderr, "%s could not be opened.\n", file_name); return; } mod_c = malloc(sizeof (struct mod_c_t)); mod_c->mod = mod; t = strchr(file_name, '.'); *t = '\0'; mod_c->mod_name = strdup(file_name); #ifdef _WIN32 initializer = GetProcAddress((HMODULE) mod, file_name); #else initializer = dlsym(mod, file_name); #endif if (!initializer) { fprintf(stderr, "entry point %s not found in %s.\n", file_name, file_full_path); return; } fp_list[0] = curl_perform; fp_list[1] = n_strip_tags; fp_list[2] = n_get_tag_value; #ifdef _WIN32 init_fp = (void (__cdecl *)(void **, char ***))GetProcAddress((HMODULE) mod, "init"); #else init_fp = dlsym(mod, "init"); #endif init_fp(fp_list, &keywords); mod_c->keywords = keywords; mod_c->func = (void (*)(struct irc_t *, char *)) initializer; for (k = 0; mod_array[k][mod_array_t_mod_name] != NULL; k++) {} mod_array[k][mod_array_t_mod_name] = strdup(file_name); mod_array[k][mod_array_t_mod_c] = mod_c; mod_array[k][mod_array_t_keywords] = keywords; fprintf(stderr, "Shared-lib Module loaded: [%s]", file_name); if (*keywords) { fprintf(stderr, " with keywords: "); while (*keywords != NULL) { fprintf(stderr, "\"%s\"", *keywords++); if (*keywords) fprintf(stderr, ", "); } fprintf(stderr, "."); } fprintf(stderr, "\n"); }
int capn_init_fp(struct capn *c, FILE *f, int packed) { struct capn_stream z; memset(&z, 0, sizeof(z)); return init_fp(c, f, &z, packed); }