void multirule::visit (t_filename &n) { if (state != S_TARGET) return; node_vec const &multifile = n.list; node_vec::const_iterator const lb = find_if (multifile.begin (), multifile.end (), lbrace); node_vec::const_iterator const rb = find_if (lb, multifile.end (), rbrace); if (lb == multifile.end ()) return; assert (rb != multifile.end ()); assert (distance (lb, rb) > 2); node_vec::const_iterator option = lb + 1; t_filename_ptr common_prereq; { node_vec target_file; for (node_vec::const_iterator copy = multifile.begin (); copy != lb; ++copy) target_file.push_back ((*copy)->clone ()); target_file.push_back ((*option)->clone ()); for (node_vec::const_iterator copy = rb + 1; copy != multifile.end (); ++copy) target_file.push_back ((*copy)->clone ()); common_prereq = make_filename (n.loc, target_file); } ++option; t_rule &origin = n.parent () // filenames ->parent () // rule ->as<t_rule> (); node_list *container = origin.parent (); // container of rule for (node_vec::const_iterator it = option; it != rb; ++it) { node_vec instance; for (node_vec::const_iterator copy = multifile.begin (); copy != lb; ++copy) instance.push_back ((*copy)->clone ()); instance.push_back ((*it)->clone ()); for (node_vec::const_iterator copy = rb + 1; copy != multifile.end (); ++copy) instance.push_back ((*copy)->clone ()); t_rule_ptr rule = new t_rule ( n.loc , (new t_filenames (n.loc))->add (make_filename (n.loc, instance)) , origin.prereq ()->clone ()->as<t_filenames> ().add (common_prereq->clone ()) , origin.code () ? (new t_rule_lines ())->add (new t_rule_line) : NULL); container->add (rule); } n.parent ()->replace (n, common_prereq); }
void run_chromatic_sampler(graphlab::core<mrf_graph_type, gibbs_update>& core, const std::string& chromatic_results_fn, const std::vector<double>& runtimes, const bool draw_images) { // Initialize scheduler core.set_scheduler_type("chromatic"); core.set_scope_type("null"); const size_t ncpus = core.get_options().get_ncpus(); // Use fixed update function gibbs_update ufun; core.schedule_all( ufun ); double total_runtime = 0; double actual_total_runtime = 0; foreach(const double experiment_runtime, runtimes) { total_runtime += experiment_runtime; // get the experiment id size_t experiment_id = file_line_count(chromatic_results_fn); std::cout << "Running chromatic sampler experiment " << experiment_id << " for " << experiment_runtime << " seconds." << std::endl; // set the termination time core.engine().set_timeout(experiment_runtime); // Run the engine graphlab::timer timer; timer.start(); core.start(); double actual_experiment_runtime = timer.current_time(); actual_total_runtime += actual_experiment_runtime; /// ================================================================== // Compute final statistics of the mode run_statistics stats(core.graph()); stats.print(); // Save the beliefs save_beliefs(core.graph(), make_filename("chromatic_blfs_", ".tsv", experiment_id)); // // Save the current assignments save_asg(core.graph(), make_filename("chromatic_asg_", ".asg", experiment_id)); // Save the experiment std::ofstream fout(chromatic_results_fn.c_str(), std::ios::app); fout.precision(16); fout << experiment_id << '\t' << total_runtime << '\t' << actual_total_runtime << '\t' << ncpus << '\t' << stats.nsamples << '\t' << stats.nchanges << '\t' << stats.loglik << '\t' << stats.min_samples << '\t' << stats.max_samples << std::endl; fout.close(); // Plot images if desired if(draw_images) draw_mrf(experiment_id, "chromatic", core.graph()); }
struct ast_frame *ast_read_image(char *filename, char *preflang, int format) { struct ast_imager *i; char buf[256]; char tmp[80]; char *e; struct ast_imager *found = NULL; int fd; int len=0; struct ast_frame *f = NULL; #if 0 /* We need to have some sort of read-only lock */ ast_mutex_lock(&listlock); #endif i = list; while(!found && i) { if (i->format & format) { char *stringp=NULL; strncpy(tmp, i->exts, sizeof(tmp)-1); stringp=tmp; e = strsep(&stringp, "|"); while(e) { make_filename(buf, sizeof(buf), filename, preflang, e); if ((len = file_exists(buf))) { found = i; break; } make_filename(buf, sizeof(buf), filename, NULL, e); if ((len = file_exists(buf))) { found = i; break; } e = strsep(&stringp, "|"); } } i = i->next; } if (found) { fd = open(buf, O_RDONLY); if (fd > -1) { if (!found->identify || found->identify(fd)) { /* Reset file pointer */ lseek(fd, 0, SEEK_SET); f = found->read_image(fd,len); } else ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name); close(fd); } else ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno)); } else ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); #if 0 ast_mutex_unlock(&listlock); #endif return f; }
avlog::ofstream_ptr avlog::create_file(const std::string& groupid) const { // 生成对应的路径. std::string save_path = make_path(groupid); // 如果不存在, 则创建目录. if (!fs::exists(fs::path(save_path))) { if (!fs::create_directory(fs::path(save_path))) { std::cerr << "create directory " << save_path.c_str() << " failed!" << std::endl; return ofstream_ptr(); } } // 按时间构造文件名. save_path = make_filename(save_path); // 创建文件. ofstream_ptr file_ptr(new std::ofstream(save_path.c_str(), fs::exists(save_path) ? std::ofstream::app : std::ofstream::out)); if (file_ptr->bad() || file_ptr->fail()) { std::cerr << "create file " << save_path.c_str() << " failed!" << std::endl; return ofstream_ptr(); } // 写入信息头. std::string info = "<head><meta http-equiv=\"Content-Type\" content=\"text/plain; charset=UTF-8\">\n"; file_ptr->write(info.c_str(), info.length()); return file_ptr; }
// 添加日志消息. bool add_log(const std::wstring &groupid, const std::string &msg) { // 在qq群列表中查找已有的项目, 如果没找到则创建一个新的. loglist::iterator finder = m_group_list.find(groupid); if (m_group_list.find(groupid) == m_group_list.end()) { // 创建文件. ofstream_ptr file_ptr = create_file(groupid); m_group_list[groupid] = file_ptr; finder = m_group_list.find(groupid); } // 如果没有找到日期对应的文件. if (!fs::exists(fs::path(make_filename(make_path(groupid))))) { // 创建文件. ofstream_ptr file_ptr = create_file(groupid); if (finder->second->is_open()) finder->second->close(); // 关闭原来的文件. // 重置为新的文件. finder->second = file_ptr; } // 得到文件指针. ofstream_ptr &file_ptr = finder->second; // 构造消息, 添加消息时间头. std::string data = "<p>" + current_time() + " " + msg + "</p>\n"; file_ptr->write(data.c_str(), data.length()); // 刷新写入缓冲, 实时写到文件. file_ptr->flush(); return true; }
/* Return some information about a module. */ static enum zi_module_info get_module_info(ZipImporter *self, PyObject *fullname) { PyObject *subname; PyObject *path, *fullpath, *item; struct st_zip_searchorder *zso; subname = get_subname(fullname); if (subname == NULL) return MI_ERROR; path = make_filename(self->prefix, subname); Py_DECREF(subname); if (path == NULL) return MI_ERROR; for (zso = zip_searchorder; *zso->suffix; zso++) { fullpath = PyUnicode_FromFormat("%U%s", path, zso->suffix); if (fullpath == NULL) { Py_DECREF(path); return MI_ERROR; } item = PyDict_GetItem(self->files, fullpath); Py_DECREF(fullpath); if (item != NULL) { Py_DECREF(path); if (zso->type & IS_PACKAGE) return MI_PACKAGE; else return MI_MODULE; } } Py_DECREF(path); return MI_NOT_FOUND; }
bool write_usim_data(const char *directory, int user_id, usim_data_t *usim_data){ int rc; char *filename = make_filename(directory, USIM_API_NVRAM_FILENAME, user_id); rc = usim_api_write(filename, usim_data); free(filename); return rc; }
static struct closure *compile_code(struct global_state *gstate, clist b) { struct code *cc; u8 nb_locals; fncode top; location topl; struct string *afilename; /* Code strings must be allocated before code (immutability restriction) */ afilename = make_filename(lexloc.filename); GCPRO1(afilename); erred = FALSE; env_reset(); topl.filename = NULL; topl.lineno = 0; top = new_fncode(gstate, topl, TRUE, 0); env_push(NULL, top); /* Environment must not be totally empty */ generate_clist(b, FALSE, top); ins0(OPmreturn, top); env_pop(&nb_locals); cc = generate_fncode(top, nb_locals, NULL, NULL, afilename, 0); delete_fncode(top); GCPOP(1); if (erred) return NULL; else return alloc_closure0(cc); }
pointer scm_load_ext(scheme *sc, pointer args) { pointer first_arg; pointer retval; char filename[MAXPATHLEN], init_fn[MAXPATHLEN+6]; char *name; HMODULE dll_handle; void (*module_init)(scheme *sc); if ((args != sc->NIL) && is_string((first_arg = pair_car(args)))) { name = string_value(first_arg); make_filename(name, filename); make_init_fn(name, init_fn); dll_handle = dl_attach(filename); if (dll_handle == 0) { retval = sc -> F; } else { module_init = (void(*)(scheme *))dl_proc(dll_handle, init_fn); if (module_init != 0) { (*module_init)(sc); retval = sc -> T; } else { retval = sc->F; } } } else { retval = sc -> F; } return(retval); }
int main (int argc, char **argv) { ARGPARSE_ARGS pargs; int cmd = 0; const char *keygrip = NULL; set_strusage (my_strusage); log_set_prefix ("gpg-preset-passphrase", 1); /* Make sure that our subsystems are ready. */ i18n_init (); init_common_subsystems (&argc, &argv); opt_homedir = default_homedir (); pargs.argc = &argc; pargs.argv = &argv; pargs.flags= 1; /* (do not remove the args) */ while (arg_parse (&pargs, opts) ) { switch (pargs.r_opt) { case oVerbose: opt.verbose++; break; case oHomedir: opt_homedir = pargs.r.ret_str; break; case oPreset: cmd = oPreset; break; case oForget: cmd = oForget; break; case oPassphrase: opt_passphrase = pargs.r.ret_str; break; default : pargs.err = 2; break; } } if (log_get_errorcount(0)) exit(2); if (argc == 1) keygrip = *argv; else usage (1); /* Tell simple-pwquery about the the standard socket name. */ { char *tmp = make_filename (opt_homedir, GPG_AGENT_SOCK_NAME, NULL); simple_pw_set_socket (tmp); xfree (tmp); } if (cmd == oPreset) preset_passphrase (keygrip); else if (cmd == oForget) forget_passphrase (keygrip); else log_error ("one of the options --preset or --forget must be given\n"); agent_exit (0); return 8; /*NOTREACHED*/ }
/* Return the user socket name used by DirMngr. If a user specific dirmngr installation is not supported, NULL is returned. */ const char * dirmngr_user_socket_name (void) { static char *name; if (!name) name = make_filename (gnupg_socketdir (), DIRMNGR_SOCK_NAME, NULL); return name; }
int readFiles( char *source, char *dest) { long h, err; struct _finddata_t data; char *filename, *prevname, *destname; unsigned int failID; int failpos; lwReader reader; Lwo2MeshWriter lwo2mesh; filename = (char *)malloc(3 * 512); if ( !filename ) return 0; prevname = filename + 512; destname = filename + 1024; err = h = _findfirst( source, &data ); if ( err == -1 ) { printf( "No files found: '%s'\n", source ); return 0; } while ( err != -1 ) { if (( data.attrib & _A_SUBDIR ) && data.name[ 0 ] != '.' ) { make_filespec( source, data.name, filename ); readFiles( filename, dest ); } if ( !( data.attrib & _A_SUBDIR )) { make_filename( source, data.name, filename ); if ( !strcmp( filename, prevname )) break; strcpy( prevname, filename ); failID = failpos = 0; lwObject *object = reader.readObjectFromFile( filename ); if ( object ) { if (flags[InfoOnly]) info(object, filename); else { make_destname( dest, data.name, destname ); lwo2mesh.writeLwo2Mesh(object, destname); } delete object; } } err = _findnext( h, &data ); } _findclose( h ); free (filename); return 1; }
void FileCtl::open // OPEN THE FILE ( char const* fname // - file name , char const* def // - default suffix , char const* mode ) // - open mode { make_filename( fname, def ); _file = fopen( _filename, mode ); if( 0 == _file ) { io_err( "cannot open" ); } }
/* Write an S-expression formatted key to our key storage. With FORCE passed as true an existing key with the given GRIP will get overwritten. */ int agent_write_private_key (const unsigned char *grip, const void *buffer, size_t length, int force) { char *fname; estream_t fp; char hexgrip[40+4+1]; bin2hex (grip, 20, hexgrip); strcpy (hexgrip+40, ".key"); fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL); /* FIXME: Write to a temp file first so that write failures during key updates won't lead to a key loss. */ if (!force && !access (fname, F_OK)) { log_error ("secret key file '%s' already exists\n", fname); xfree (fname); return gpg_error (GPG_ERR_EEXIST); } fp = es_fopen (fname, force? "wb,mode=-rw" : "wbx,mode=-rw"); if (!fp) { gpg_error_t tmperr = gpg_error_from_syserror (); log_error ("can't create '%s': %s\n", fname, gpg_strerror (tmperr)); xfree (fname); return tmperr; } if (es_fwrite (buffer, length, 1, fp) != 1) { gpg_error_t tmperr = gpg_error_from_syserror (); log_error ("error writing '%s': %s\n", fname, gpg_strerror (tmperr)); es_fclose (fp); gnupg_remove (fname); xfree (fname); return tmperr; } if (es_fclose (fp)) { gpg_error_t tmperr = gpg_error_from_syserror (); log_error ("error closing '%s': %s\n", fname, gpg_strerror (tmperr)); gnupg_remove (fname); xfree (fname); return tmperr; } bump_key_eventcounter (); xfree (fname); return 0; }
static PyObject * zipimporter_get_source(PyObject *obj, PyObject *args) { ZipImporter *self = (ZipImporter *)obj; PyObject *toc_entry; PyObject *fullname, *subname, *path, *fullpath; enum zi_module_info mi; if (!PyArg_ParseTuple(args, "U:zipimporter.get_source", &fullname)) return NULL; mi = get_module_info(self, fullname); if (mi == MI_ERROR) return NULL; if (mi == MI_NOT_FOUND) { PyErr_Format(ZipImportError, "can't find module %R", fullname); return NULL; } subname = get_subname(fullname); if (subname == NULL) return NULL; path = make_filename(self->prefix, subname); Py_DECREF(subname); if (path == NULL) return NULL; if (mi == MI_PACKAGE) fullpath = PyUnicode_FromFormat("%U%c__init__.py", path, SEP); else fullpath = PyUnicode_FromFormat("%U.py", path); Py_DECREF(path); if (fullpath == NULL) return NULL; toc_entry = PyDict_GetItem(self->files, fullpath); Py_DECREF(fullpath); if (toc_entry != NULL) { PyObject *res, *bytes; bytes = get_data(self->archive, toc_entry); if (bytes == NULL) return NULL; res = PyUnicode_FromStringAndSize(PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes)); Py_DECREF(bytes); return res; } /* we have the module, but no source */ Py_INCREF(Py_None); return Py_None; }
int main (int argc, char **argv) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; char *cert_1 = make_filename ("cert_dfn_pca01.der"); char *cert_2 = make_filename ("cert_dfn_pca15.der"); init_gpgme (GPGME_PROTOCOL_CMS); err = gpgme_new (&ctx); fail_if_err (err); gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); err = gpgme_data_new_from_file (&in, cert_1, 1); free (cert_1); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "DFA56FB5FC41E3A8921F77AD1622EEFD9152A5AD", 1, 1); gpgme_data_release (in); err = gpgme_data_new_from_file (&in, cert_2, 1); free (cert_2); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "2C8F3C356AB761CB3674835B792CDA52937F9285", 1, 2); gpgme_data_release (in); gpgme_release (ctx); return 0; }
/* Get the code object assoiciated with the module specified by 'fullname'. */ static PyObject * get_module_code(ZipImporter *self, char *fullname, int *p_ispackage, char **p_modpath) { PyObject *toc_entry; char *subname, path[MAXPATHLEN + 1]; int len; struct st_zip_searchorder *zso; subname = get_subname(fullname); len = make_filename(PyString_AsString(self->prefix), subname, path); if (len < 0) return NULL; for (zso = zip_searchorder; *zso->suffix; zso++) { PyObject *code = NULL; strcpy(path + len, zso->suffix); if (Py_VerboseFlag > 1) PySys_WriteStderr("# trying %s%c%s\n", PyString_AsString(self->archive), SEP, path); toc_entry = PyDict_GetItemString(self->files, path); if (toc_entry != NULL) { time_t mtime = 0; int ispackage = zso->type & IS_PACKAGE; int isbytecode = zso->type & IS_BYTECODE; if (isbytecode) mtime = get_mtime_of_source(self, path); if (p_ispackage != NULL) *p_ispackage = ispackage; code = get_code_from_data(self, ispackage, isbytecode, mtime, toc_entry); if (code == Py_None) { /* bad magic number or non-matching mtime in byte code, try next */ Py_DECREF(code); continue; } if (code != NULL && p_modpath != NULL) *p_modpath = PyString_AsString( PyTuple_GetItem(toc_entry, 0)); return code; } } PyErr_Format(ZipImportError, "can't find module '%.200s'", fullname); return NULL; }
/* This is actually not used anymore but we keep a list of already * set extensions modules here. * * Here is the ancient comment: * Register an extension module. The last registered module will * be loaded first. A name may have a list of classes * appended; e.g: * mymodule.so(1:17,3:20,3:109) * means that this module provides digest algorithm 17 and public key * algorithms 20 and 109. This is only a hint but if it is there the * loader may decide to only load a module which claims to have a * requested algorithm. * * mainpgm is the path to the program which wants to load a module * it is only used in some environments. */ void register_cipher_extension( const char *mainpgm, const char *fname ) { EXTLIST r, el, intex; char *p, *pe; if( *fname != DIRSEP_C ) { /* do tilde expansion etc */ char *tmp; if( strchr(fname, DIRSEP_C) ) tmp = make_filename(fname, NULL); else tmp = make_filename(GNUPG_LIBDIR, fname, NULL); el = xmalloc_clear( sizeof *el + strlen(tmp) ); strcpy(el->name, tmp ); xfree(tmp); } else { el = xmalloc_clear( sizeof *el + strlen(fname) ); strcpy(el->name, fname ); } /* check whether we have a class hint */ if( (p=strchr(el->name,'(')) && (pe=strchr(p+1,')')) && !pe[1] ) *p = *pe = 0; /* check that it is not already registered */ intex = NULL; for(r = extensions; r; r = r->next ) { if( !compare_filenames(r->name, el->name) ) { log_info("extension `%s' already registered\n", el->name ); xfree(el); return; } } /* and register */ el->next = extensions; extensions = el; }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; char *pubkey_1_asc = make_filename ("pubkey-1.asc"); char *seckey_1_asc = make_filename ("seckey-1.asc"); init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); err = gpgme_data_new_from_file (&in, pubkey_1_asc, 1); free (pubkey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 0); gpgme_data_release (in); err = gpgme_data_new_from_file (&in, seckey_1_asc, 1); free (seckey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); fail_if_err (err); result = gpgme_op_import_result (ctx); check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 1); gpgme_data_release (in); gpgme_release (ctx); return 0; }
/* Initialize the certificate cache if not yet done. */ void cert_cache_init (void) { char *dname; if (initialization_done) return; init_cache_lock (); acquire_cache_write_lock (); dname = make_filename (gnupg_sysconfdir (), "trusted-certs", NULL); load_certs_from_dir (dname, 1); xfree (dname); dname = make_filename (gnupg_sysconfdir (), "extra-certs", NULL); load_certs_from_dir (dname, 0); xfree (dname); initialization_done = 1; release_cache_lock (); cert_cache_print_stats (); }
static PyObject * zipimport_zipimporter_get_source_impl(ZipImporter *self, PyObject *fullname) /*[clinic end generated code: output=bc059301b0c33729 input=4e4b186f2e690716]*/ { PyObject *toc_entry; PyObject *subname, *path, *fullpath; enum zi_module_info mi; mi = get_module_info(self, fullname); if (mi == MI_ERROR) return NULL; if (mi == MI_NOT_FOUND) { PyErr_Format(ZipImportError, "can't find module %R", fullname); return NULL; } subname = get_subname(fullname); if (subname == NULL) return NULL; path = make_filename(self->prefix, subname); Py_DECREF(subname); if (path == NULL) return NULL; if (mi == MI_PACKAGE) fullpath = PyUnicode_FromFormat("%U%c__init__.py", path, SEP); else fullpath = PyUnicode_FromFormat("%U.py", path); Py_DECREF(path); if (fullpath == NULL) return NULL; toc_entry = PyDict_GetItem(self->files, fullpath); Py_DECREF(fullpath); if (toc_entry != NULL) { PyObject *res, *bytes; bytes = get_data(self->archive, toc_entry); if (bytes == NULL) return NULL; res = PyUnicode_FromStringAndSize(PyBytes_AS_STRING(bytes), PyBytes_GET_SIZE(bytes)); Py_DECREF(bytes); return res; } /* we have the module, but no source */ Py_RETURN_NONE; }
/* Return the secret key as an S-Exp after locating it using the grip. Returns NULL if key is not available. 0 = key is available */ int agent_key_available (const unsigned char *grip) { int result; char *fname; char hexgrip[40+4+1]; bin2hex (grip, 20, hexgrip); strcpy (hexgrip+40, ".key"); fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL); result = !access (fname, R_OK)? 0 : -1; xfree (fname); return result; }
void OutputPDB::push(data_sp data) { if (m_multiple_files) { m_pos_s.open(make_filename(m_posfn, m_step_counter).c_str()); } writeVectorPoint(m_pos_s, data->vectorPointByIndex(m_idx_positions)); // writeVectorPoint(m_vel_s, data->vectorPointByIndex(m_idx_velocities)); ++m_step_counter; if (m_multiple_files) { m_pos_s.close(); // m_vel_s.close(); } }
/* Remove the key identified by GRIP from the private key directory. */ static gpg_error_t remove_key_file (const unsigned char *grip) { gpg_error_t err = 0; char *fname; char hexgrip[40+4+1]; bin2hex (grip, 20, hexgrip); strcpy (hexgrip+40, ".key"); fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL); if (gnupg_remove (fname)) err = gpg_error_from_syserror (); xfree (fname); return err; }
static void saveFile(const char name[], const char config[], const char dir[], const SkImage* image) { SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); if (NULL == data.get()) { return; } SkString filename; make_filename(name, &filename); filename.appendf("_%s.png", config); SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); ::remove(path.c_str()); SkFILEWStream stream(path.c_str()); stream.write(data->data(), data->size()); }
int find_files(char *filespec) { long h, err; struct _finddata_t data; char *filename, *prevname; unsigned int failID; int failpos; filename = malloc(520); if(!filename) return 0; prevname = filename + 260; err = h = _findfirst(filespec, &data); if(err == -1) { printf("No files found: '%s'\n", filespec); return 0; } while(err != -1) { if((data.attrib & _A_SUBDIR) && data.name[0] != '.') { make_filespec(filespec, data.name, filename); find_files(filename); } if(!(data.attrib & _A_SUBDIR)) { make_filename(filespec, data.name, filename); if(!strcmp(filename, prevname)) break; strcpy(prevname, filename); printf("%s\n", filename); failID = failpos = 0; if(!testload(filename, &failID, &failpos)) { printf("%s\nLoading failed near byte %d\n\n", filename, failpos); } } err = _findnext(h, &data); } _findclose(h); free(filename); return 1; }
int main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in, out; gpgme_decrypt_result_t decrypt_result; gpgme_verify_result_t verify_result; char *cipher_2_asc = make_filename ("cipher-2.asc"); char *agent_info; init_gpgme (GPGME_PROTOCOL_OpenPGP); err = gpgme_new (&ctx); fail_if_err (err); agent_info = getenv("GPG_AGENT_INFO"); if (!(agent_info && strchr (agent_info, ':'))) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_2_asc, 1); free (cipher_2_asc); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); err = gpgme_op_decrypt_verify (ctx, in, out); fail_if_err (err); decrypt_result = gpgme_op_decrypt_result (ctx); if (decrypt_result->unsupported_algorithm) { fprintf (stderr, "%s:%i: unsupported algorithm: %s\n", __FILE__, __LINE__, decrypt_result->unsupported_algorithm); exit (1); } print_data (out); verify_result = gpgme_op_verify_result (ctx); check_verify_result (verify_result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", GPG_ERR_NO_ERROR); gpgme_data_release (in); gpgme_data_release (out); gpgme_release (ctx); return 0; }
/* Get and if needed create a string with the directory used to store openpgp revocations. */ char * get_openpgp_revocdir (const char *home) { char *fname; struct stat statbuf; fname = make_filename (home, GNUPG_OPENPGP_REVOC_DIR, NULL); if (stat (fname, &statbuf) && errno == ENOENT) { if (gnupg_mkdir (fname, "-rwx")) log_error (_("can't create directory '%s': %s\n"), fname, strerror (errno) ); else if (!opt.quiet) log_info (_("directory '%s' created\n"), fname); } return fname; }
void write(const char* str, std::streamsize size) { if (!m_auto_mode) { if (m_file.is_open()) m_file.write(str, size); return; } ofstream_ptr of; std::string fn = make_filename(m_log_path.string()); loglist::iterator iter = m_log_list.find(fn); if (iter == m_log_list.end()) { of.reset(new std::ofstream); of->open(fn.c_str(), std::ios_base::out | std::ios_base::app); if (AVROUTER_LOG_FILE_BUFFER != -1) of->rdbuf()->pubsetbuf(NULL, AVROUTER_LOG_FILE_BUFFER); m_log_list.insert(std::make_pair(fn, of)); if (m_log_list.size() > AVROUTER_LOG_FILE_NUM) { iter = m_log_list.begin(); fn = iter->first; ofstream_ptr f = iter->second; m_log_list.erase(iter); f->close(); f.reset(); boost::system::error_code ignore_ec; boost::filesystem::remove(fn, ignore_ec); if (ignore_ec) std::cout << "delete log failed: " << fn << ", error code: " << ignore_ec.message() << std::endl; } } else { of = iter->second; } if (of->is_open()) { (*of).write(str, size); (*of).flush(); } }
static int nrx_mib_init(struct nrx_px_softc *psc) { int status; char filename[128]; nrx_px_wlock(psc); make_filename(filename, sizeof(filename), "mib.bin"); status = nrx_px_read_file(psc, filename); if (status != 0) { printk("[nano] read mib file: %s failed\n", filename); } if (status == 0) { printk("loaded mib file: %s\n", filename); nrx_mib_release(psc, NULL, NULL); } nrx_px_wunlock(psc); return 0; }