int main(int argc, char** argv) { const char *p = argv[1] ?: "/tmp"; char *pattern = strjoina(p, "/systemd-test-XXXXXX"); _cleanup_close_ int fd, fd2; _cleanup_free_ char *cmd, *cmd2, *ans, *ans2; log_set_max_level(LOG_DEBUG); log_parse_environment(); fd = open_tmpfile(p, O_RDWR|O_CLOEXEC); assert_se(fd >= 0); assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0); (void) system(cmd); assert_se(readlink_malloc(cmd + 6, &ans) >= 0); log_debug("link1: %s", ans); assert_se(endswith(ans, " (deleted)")); fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC); assert_se(fd >= 0); assert_se(unlink(pattern) == 0); assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0); (void) system(cmd2); assert_se(readlink_malloc(cmd2 + 6, &ans2) >= 0); log_debug("link2: %s", ans2); assert_se(endswith(ans2, " (deleted)")); return 0; }
carve::poly::Polyhedron *readModel(const std::string &file) { carve::poly::Polyhedron *poly; if (file == "") { if (options.obj) { poly = readOBJ(std::cin); } else if (options.vtk) { poly = readVTK(std::cin); } else { poly = readPLY(std::cin); } } else if (endswith(file, ".ply")) { poly = readPLY(file); } else if (endswith(file, ".vtk")) { poly = readVTK(file); } else if (endswith(file, ".obj")) { poly = readOBJ(file); } if (poly == NULL) return NULL; std::cerr << "loaded polyhedron " << poly << " has " << poly->vertices.size() << " vertices " << poly->faces.size() << " faces " << poly->manifold_is_closed.size() << " manifolds (" << std::count(poly->manifold_is_closed.begin(), poly->manifold_is_closed.end(), true) << " closed)" << std::endl; return poly; }
static void _Converter_ToFlacRun(void *pArg) { Converter_ThreadData *ctd = (Converter_ThreadData*)pArg; wchar_t realSrc[MAX_PATH]; BOOL hasIntermediary; wchar_t *cmdLine = NULL; wchar_t flacpath[MAX_PATH]; if(!endswith(ctd->src, L".wav") && !endswith(ctd->src, L".flac")) { debugfmt(L"Invalid file extension: %s.", wcsrchr(ctd->src, L'.')); goto bye; } lstrcpy(realSrc, ctd->src); hasIntermediary = endswith(realSrc, L".flac"); // FLAC can be reencoded if(hasIntermediary) // FLAC is converted to WAV first { Converter_ThreadData *data = calloc(1, sizeof(Converter_ThreadData)); // will be consumed lstrcpy(data->src, realSrc); data->delSrc = FALSE; _Converter_ToWavRun(data); // not another thread, will block until returns { wchar_t newWav[MAX_PATH]; lstrcpy(newWav, ctd->src); lstrcpy(wcsrchr(newWav, L'.'), L".wav"); // path of newly created WAV lstrcpy(wcsrchr(realSrc, L'.'), L"_tmp.wav"); // remove .FLAC, append suffix and .WAV MoveFile(newWav, realSrc); // rename new WAV to have suffix } } // Proceed with FLAC command line tool. Converter_GetFlacPath(flacpath, ARRAYSIZE(flacpath)); cmdLine = allocfmt(L"\"%s\" -%s -V --no-seektable \"%s\"", flacpath, ctd->quality, realSrc); #ifdef _DEBUG // Debug summary of operations about to be performed. debugfmt(L"Run %s\n", cmdLine); if(hasIntermediary) debugfmt(L"Del %s\n", realSrc); else if(ctd->delSrc) debugfmt(L"Del %s\n", ctd->src); #endif exec(cmdLine); // execute tool free(cmdLine); if(hasIntermediary) { DeleteFile(realSrc); // delete intermediary WAV DeleteFile(ctd->src); // delete original FLAC lstrcpy(wcsrchr(realSrc, L'.'), L".flac"); // remove suffix, append .FLAC MoveFile(realSrc, ctd->src); // rename final file to same original name } else if(ctd->delSrc) DeleteFile(ctd->src); // delete source file bye: free(ctd); // consume }
/* Determine which paths should be traced */ static int should_trace(const char *path) { /* Trace all files */ if (getenv("KICKSTART_TRACE_ALL") != NULL) { return 1; } /* Trace files in the current working directory */ if (getenv("KICKSTART_TRACE_CWD") != NULL) { char *wd = getcwd(NULL, 0); int incwd = startswith(path, wd); free(wd); return incwd; } /* Skip files with known extensions that we don't care about */ if (endswith(path, ".py") || endswith(path, ".pyc") || endswith(path, ".jar")) { return 0; } /* Skip all the common system paths, which we don't care about */ if (startswith(path, "/lib") || startswith(path, "/usr") || startswith(path, "/dev") || startswith(path, "/etc") || startswith(path, "/proc")|| startswith(path, "/sys") || startswith(path, "/selinux")) { return 0; } return 1; }
static int nftw_cb( const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { char *p, *e; int r; if (tflag != FTW_F) return 0; if (!endswith(fpath, ".map") && !endswith(fpath, ".map.gz")) return 0; p = strdup(basename(fpath)); if (!p) return FTW_STOP; e = endswith(p, ".map"); if (e) *e = 0; e = endswith(p, ".map.gz"); if (e) *e = 0; r = set_consume(keymaps, p); if (r < 0 && r != -EEXIST) return r; return 0; }
int main(int argc, char **argv) { options.parse(argc, argv); carve::input::Input inputs; std::vector<carve::mesh::MeshSet<3> *> polys; std::vector<carve::line::PolylineSet *> lines; std::vector<carve::point::PointSet *> points; if (options.file == "") { readPLY(std::cin, inputs); } else { if (endswith(options.file, ".ply")) { readPLY(options.file, inputs); } else if (endswith(options.file, ".vtk")) { readVTK(options.file, inputs); } else if (endswith(options.file, ".obj")) { readOBJ(options.file, inputs); } } for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin(); i != inputs.input.end(); ++i) { carve::mesh::MeshSet<3> *p; carve::point::PointSet *ps; carve::line::PolylineSet *l; if ((p = carve::input::Input::create<carve::mesh::MeshSet<3> >(*i)) != NULL) { if (options.canonicalize) p->canonicalize(); if (options.obj) { writeOBJ(std::cout, p); } else if (options.vtk) { writeVTK(std::cout, p); } else { writePLY(std::cout, p, options.ascii); } delete p; } else if ((l = carve::input::Input::create<carve::line::PolylineSet>(*i)) != NULL) { if (options.obj) { writeOBJ(std::cout, l); } else if (options.vtk) { writeVTK(std::cout, l); } else { writePLY(std::cout, l, options.ascii); } delete l; } else if ((ps = carve::input::Input::create<carve::point::PointSet>(*i)) != NULL) { if (options.obj) { std::cerr << "Can't write a point set in .obj format" << std::endl; } else if (options.vtk) { std::cerr << "Can't write a point set in .vtk format" << std::endl; } else { writePLY(std::cout, ps, options.ascii); } delete ps; } } return 0; }
int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes) { if (endswith(filename, ".lz4")) return decompress_stream_lz4(fdf, fdt, max_bytes); else if (endswith(filename, ".xz")) return decompress_stream_xz(fdf, fdt, max_bytes); else return -EPROTONOSUPPORT; }
void Backend::loadComponents(std::string dir) { auto listing = get_directory_listing(dir); for (auto entry : listing) { std::string fullPath = dir+"/"+entry; if (is_directory(fullPath)) { loadComponents(fullPath); } else { if (endswith(fullPath, ".scad") && !endswith(fullPath, ".metabot.scad")) { parse(fullPath); } } } }
std::string format(const char* fmt, ...) { const int size = 512; struct deleter{ static void delarray(char* p) { delete[] p; } }; // to use delete[] shared_ptr<char> buffer(new char[size], deleter::delarray); // I'd prefer unique_ptr, but it's only available since c++11 va_list vl; va_start(vl,fmt); int nsize = vsnprintf(buffer.get(),size,fmt,vl); if(size<=nsize){//fail delete buffer and try again buffer.reset(new char[++nsize], deleter::delarray);//+1 for /0 nsize = vsnprintf(buffer.get(),nsize,fmt,vl); } va_end(vl); return buffer.get(); }
int main(int argc, char** argv) { _cleanup_free_ char *cmd = NULL, *cmd2 = NULL, *ans = NULL, *ans2 = NULL, *d = NULL, *tmp = NULL, *line = NULL; _cleanup_close_ int fd = -1, fd2 = -1; const char *p = argv[1] ?: "/tmp"; char *pattern; log_set_max_level(LOG_DEBUG); log_parse_environment(); pattern = strjoina(p, "/systemd-test-XXXXXX"); fd = open_tmpfile_unlinkable(p, O_RDWR|O_CLOEXEC); assert_se(fd >= 0); assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd) > 0); (void) system(cmd); assert_se(readlink_malloc(cmd + 6, &ans) >= 0); log_debug("link1: %s", ans); assert_se(endswith(ans, " (deleted)")); fd2 = mkostemp_safe(pattern); assert_se(fd >= 0); assert_se(unlink(pattern) == 0); assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd2) > 0); (void) system(cmd2); assert_se(readlink_malloc(cmd2 + 6, &ans2) >= 0); log_debug("link2: %s", ans2); assert_se(endswith(ans2, " (deleted)")); pattern = strjoina(p, "/tmpfiles-test"); assert_se(tempfn_random(pattern, NULL, &d) >= 0); fd = open_tmpfile_linkable(d, O_RDWR|O_CLOEXEC, &tmp); assert_se(fd >= 0); assert_se(write(fd, "foobar\n", 7) == 7); assert_se(touch(d) >= 0); assert_se(link_tmpfile(fd, tmp, d) == -EEXIST); assert_se(unlink(d) >= 0); assert_se(link_tmpfile(fd, tmp, d) >= 0); assert_se(read_one_line_file(d, &line) >= 0); assert_se(streq(line, "foobar")); assert_se(unlink(d) >= 0); return 0; }
int runtests(char *dirname, char *ironout) { struct dirent *ent; DIR *dir; int total = 0; int fails = 0; dir = opendir(dirname); if (!dir) { printf("failed: %s does not exist\n", dirname); return 1; } while ((ent = readdir(dir))) { char *name = ent->d_name; rmtempdir(".", 0); if (startswith(name, "test-") && !endswith(name, "~")) { char path[MAXPATHLEN]; sprintf(path, "%s/%s", dirname, name); total++; if (runtest(path, ironout)) { fails++; } } } closedir(dir); if (fails) printf("\n%d of %d failed\n", fails, total); else printf("%d succeeded\n", total); return fails; }
static int has_virtio_rng_nftw_cb( const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { _cleanup_free_ char *alias = NULL; int r; if ((FTW_D == tflag) && (ftwbuf->level > 2)) return FTW_SKIP_SUBTREE; if (FTW_F != tflag) return FTW_CONTINUE; if (!endswith(fpath, "/modalias")) return FTW_CONTINUE; r = read_one_line_file(fpath, &alias); if (r < 0) return FTW_SKIP_SIBLINGS; if (startswith(alias, "pci:v00001AF4d00001005")) return FTW_STOP; if (startswith(alias, "pci:v00001AF4d00001044")) return FTW_STOP; return FTW_SKIP_SIBLINGS; }
/* * We treat lstat the same as read except that only the existence or * nonexistence of the file is stored (represented as either the all * zero hash or the all one hash). */ int action_lstat(const char *path) { // Not all programs access files in a correct acyclic order. // In particular, GNU as stats its output .o file before writing // it. To fix this flaw, we lie to GNU as and pretend the file // is never there when statted. // TODO: This mechanism should be generalized and moved into a user // customizable file. struct process *process = process_info(); if ((process->flags & HACK_SKIP_O_STAT) && endswith(path, ".o")) { wlog("skipping stat(\"%s\")", path); return 0; } process = lock_master_process(); // Add a stat node to the subgraph struct hash path_hash; remember_hash_path(&path_hash, path); new_node(process, SG_STAT, &path_hash); // Check existence and update snapshot struct hash exists_hash; struct snapshot_entry *entry = snapshot_update(&exists_hash, path, &path_hash, 0); // No need to check for writers; if the file is being written, it must exist entry->stat = 1; shared_map_unlock(&snapshot); add_parent(process, &exists_hash); unlock_master_process(); return !hash_is_null(&exists_hash); }
/** * @brief Write the TFTF section table field offsets to the map file. * * Append the map for this TFTF to the map file. * * @param tftf_hdr The TFTF blob to write * @param prefix Optional prefix for each map entry * @param offset The starting offset of the TFTF (zero for a standalone * tftf map; non-zero for a TFTF in an FFFF). * @param map_file The open file object for the map file. * * @returns Returns nothing */ void signature_block_write_map(const tftf_section_descriptor * section, const char * prefix, size_t offset, FILE * map_file) { char prefix_buf[256] = {0}; prefix_buf[0] = '\0'; if (prefix) { /** * If we have a prefix, then issue a marker (without any added ".") * separator) for the start of the tftf. */ fprintf(map_file, "%s %08x\n", prefix, (uint32_t)offset); /* Ensure the prefix we use for the signature fields has a separator */ if (!endswith(prefix, ".")) { snprintf(prefix_buf, sizeof(prefix_buf), "%s.", prefix); } else { snprintf(prefix_buf, sizeof(prefix_buf), "%s", prefix); } } prefix = prefix_buf; /* Add the header fields */ fprintf(map_file, "%slength %08x\n", prefix, (uint32_t)(offset + offsetof(tftf_signature, length))); fprintf(map_file, "%stype %08x\n", prefix, (uint32_t)(offset + offsetof(tftf_signature, type))); fprintf(map_file, "%skey_name %08x\n", prefix, (uint32_t)(offset + offsetof(tftf_signature, key_name))); fprintf(map_file, "%skey_signature %08x\n", prefix, (uint32_t)(offset + offsetof(tftf_signature, signature))); }
int write_string_stream_ts( FILE *f, const char *line, WriteStringFileFlags flags, struct timespec *ts) { assert(f); assert(line); fputs(line, f); if (!(flags & WRITE_STRING_FILE_AVOID_NEWLINE) && !endswith(line, "\n")) fputc('\n', f); if (ts) { struct timespec twice[2] = {*ts, *ts}; if (futimens(fileno(f), twice) < 0) return -errno; } if (flags & WRITE_STRING_FILE_SYNC) return fflush_sync_and_check(f); else return fflush_and_check(f); }
static bool is_valid_filename(char *filename) { assert(filename); // Ignore backup files if (endswith(filename, ".swp") || endswith(filename, "~")) { return false; } // Ignore hidden files if (startswith(basename(filename), ".")) { return false; } return true; }
static int specifier_prefix_and_instance(char specifier, void *data, void *userdata, char **ret) { const UnitFileInstallInfo *i = userdata; _cleanup_free_ char *prefix = NULL; int r; assert(i); r = unit_name_to_prefix_and_instance(i->name, &prefix); if (r < 0) return r; if (endswith(prefix, "@") && i->default_instance) { char *ans; ans = strjoin(prefix, i->default_instance); if (!ans) return -ENOMEM; *ret = ans; } else { *ret = prefix; prefix = NULL; } return 0; }
static void _Converter_ToWavRun(void *pArg) { Converter_ThreadData *ctd = (Converter_ThreadData*)pArg; wchar_t flacpath[MAX_PATH]; wchar_t *cmdLine = NULL; if(!endswith(ctd->src, L".flac")) { debugfmt(L"Invalid file extension: %s.", wcsrchr(ctd->src, L'.')); goto bye; } Converter_GetFlacPath(flacpath, ARRAYSIZE(flacpath)); // retrieve FLAC tool path cmdLine = allocfmt(L"\"%s\" -d \"%s\"", flacpath, ctd->src); #ifdef _DEBUG // Debug summary of operations about to be performed. debugfmt(L"Run %s\n", cmdLine); if(ctd->delSrc) debugfmt(L"Del %s\n", ctd->src); #endif exec(cmdLine); // execute tool free(cmdLine); if(ctd->delSrc) DeleteFile(ctd->src); // delete source file bye: free(ctd); // consume }
static int extract_pretty(const char *path, const char *suffix, char **ret) { _cleanup_free_ char *name = NULL; const char *p; size_t n; assert(path); assert(ret); p = last_path_component(path); n = strcspn(p, "/"); name = strndup(p, n); if (!name) return -ENOMEM; if (suffix) { char *e; e = endswith(name, suffix); if (!e) return -EINVAL; *e = 0; } if (!image_name_is_valid(name)) return -EINVAL; *ret = TAKE_PTR(name); return 0; }
int write_string_file_atomic(const char *fn, const char *line) { _cleanup_fclose_ FILE *f = NULL; _cleanup_free_ char *p = NULL; int r; assert(fn); assert(line); r = fopen_temporary(fn, &f, &p); if (r < 0) return r; fchmod_umask(fileno(f), 0644); errno = 0; fputs(line, f); if (!endswith(line, "\n")) fputc('\n', f); fflush(f); if (ferror(f)) r = errno ? -errno : -EIO; else { if (rename(p, fn) < 0) r = -errno; else r = 0; } if (r < 0) unlink(p); return r; }
// // makes an exit token, and parses options. Returns NULL if there's bad options PARSE_TOKEN *parse_token_exit(const char *options) { // make it PARSE_TOKEN *token = newParseTokenDescriptive(PARSE_TOKEN_EXIT, options); // search for options while(*options != '\0') { if(!strncasecmp(options, ".multiple", 9)) { options = options + 9; token->all_ok = TRUE; } else if(!strncasecmp(options, ".invis_ok", 9)) { options = options + 9; REMOVE_BIT(token->scope, FIND_SCOPE_VISIBLE); } else if(*options == '(' && endswith(options, ")")) break; // didn't recognize the option else { deleteParseToken(token); token = NULL; break; } } return token; }
Matcher::cu_iterator Matcher::matchCompileUnit(StringRef fullname) { if (!initName(fullname)) return MyCUs.end(); initialized = true; /* TODO use binary search here */ cu_iterator I = cu_begin(), E = cu_end(); while(I != E) { std::string debugname; // Filename may already contains the path information if (I->getFilename().size() > 0 && I->getFilename()[0] == '/') debugname = I->getFilename(); else debugname = I->getDirectory().str() + "/" + I->getFilename().str(); if (endswith(debugname.c_str(), patchname)) break; I++; } if (I == E) errs() << "Warning: no matching file(" << patchname << ") was found in the CUs\n"; return I; }
static int parse_dbus_fragments(const char *path, const char *type) { _cleanup_closedir_ DIR *d = NULL; struct dirent *de; int r; assert(path); assert(type); d = opendir(path); if (!d) { if (errno == -ENOENT) return 0; return log_error_errno(errno, "Failed to enumerate D-Bus activated services: %m"); } r = 0; FOREACH_DIRENT(de, d, goto fail) { int q; if (!endswith(de->d_name, ".service")) continue; q = add_dbus(path, de->d_name, type); if (q < 0) r = q; } return r; fail: return log_error_errno(errno, "Failed to read D-Bus services directory: %m"); }
static enum VFSType _vdezType(struct VDirEntry* vde) { struct VDirEntryZip* vdez = (struct VDirEntryZip*) vde; if (endswith(vdez->name, "/")) { return VFS_DIRECTORY; } return VFS_FILE; }
int cg_get_user_path(char **path) { char *root, *p; assert(path); /* Figure out the place to put user cgroups below. We use the * same as PID 1 has but with the "/system" suffix replaced by * "/user" */ if (cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &root) < 0) p = strdup("/user"); else { if (endswith(root, "/system")) root[strlen(root) - 7] = 0; else if (streq(root, "/")) root[0] = 0; p = strappend(root, "/user"); free(root); } if (!p) return -ENOMEM; *path = p; return 0; }
static void load_plugin(const char *path) { const deo_plugin *tmp = NULL; const char *tmpx; if (inv.cnt >= MAX_PLUGINS) error(EXIT_FAILURE, 0, "Too many plugins"); assert(endswith(path, LT_MODULE_EXT)); tmpx = strrchr(path, '/'); if (tmpx == NULL) tmpx = path; else tmpx++; inv.rec[inv.cnt].name = strndup(tmpx, strlen(tmpx) - strlen(LT_MODULE_EXT)); inv.rec[inv.cnt].dll = dlopen(path, RTLD_NOW | RTLD_LOCAL); if (inv.rec[inv.cnt].dll == NULL) error(EXIT_FAILURE, 0, "Unable to open plugin: %s", dlerror()); tmp = dlsym(inv.rec[inv.cnt++].dll, "deo"); if (tmp == NULL) error(EXIT_FAILURE, 0, "Unable to read plugin: %s", dlerror()); inv.rec[inv.cnt - 1].plug = *tmp; }
static void _Converter_ToMp3Run(void *pArg) { Converter_ThreadData *ctd = (Converter_ThreadData*)pArg; wchar_t realSrc[MAX_PATH]; BOOL hasIntermediary; wchar_t *cmdLine = NULL; wchar_t lamepath[MAX_PATH]; if(!endswith(ctd->src, L".wav") && !endswith(ctd->src, L".flac")) { debugfmt(L"Invalid file extension: %s.", wcsrchr(ctd->src, L'.')); goto bye; } lstrcpy(realSrc, ctd->src); hasIntermediary = endswith(realSrc, L".flac"); if(hasIntermediary) // FLAC is converted to WAV first { Converter_ThreadData *data = calloc(1, sizeof(Converter_ThreadData)); // will be consumed lstrcpy(data->src, realSrc); data->delSrc = FALSE; _Converter_ToWavRun(data); // not another thread, will block until returns lstrcpy(wcsrchr(realSrc, L'.'), L".wav"); // src will be the newly-converted WAV } // Proceed with LAME command line tool. Converter_GetLamePath(lamepath, ARRAYSIZE(lamepath)); cmdLine = allocfmt(L"\"%s\" -%s%s --noreplaygain \"%s\" \"%s\"", lamepath, (ctd->isVbr ? L"V" : L"b"), ctd->quality, realSrc, realSrc); lstrcpy(wcsrchr(cmdLine, L'.'), L".mp3\""); // MP3 extension instead of WAV on destination filepath #ifdef _DEBUG // Debug summary of operations about to be performed. debugfmt(L"Run %s\n", cmdLine); if(hasIntermediary) debugfmt(L"Del %s\n", realSrc); if(ctd->delSrc) debugfmt(L"Del %s\n", ctd->src); #endif exec(cmdLine); // execute tool free(cmdLine); if(hasIntermediary) DeleteFile(realSrc); // delete intermediary WAV if(ctd->delSrc) DeleteFile(ctd->src); // delete source file bye: free(ctd); // consume }
int dkr_pull_new( DkrPull **ret, sd_event *event, const char *index_url, const char *image_root, DkrPullFinished on_finished, void *userdata) { _cleanup_(dkr_pull_unrefp) DkrPull *i = NULL; char *e; int r; assert(ret); assert(index_url); if (!http_url_is_valid(index_url)) return -EINVAL; i = new0(DkrPull, 1); if (!i) return -ENOMEM; i->on_finished = on_finished; i->userdata = userdata; i->image_root = strdup(image_root ?: "/var/lib/machines"); if (!i->image_root) return -ENOMEM; i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines"); i->index_url = strdup(index_url); if (!i->index_url) return -ENOMEM; e = endswith(i->index_url, "/"); if (e) *e = 0; if (event) i->event = sd_event_ref(event); else { r = sd_event_default(&i->event); if (r < 0) return r; } r = curl_glue_new(&i->glue, i->event); if (r < 0) return r; i->glue->on_finished = pull_job_curl_on_finished; i->glue->userdata = i; *ret = i; i = NULL; return 0; }
int test_endswith(struct libmnt_test *ts, int argc, char *argv[]) { char *optstr = argv[1]; char *pattern = argv[2]; printf("%s\n", endswith(optstr, pattern) ? "YES" : "NOT"); return 0; }
void read_matrix(idx *nv, idx *ne,idx **xadj, idx **adj, wt **ew, const char *filename){ std::string strfilename(filename); if (endswith(strfilename, ".mtx")){ read_mtx ( filename, nv, ne, xadj, adj, ew,false,false,false); } else if (endswith(strfilename, ".bin")){ read_graph_bin(nv, ne,xadj, adj, ew, filename); } else { throw std::runtime_error ("Reader is not available\n"); } }