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


C++ x_strdup函数代码示例

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


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

示例1: cct_check_str_eq

bool
cct_check_str_eq(const char *file, int line, const char *expression,
                 const char *expected, const char *actual, bool free1,
                 bool free2)
{
	bool result;

	if (expected && actual && str_eq(actual, expected)) {
		cct_check_passed(file, line, expression);
		result = true;
	} else {
		char *exp_str = expected ? format("\"%s\"", expected) : x_strdup("(null)");
		char *act_str = actual ? format("\"%s\"", actual) : x_strdup("(null)");
		cct_check_failed(file, line, expression, exp_str, act_str);
		free(exp_str);
		free(act_str);
		result = false;
	}

	if (free1) {
		free((char *)expected);
	}
	if (free2) {
		free((char *)actual);
	}
	return result;
}
开发者ID:TheOneRing,项目名称:ccache,代码行数:27,代码来源:framework.c

示例2: cct_check_args_eq

bool
cct_check_args_eq(const char *file, int line, const char *expression,
                  struct args *expected, struct args *actual,
                  bool free1, bool free2)
{
	bool result;

	if (expected && actual && args_equal(actual, expected)) {
		cct_check_passed(file, line, expression);
		result = true;
	} else {
		char *exp_str = expected ? args_to_string(expected) : x_strdup("(null)");
		char *act_str = actual ? args_to_string(actual) : x_strdup("(null)");
		cct_check_failed(file, line, expression, exp_str, act_str);
		free(exp_str);
		free(act_str);
		result = false;
	}

	if (free1) {
		args_free(expected);
	}
	if (free2) {
		args_free(actual);
	}
	return result;
}
开发者ID:TheOneRing,项目名称:ccache,代码行数:27,代码来源:framework.c

示例3: fdstream_resource

struct resource *
fdstream_resource (const char * path, int fd, const char * content_type)
{
	struct fdstream * st;

	if ((st = calloc (1, sizeof(*st))) == NULL)
		return NULL;

	st->path = x_strdup (path);
	if (st->path == NULL) {
		free (st);
		return NULL;
	}

	st->content_type = x_strdup (content_type);
	if (st->content_type == NULL) {
		free (st);
		free ((char *)st->path);
		return NULL;
	}

	st->stream = stream_open (fd);
	if (st->stream == NULL) {
		free (st);
		free ((char *)st->path);
		free ((char *)st->content_type);
		return NULL;
	}

	return resource_new (fdstream_check, fdstream_head, fdstream_body, fdstream_delete, st);
}
开发者ID:achellies,项目名称:sighttpd,代码行数:31,代码来源:fdstream.c

示例4: conf_item_receiver

static void
conf_item_receiver(const char *descr, const char *origin, void *context)
{
	(void)context;
	received_conf_items[n_received_conf_items].descr = x_strdup(descr);
	received_conf_items[n_received_conf_items].origin = x_strdup(origin);
	++n_received_conf_items;
}
开发者ID:ccache,项目名称:ccache,代码行数:8,代码来源:test_conf.c

示例5: verify_object

static int
verify_object(struct conf *conf, struct manifest *mf, struct object *obj,
              struct hashtable *stated_files, struct hashtable *hashed_files)
{
	for (uint32_t i = 0; i < obj->n_file_info_indexes; i++) {
		struct file_info *fi = &mf->file_infos[obj->file_info_indexes[i]];
		char *path = mf->files[fi->index];
		struct file_stats *st = hashtable_search(stated_files, path);
		if (!st) {
			struct stat file_stat;
			if (x_stat(path, &file_stat) != 0) {
				return 0;
			}
			st = x_malloc(sizeof(*st));
			st->size = file_stat.st_size;
			st->mtime = file_stat.st_mtime;
			st->ctime = file_stat.st_ctime;
			hashtable_insert(stated_files, x_strdup(path), st);
		}

		if (fi->size != st->size) {
			return 0;
		}

		if (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES) {
			if (fi->mtime == st->mtime && fi->ctime == st->ctime) {
				cc_log("mtime/ctime hit for %s", path);
				continue;
			} else {
				cc_log("mtime/ctime miss for %s", path);
			}
		}

		struct file_hash *actual = hashtable_search(hashed_files, path);
		if (!actual) {
			struct mdfour hash;
			hash_start(&hash);
			int result = hash_source_code_file(conf, &hash, path);
			if (result & HASH_SOURCE_CODE_ERROR) {
				cc_log("Failed hashing %s", path);
				return 0;
			}
			if (result & HASH_SOURCE_CODE_FOUND_TIME) {
				return 0;
			}
			actual = x_malloc(sizeof(*actual));
			hash_result_as_bytes(&hash, actual->hash);
			actual->size = hash.totalN;
			hashtable_insert(hashed_files, x_strdup(path), actual);
		}
		if (memcmp(fi->hash, actual->hash, mf->hash_size) != 0
		    || fi->size != actual->size) {
			return 0;
		}
	}

	return 1;
}
开发者ID:ezyang,项目名称:ccache,代码行数:58,代码来源:manifest.c

示例6: find_executable_in_path

static char *
find_executable_in_path(const char *name, const char *exclude_name, char *path)
{
	path = x_strdup(path);

	// Search the path looking for the first compiler of the right name that
	// isn't us.
	char *saveptr = NULL;
	for (char *tok = strtok_r(path, PATH_DELIM, &saveptr);
	     tok;
	     tok = strtok_r(NULL, PATH_DELIM, &saveptr)) {
#ifdef _WIN32
		char namebuf[MAX_PATH];
		int ret = SearchPath(tok, name, NULL, sizeof(namebuf), namebuf, NULL);
		if (!ret) {
			char *exename = format("%s.exe", name);
			ret = SearchPath(tok, exename, NULL, sizeof(namebuf), namebuf, NULL);
			free(exename);
		}
		(void) exclude_name;
		if (ret) {
			free(path);
			return x_strdup(namebuf);
		}
#else
		struct stat st1, st2;
		char *fname = format("%s/%s", tok, name);
		// Look for a normal executable file.
		if (access(fname, X_OK) == 0 &&
		    lstat(fname, &st1) == 0 &&
		    stat(fname, &st2) == 0 &&
		    S_ISREG(st2.st_mode)) {
			if (S_ISLNK(st1.st_mode)) {
				char *buf = x_realpath(fname);
				if (buf) {
					char *p = basename(buf);
					if (str_eq(p, exclude_name)) {
						// It's a link to "ccache"!
						free(p);
						free(buf);
						continue;
					}
					free(buf);
					free(p);
				}
			}

			// Found it!
			free(path);
			return fname;
		}
		free(fname);
#endif
	}

	free(path);
	return NULL;
}
开发者ID:orgads,项目名称:ccache,代码行数:58,代码来源:execute.c

示例7: alloc_pw

static void
alloc_pw(struct passwd *target, struct passwd *source)
{
    *target = *source;
    /* we care only about these strings */
    target->pw_dir = x_strdup(source->pw_dir);
    target->pw_name = x_strdup(source->pw_name);
    target->pw_shell = x_strdup(source->pw_shell);
}
开发者ID:alepharchives,项目名称:bitrig-xenocara,代码行数:9,代码来源:xstrings.c

示例8: strrchr

/* return the base name of a file - caller frees */
char *str_basename(const char *s)
{
	char *p = strrchr(s, '/');
	if (p) {
		return x_strdup(p+1);
	} 

	return x_strdup(s);
}
开发者ID:Voskrese,项目名称:mipsonqemu,代码行数:10,代码来源:util.c

示例9: _pam_parse

static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
		      int *hashcount)
{
    int ctrl=0;

    if (flags & PAM_SILENT) {
	ctrl |= PAM_MAIL_SILENT;
    }

    *hashcount = 0;

    /* step through arguments */
    for (; argc-- > 0; ++argv) {

	/* generic options */

	if (!strcmp(*argv,"debug"))
	    ctrl |= PAM_DEBUG_ARG;
	else if (!strcmp(*argv,"quiet"))
	    ctrl |= PAM_QUIET_MAIL;
	else if (!strcmp(*argv,"standard"))
	    ctrl |= PAM_STANDARD_MAIL | PAM_EMPTY_TOO;
	else if (!strncmp(*argv,"dir=",4)) {
	    *maildir = x_strdup(4+*argv);
	    if (*maildir != NULL) {
		D(("new mail directory: %s", *maildir));
		ctrl |= PAM_NEW_MAIL_DIR;
	    } else {
		_log_err(LOG_CRIT,
			 "failed to duplicate mail directory - ignored");
	    }
	} else if (!strncmp(*argv,"hash=",5)) {
	    char *ep = NULL;
	    *hashcount = strtol(*argv+5,&ep,10);
	    if (!ep || (*hashcount < 0)) {
		*hashcount = 0;
	    }
	} else if (!strcmp(*argv,"close")) {
	    ctrl |= PAM_LOGOUT_TOO;
	} else if (!strcmp(*argv,"nopen")) {
	    ctrl |= PAM_NO_LOGIN;
	} else if (!strcmp(*argv,"noenv")) {
	    ctrl |= PAM_NO_ENV;
	} else if (!strcmp(*argv,"empty")) {
	    ctrl |= PAM_EMPTY_TOO;
	} else {
	    _log_err(LOG_ERR,"pam_parse: unknown option; %s",*argv);
	}
    }

    if ((*hashcount != 0) && !(ctrl & PAM_NEW_MAIL_DIR)) {
	*maildir = x_strdup(DEFAULT_MAIL_DIRECTORY);
	ctrl |= PAM_NEW_MAIL_DIR;
    }

    return ctrl;
}
开发者ID:aosm,项目名称:pam,代码行数:57,代码来源:pam_mail.c

示例10: x_strdup

/*
  find an executable by name in $PATH. Exclude any that are links
  to exclude_name
*/
char *find_executable(const char *name, const char *exclude_name)
{
    char *path;
    char *tok;
    struct stat st1, st2;

    if (*name == '/') {
	return x_strdup(name);
    }

    path = getenv("F90CACHE_PATH");
    if (!path) {
	path = getenv("PATH");
    }
    if (!path) {
	fc_log("no PATH variable!?\n");
	return NULL;
    }

    path = x_strdup(path);

    /* search the path looking for the first compiler of the right name
       that isn't us */
    for (tok=strtok(path,":"); tok; tok = strtok(NULL, ":")) {
	char *fname;
	x_asprintf(&fname, "%s/%s", tok, name);
	/* look for a normal executable file */
	if (access(fname, X_OK) == 0 &&
	     lstat(fname, &st1) == 0 &&
	     stat(fname, &st2) == 0 &&
	     S_ISREG(st2.st_mode)) {
	    /* if its a symlink then ensure it doesn't
		point at something called exclude_name */
	    if (S_ISLNK(st1.st_mode)) {
		char *buf = x_realpath(fname);
		if (buf) {
		    char *p = str_basename(buf);
		    if (strcmp(p, exclude_name) == 0) {
			/* its a link to "f90cache" ! */
			free(p);
			free(buf);
			continue;
		    }
		    free(buf);
		    free(p);
		}
	    }

	    /* found it! */
	    free(path);
	    return fname;
	}
	free(fname);
    }

    return NULL;
}
开发者ID:muellermichel,项目名称:f90cache,代码行数:61,代码来源:execute.c

示例11: get_root

static char *
get_root(void)
{
#ifndef _WIN32
	return x_strdup("/");
#else
	char volume[4]; // "C:\"
	GetVolumePathName(get_cwd(), volume, sizeof(volume));
	return x_strdup(volume);
#endif
}
开发者ID:ezyang,项目名称:ccache,代码行数:11,代码来源:test_argument_processing.c

示例12: strcasematch

/* Case insentively matches against wildcards */
int strcasematch(const char *str, const char *mask) {
  char *newstr, *newmask;
  int ret;

  newstr = strlwr(x_strdup(str));
  newmask = strlwr(x_strdup(mask));

  ret = strmatch(newstr, newmask);

  free(newstr);
  free(newmask);

  return ret;
}
开发者ID:Cougar,项目名称:dircproxy,代码行数:15,代码来源:match.c

示例13: main

int
main(int argc, char *argv[])
{
    char *program_name, *compiler_name, *other_wrappers, *sysroot;
    struct args *compiler_args, *cmd;

    compiler_args = args_init(argc, argv);

    /* check if we were called directly. */
    program_name = basename(compiler_args->argv[0]);
    args_remove_first(compiler_args);
    if (str_eq(program_name, MYNAME)) {
        /* the first argument should be a compiler */
        if (compiler_args->argc < 1 || compiler_args->argv[0][0] == '-') {
            fprintf(stderr, "%s", USAGE_TEXT);
            exit(1);
        }

        compiler_name = x_strdup(compiler_args->argv[0]);
        args_remove_first(compiler_args);
    } else {
        compiler_name = x_strdup(program_name);
    }
    free(program_name);

    other_wrappers = getenv(MYNAME "_OTHER_WRAPPERS");
    if (!other_wrappers) {
        other_wrappers = "ccache distcc";
    }

    cmd = find_all_executables(compiler_name, MYNAME, other_wrappers);
    if (!cmd) {
        fatal("No valid executables named %s found!", compiler_name);
    }
    free(compiler_name);

    sysroot = getenv("SYSROOT");
    if (sysroot) {
        args_add(cmd, "--sysroot");
        args_add(cmd, sysroot);
    }

    args_extend(cmd, compiler_args);
    args_free(compiler_args);

    execute(cmd->argv);
    return 1;
}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:sysroot-wrappers,代码行数:48,代码来源:cc_wrap.c

示例14: args_set

// Set argument at given index.
void
args_set(struct args *args, int index, const char *value)
{
	assert(index < args->argc);
	free(args->argv[index]);
	args->argv[index] = x_strdup(value);
}
开发者ID:ccache,项目名称:ccache,代码行数:8,代码来源:args.c

示例15: x_strtrim

/*
 * Trims leading/trailing spaces from the string, returns a copy of it if it
 * is modified.
 */
char *
x_strtrim(char *s)
{
    char *base = s;
    char *d;

    if (s != 0 && *s != '\0') {
	char *t = x_strdup(base);
	s = t;
	d = s;
	while (isspace(CharOf(*s))) {
	    ++s;
	}
	while ((*d++ = *s++) != '\0') {
	    ;
	}
	if (*t != '\0') {
	    s = t + strlen(t);
	    while (s != t && isspace(CharOf(s[-1]))) {
		*--s = '\0';
	    }
	}
	if (!strcmp(t, base)) {
	    free(t);
	} else {
	    base = t;
	}
    }
    return base;
}
开发者ID:JeffersonLab,项目名称:clas12-coda,代码行数:34,代码来源:xstrings.c


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