当前位置: 首页>>代码示例>>C++>>正文


C++ endswith函数代码示例

本文整理汇总了C++中endswith函数的典型用法代码示例。如果您正苦于以下问题:C++ endswith函数的具体用法?C++ endswith怎么用?C++ endswith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了endswith函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:nmartensen,项目名称:systemd,代码行数:30,代码来源:test-tmpfiles.c

示例2: readOBJ

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;
}
开发者ID:dbc,项目名称:pyPolyCSG,代码行数:28,代码来源:triangulate.cpp

示例3: _Converter_ToFlacRun

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
}
开发者ID:rodrigocfd,项目名称:flac-lame-gui,代码行数:60,代码来源:Converter.c

示例4: should_trace

/* 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;
}
开发者ID:bingzhang,项目名称:pegasus,代码行数:36,代码来源:interpose.c

示例5: nftw_cb

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;
}
开发者ID:floppym,项目名称:systemd,代码行数:34,代码来源:locale-util.c

示例6: main

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;
}
开发者ID:ManojRollo,项目名称:carve,代码行数:58,代码来源:convert.cpp

示例7: decompress_stream

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;
}
开发者ID:jsynacek,项目名称:systemd-rhel,代码行数:9,代码来源:compress.c

示例8: get_directory_listing

    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);
                }
            }
        }
    }
开发者ID:RhobanProject,项目名称:MetabotStudio,代码行数:15,代码来源:Backend.cpp

示例9: main

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;
}
开发者ID:Werkov,项目名称:systemd,代码行数:48,代码来源:test-tmpfiles.c

示例10: runtests

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;
}
开发者ID:BackupTheBerlios,项目名称:ironout,代码行数:30,代码来源:runtests.c

示例11: has_virtio_rng_nftw_cb

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;
}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:30,代码来源:kmod-setup.c

示例12: action_lstat

/*
 * 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);
}
开发者ID:girving,项目名称:waitless,代码行数:37,代码来源:action.c

示例13: signature_block_write_map

/**
 * @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)));
}
开发者ID:JoshKaufman,项目名称:bootrom-tools,代码行数:46,代码来源:tftf_map.c

示例14: write_string_stream_ts

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);
}
开发者ID:heftig,项目名称:systemd,代码行数:25,代码来源:fileio.c

示例15: is_valid_filename

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;
}
开发者ID:kidanger,项目名称:Drystal,代码行数:16,代码来源:livecoding_linux.c


注:本文中的endswith函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。