• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ endswith函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: specifier_prefix_and_instance

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


示例17: _Converter_ToWavRun

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


示例18: extract_pretty

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;
}
开发者ID:Keruspe,项目名称:systemd,代码行数:31,代码来源:machine-image.c


示例19: write_string_file_atomic

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


示例20: newParseTokenDescriptive

//
// 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;
}
开发者ID:KaSt,项目名称:nereamud,代码行数:28,代码来源:parse.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ endutent函数代码示例发布时间:2022-05-30
下一篇:
C++ ends_with函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap