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

C++ concat_path_file函数代码示例

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

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



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

示例1: mktemp_main

int mktemp_main(int argc, char **argv)
{
	unsigned long flags = getopt32(argc, argv, "dqt");
	char *chp;

	if (optind + 1 != argc)
		bb_show_usage();

	chp = argv[optind];

	if (flags & 4) {
		char *dir = getenv("TMPDIR");
		if (dir && *dir != '\0')
			chp = concat_path_file(dir, chp);
		else
			chp = concat_path_file("/tmp/", chp);
	}

	if (flags & 1) {
		if (mkdtemp(chp) == NULL)
			return EXIT_FAILURE;
	} else {
		if (mkstemp(chp) < 0)
			return EXIT_FAILURE;
	}

	puts(chp);

	return EXIT_SUCCESS;
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:30,代码来源:mktemp.c


示例2: find_executable

/* search (*PATHp) for an executable file;
 * return allocated string containing full path if found;
 *  PATHp points to the component after the one where it was found
 *  (or NULL),
 *  you may call find_executable again with this PATHp to continue
 *  (if it's not NULL).
 * return NULL otherwise; (PATHp is undefined)
 * in all cases (*PATHp) contents will be trashed (s/:/NUL/).
 */
char* FAST_FUNC find_executable(const char *filename, char **PATHp)
{
	/* About empty components in $PATH:
	 * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
	 * 8.3 Other Environment Variables - PATH
	 * A zero-length prefix is a legacy feature that indicates the current
	 * working directory. It appears as two adjacent colons ( "::" ), as an
	 * initial colon preceding the rest of the list, or as a trailing colon
	 * following the rest of the list.
	 */
	char *p, *n;

	p = *PATHp;
	while (p) {
		n = strchr(p, ':');
		if (n)
			*n++ = '\0';
		p = concat_path_file(
			p[0] ? p : ".", /* handle "::" case */
			filename
		);
		if (file_is_executable(p)) {
			*PATHp = n;
			return p;
		}
		free(p);
		p = n;
	} /* on loop exit p == NULL */
	return p;
}
开发者ID:android-ide,项目名称:busybox,代码行数:39,代码来源:executable.c


示例3: concat_path_file

static struct dump_dir *try_dd_create(const char *base_dir_name, const char *dir_name, uid_t uid)
{
    char *path = concat_path_file(base_dir_name, dir_name);
    struct dump_dir *dd = dd_create(path, uid, DEFAULT_DUMP_DIR_MODE);
    free(path);
    return dd;
}
开发者ID:tylerwhall,项目名称:libreport,代码行数:7,代码来源:create_dump_dir.c


示例4: save_abrt_plugin_conf_file

int save_abrt_plugin_conf_file(const char *file, map_string_t *settings)
{
    char *path = concat_path_file(PLUGINS_CONF_DIR, file);
    int retval = save_conf_file(path, settings);
    free(path);
    return retval;
}
开发者ID:arhledvink,项目名称:abrt,代码行数:7,代码来源:abrt_conf.c


示例5: get_dirsize

double get_dirsize(const char *pPath)
{
    DIR *dp = opendir(pPath);
    if (dp == NULL)
        return 0;

    struct dirent *ep;
    struct stat statbuf;
    double size = 0;
    while ((ep = readdir(dp)) != NULL)
    {
        if (dot_or_dotdot(ep->d_name))
            continue;
        char *dname = concat_path_file(pPath, ep->d_name);
        if (lstat(dname, &statbuf) != 0)
        {
            goto next;
        }
        if (S_ISDIR(statbuf.st_mode))
        {
            size += get_dirsize(dname);
        }
        else if (S_ISREG(statbuf.st_mode))
        {
            size += statbuf.st_size;
        }
 next:
        free(dname);
    }
    closedir(dp);
    return size;
}
开发者ID:fengye0316,项目名称:libreport,代码行数:32,代码来源:dirsize.c


示例6: who_main

int who_main(int argc, char **argv)
{
	char str6[6];
	struct utmp *ut;
	struct stat st;
	char *name;

	if (argc > 1) {
		bb_show_usage();
	}

	setutent();
	printf("USER       TTY      IDLE      TIME           HOST\n");
	while ((ut = getutent()) != NULL) {
		if (ut->ut_user[0] && ut->ut_type == USER_PROCESS) {
			time_t thyme = ut->ut_tv.tv_sec;

			/* ut->ut_line is device name of tty - "/dev/" */
			name = concat_path_file("/dev", ut->ut_line);
			str6[0] = '?';
			str6[1] = '\0';
			if (stat(name, &st) == 0)
				idle_string(str6, st.st_atime);
			printf("%-10s %-8s %-9s %-14.14s %s\n",
					ut->ut_user, ut->ut_line, str6,
					ctime(&thyme) + 4, ut->ut_host);
			if (ENABLE_FEATURE_CLEAN_UP)
				free(name);
		}
	}
	if (ENABLE_FEATURE_CLEAN_UP)
		endutent();
	return 0;
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:34,代码来源:who.c


示例7: delete_contents

// Recursively delete contents of rootfs.
static void delete_contents(const char *directory, dev_t rootdev)
{
	DIR *dir;
	struct dirent *d;
	struct stat st;

	// Don't descend into other filesystems
	if (lstat(directory, &st) || st.st_dev != rootdev)
		return;

	// Recursively delete the contents of directories.
	if (S_ISDIR(st.st_mode)) {
		dir = opendir(directory);
		if (dir) {
			while ((d = readdir(dir))) {
				char *newdir = d->d_name;

				// Skip . and ..
				if (DOT_OR_DOTDOT(newdir))
					continue;

				// Recurse to delete contents
				newdir = concat_path_file(directory, newdir);
				delete_contents(newdir, rootdev);
				free(newdir);
			}
			closedir(dir);

			// Directory should now be empty.  Zap it.
			rmdir(directory);
		}

	// It wasn't a directory.  Zap it.
	} else unlink(directory);
}
开发者ID:Jeanlst,项目名称:Onlive-Source-Backup,代码行数:36,代码来源:switch_root.c


示例8: dd_exist

int dd_exist(const struct dump_dir *dd, const char *path)
{
    char *full_path = concat_path_file(dd->dd_dirname, path);
    int ret = exist_file_dir(full_path);
    free(full_path);
    return ret;
}
开发者ID:scottgfhong,项目名称:libreport,代码行数:7,代码来源:dump_dir.c


示例9: wall_main

int wall_main(int argc UNUSED_PARAM, char **argv)
{
	struct utmpx *ut;
	char *msg;
	int fd;

	fd = STDIN_FILENO;
	if (argv[1]) {
		/* The applet is setuid.
		 * Access to the file must be under user's uid/gid.
		 */
		fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
	}
	msg = xmalloc_read(fd, NULL);
	if (ENABLE_FEATURE_CLEAN_UP && argv[1])
		close(fd);
	setutxent();
	while ((ut = getutxent()) != NULL) {
		char *line;
		if (ut->ut_type != USER_PROCESS)
			continue;
		line = concat_path_file("/dev", ut->ut_line);
		xopen_xwrite_close(line, msg);
		free(line);
	}
	if (ENABLE_FEATURE_CLEAN_UP) {
		endutxent();
		free(msg);
	}
	return EXIT_SUCCESS;
}
开发者ID:android-ide,项目名称:busybox,代码行数:31,代码来源:wall.c


示例10: get_dir_size

static double get_dir_size(const char *dirname,
                           char **worst_file,
                           double *worst_file_size)
{
    DIR *dp = opendir(dirname);
    if (!dp)
        return 0;

    /* "now" is used only if caller wants to know worst_file */
    time_t now = worst_file ? time(NULL) : 0;
    struct dirent *dent;
    struct stat stats;
    double size = 0;
    while ((dent = readdir(dp)) != NULL)
    {
        if (dot_or_dotdot(dent->d_name))
            continue;

        char *fullname = concat_path_file(dirname, dent->d_name);
        if (lstat(fullname, &stats) != 0)
        {
            free(fullname);
            continue;
        }

        if (S_ISDIR(stats.st_mode))
        {
            double sz = get_dir_size(fullname, worst_file, worst_file_size);
            size += sz;
        }
        else if (S_ISREG(stats.st_mode))
        {
            double sz = stats.st_size;
            size += sz;

            if (worst_file)
            {
                /* Calculate "weighted" size and age
                 * w = sz_kbytes * age_mins */
                sz /= 1024;
                long age = (now - stats.st_mtime) / 60;
                if (age > 0)
                    sz *= age;

                if (sz > *worst_file_size)
                {
                    *worst_file_size = sz;
                    free(*worst_file);
                    *worst_file = fullname;
                    fullname = NULL;
                }
            }
        }
        free(fullname);
    }
    closedir(dp);

    return size;
}
开发者ID:michalnowak,项目名称:abrt-tests,代码行数:59,代码来源:abrt-action-trim-files.c


示例11: mktemp_main

int mktemp_main(int argc UNUSED_PARAM, char **argv)
{
	const char *path;
	char *chp;
	unsigned opts;
	enum {
		OPT_d = 1 << 0,
		OPT_q = 1 << 1,
		OPT_t = 1 << 2,
		OPT_p = 1 << 3,
		OPT_u = 1 << 4,
	};

	path = getenv("TMPDIR");
	if (!path || path[0] == '\0')
		path = "/tmp";

	opt_complementary = "?1"; /* 1 argument max */
	opts = getopt32(argv, "dqtp:u", &path);

	chp = argv[optind];
	if (!chp) {
		/* GNU coreutils 8.4:
		 * bare "mktemp" -> "mktemp -t tmp.XXXXXX"
		 */
		chp = xstrdup("tmp.XXXXXX");
		opts |= OPT_t;
	}
#if 0
	/* Don't allow directory separator in template */
	if ((opts & OPT_t) && bb_basename(chp) != chp) {
		errno = EINVAL;
		goto error;
	}
#endif
	if (opts & (OPT_t|OPT_p))
		chp = concat_path_file(path, chp);

	if (opts & OPT_u) {
		chp = mktemp(chp);
		if (chp[0] == '\0')
			goto error;
	} else if (opts & OPT_d) {
		if (mkdtemp(chp) == NULL)
			goto error;
	} else {
		if (mkstemp(chp) < 0)
			goto error;
	}
	puts(chp);
	return EXIT_SUCCESS;
 error:
	if (opts & OPT_q)
		return EXIT_FAILURE;
	/* don't use chp as it gets mangled in case of error */
	bb_perror_nomsg_and_die();
}
开发者ID:ThinkIntegrate,项目名称:busybox,代码行数:57,代码来源:mktemp.c


示例12: mark_unprocessed_dump_dirs_not_reportable

/* The function expects that FILENAME_COUNT dump dir element is created by
 * abrtd after all post-create events are successfully done. Thus if
 * FILENAME_COUNT element doesn't exist abrtd can consider the dump directory
 * as unprocessed.
 *
 * Relying on content of dump directory has one problem. If a hook provides
 * FILENAME_COUNT abrtd will consider the dump directory as processed.
 */
static void mark_unprocessed_dump_dirs_not_reportable(const char *path)
{
    log_notice("Searching for unprocessed dump directories");

    DIR *dp = opendir(path);
    if (!dp)
    {
        perror_msg("Can't open directory '%s'", path);
        return;
    }

    struct dirent *dent;
    while ((dent = readdir(dp)) != NULL)
    {
        if (dot_or_dotdot(dent->d_name))
            continue; /* skip "." and ".." */

        char *full_name = concat_path_file(path, dent->d_name);

        struct stat stat_buf;
        if (stat(full_name, &stat_buf) != 0)
        {
            perror_msg("Can't access path '%s'", full_name);
            goto next_dd;
        }

        if (S_ISDIR(stat_buf.st_mode) == 0)
            /* This is expected. The dump location contains some aux files */
            goto next_dd;

        struct dump_dir *dd = dd_opendir(full_name, /*flags*/0);
        if (dd)
        {
            if (!problem_dump_dir_is_complete(dd) && !dd_exist(dd, FILENAME_NOT_REPORTABLE))
            {
                log_warning("Marking '%s' not reportable (no '"FILENAME_COUNT"' item)", full_name);

                dd_save_text(dd, FILENAME_NOT_REPORTABLE, _("The problem data are "
                            "incomplete. This usually happens when a problem "
                            "is detected while computer is shutting down or "
                            "user is logging out. In order to provide "
                            "valuable problem reports, ABRT will not allow "
                            "you to submit this problem. If you have time and "
                            "want to help the developers in their effort to "
                            "sort out this problem, please contact them directly."));

            }
            dd_close(dd);
        }

  next_dd:
        free(full_name);
    }
    closedir(dp);
}
开发者ID:wlindauer,项目名称:abrt,代码行数:63,代码来源:abrtd.c


示例13: set_settings

static void set_settings(struct bugzilla_struct *b, map_string_t *settings)
{
    const char *environ;

    environ = getenv("Bugzilla_Login");
    b->b_login = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Login"));

    environ = getenv("Bugzilla_Password");
    b->b_password = xstrdup(environ ? environ : get_map_string_item_or_empty(settings, "Password"));

    environ = getenv("Bugzilla_BugzillaURL");
    b->b_bugzilla_url = environ ? environ : get_map_string_item_or_empty(settings, "BugzillaURL");
    if (!b->b_bugzilla_url[0])
        b->b_bugzilla_url = "https://bugzilla.redhat.com";
    else
    {
        /* We don't want trailing '/': "https://host/dir/" -> "https://host/dir" */
        char *last_slash = strrchr(b->b_bugzilla_url, '/');
        if (last_slash && last_slash[1] == '\0')
            *last_slash = '\0';
    }
    b->b_bugzilla_xmlrpc = concat_path_file(b->b_bugzilla_url, "xmlrpc.cgi");

    environ = getenv("Bugzilla_Product");
    if (environ)
    {
        b->b_product = xstrdup(environ);
        environ = getenv("Bugzilla_ProductVersion");
        if (environ)
            b->b_product_version = xstrdup(environ);
    }
    else
    {
        const char *option = get_map_string_item_or_NULL(settings, "Product");
        if (option)
            b->b_product = xstrdup(option);
        option = get_map_string_item_or_NULL(settings, "ProductVersion");
        if (option)
            b->b_product_version = xstrdup(option);
    }

    if (!b->b_product)
    {   /* Compat, remove it later (2014?). */
        environ = getenv("Bugzilla_OSRelease");
        if (environ)
            parse_release_for_bz(environ, &b->b_product, &b->b_product_version);
    }

    environ = getenv("Bugzilla_SSLVerify");
    b->b_ssl_verify = string_to_bool(environ ? environ : get_map_string_item_or_empty(settings, "SSLVerify"));

    environ = getenv("Bugzilla_DontMatchComponents");
    b->b_DontMatchComponents = environ ? environ : get_map_string_item_or_empty(settings, "DontMatchComponents");
}
开发者ID:hors,项目名称:libreport,代码行数:54,代码来源:reporter-bugzilla.c


示例14: dump_lxc_info

void dump_lxc_info(struct dump_dir *dd, const char *lxc_cmd)
{
    if (!dd_exist(dd, FILENAME_CONTAINER))
        dd_save_text(dd, FILENAME_CONTAINER, "lxc");

    char *mntnf_path = concat_path_file(dd->dd_dirname, FILENAME_MOUNTINFO);
    FILE *mntnf_file = fopen(mntnf_path, "r");
    free(mntnf_path);

    struct mountinfo mntnf;
    int r = get_mountinfo_for_mount_point(mntnf_file, &mntnf, "/");
    fclose(mntnf_file);

    if (r != 0)
    {
        error_msg("lxc processes must have re-mounted root");
        goto dump_lxc_info_cleanup;
    }

    const char *mnt_root = MOUNTINFO_ROOT(mntnf);
    const char *last_slash = strrchr(mnt_root, '/');
    if (last_slash == NULL || (strcmp("rootfs", last_slash +1) != 0))
    {
        error_msg("Invalid root path '%s'", mnt_root);
        goto dump_lxc_info_cleanup;
    }

    if (last_slash == mnt_root)
    {
        error_msg("root path misses container id: '%s'", mnt_root);
        goto dump_lxc_info_cleanup;
    }

    const char *tmp = strrchr(last_slash - 1, '/');
    if (tmp == NULL)
    {
        error_msg("root path misses first /: '%s'", mnt_root);
        goto dump_lxc_info_cleanup;
    }

    char *container_id = xstrndup(tmp + 1, (last_slash - tmp) - 1);

    dd_save_text(dd, FILENAME_CONTAINER_ID, container_id);
    dd_save_text(dd, FILENAME_CONTAINER_UUID, container_id);

    free(container_id);

    /* TODO: make a copy of 'config' */
    /* get mount point for MOUNTINFO_MOUNT_SOURCE(mntnf) + MOUNTINFO_ROOT(mntnf) */

dump_lxc_info_cleanup:
    mountinfo_destroy(&mntnf);
}
开发者ID:arhledvink,项目名称:abrt,代码行数:53,代码来源:abrt-action-save-container-data.c


示例15: do_cp

/**
 * @param[in] argc Argument count from command line
 * @param[in] argv List of input arguments
 */
static int do_cp(int argc, char *argv[])
{
	int ret = 1;
	struct stat statbuf;
	int last_is_dir = 0;
	int i;
	int opt;
	int verbose = 0;
	int argc_min;

	while ((opt = getopt(argc, argv, "v")) > 0) {
		switch (opt) {
		case 'v':
			verbose = 1;
			break;
		}
	}

	argc_min = optind + 2;

	if (argc < argc_min)
		return COMMAND_ERROR_USAGE;

	if (!stat(argv[argc - 1], &statbuf)) {
		if (S_ISDIR(statbuf.st_mode))
			last_is_dir = 1;
	}

	if (argc > argc_min && !last_is_dir) {
		printf("cp: target `%s' is not a directory\n", argv[argc - 1]);
		return 1;
	}

	for (i = optind; i < argc - 1; i++) {
		if (last_is_dir) {
			char *dst;
			dst = concat_path_file(argv[argc - 1], basename(argv[i]));
			ret = copy_file(argv[i], dst, verbose);
			free(dst);
			if (ret)
				goto out;
		} else {
			ret = copy_file(argv[i], argv[argc - 1], verbose);
			if (ret)
				goto out;
		}
	}

	ret = 0;
out:
	return ret;
}
开发者ID:AshishNamdev,项目名称:barebox,代码行数:56,代码来源:cp.c


示例16: which_main

extern int which_main(int argc, char **argv)
{
	char *path_list, *path_n;
	int i, count=1, found, status = EXIT_SUCCESS;

	if (argc <= 1 || **(argv + 1) == '-')
		bb_show_usage();
	argc--;

	path_list = getenv("PATH");
	if (path_list != NULL) {
		for(i=strlen(path_list); i > 0; i--)
			if (path_list[i]==':') {
				path_list[i]=0;
				count++;
			}
	} else {
		path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin";
		count = 5;
	}

	while(argc-- > 0) { 
		char *buf;
		path_n = path_list;
		argv++;
		found = 0;

		/*
		 * Check if we were given the full path, first.
		 * Otherwise see if the file exists in our $PATH.
		 */
		buf = *argv;
		if (file_exists(buf)) {
			puts(buf);
			found = 1;
		} else {
			for (i = 0; i < count; i++) {
				buf = concat_path_file(path_n, *argv);
				if (file_exists(buf)) {
					puts(buf);
					found = 1;
					break;
				}
				free(buf);
				path_n += (strlen(path_n) + 1);
			}
		}
		if (!found)
			status = EXIT_FAILURE;
	}
	return status;
}
开发者ID:BackupTheBerlios,项目名称:athomux-svn,代码行数:52,代码来源:which.c


示例17: xasprintf

static char *get_user_config_file_path(const char *name, const char *suffix)
{
    char *s, *conf;

    if (suffix != NULL)
        s = xasprintf(BASE_DIR_FOR_USER_CONFIG_FILE"%s.%s", name, suffix);
    else
        s = xasprintf(BASE_DIR_FOR_USER_CONFIG_FILE"%s", name);

    conf = concat_path_file(g_get_user_config_dir(), s);
    free(s);
    return conf;
}
开发者ID:tylerwhall,项目名称:libreport,代码行数:13,代码来源:user_settings.c


示例18: sysctl_read_setting

/*
 *     Read a sysctl setting
 */
static int sysctl_read_setting(const char *name)
{
	int retval;
	char *tmpname, *outname, *cptr;
	char inbuf[1025];
	FILE *fp;

	if (!*name) {
		if (option_mask32 & FLAG_SHOW_KEY_ERRORS)
			bb_error_msg(ERR_INVALID_KEY, name);
		return -1;
	}

	tmpname = concat_path_file(PROC_SYS, name);
	outname = xstrdup(tmpname + strlen_PROC_SYS);

	while ((cptr = strchr(tmpname, '.')) != NULL)
		*cptr = '/';
	while ((cptr = strchr(outname, '/')) != NULL)
		*cptr = '.';

	fp = fopen(tmpname, "r");
	if (fp == NULL) {
		switch (errno) {
		case ENOENT:
			if (option_mask32 & FLAG_SHOW_KEY_ERRORS)
				bb_error_msg(ERR_INVALID_KEY, outname);
			break;
		case EACCES:
			bb_error_msg(ERR_PERMISSION_DENIED, outname);
			break;
		default:
			bb_perror_msg(ERR_UNKNOWN_READING, outname);
			break;
		}
		retval = EXIT_FAILURE;
	} else {
		while (fgets(inbuf, sizeof(inbuf) - 1, fp)) {
			if (option_mask32 & FLAG_SHOW_KEYS) {
				printf("%s = ", outname);
			}
			fputs(inbuf, stdout);
		}
		fclose(fp);
		retval = EXIT_SUCCESS;
	}

	free(tmpname);
	free(outname);
	return retval;
} /* end sysctl_read_setting() */
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:54,代码来源:sysctl.c


示例19: sysctl_read_setting

/*
 *     Read a sysctl setting
 *
 */
int sysctl_read_setting(const char *setting, int output)
{
    int retval = 0;
    char *tmpname, *outname, *cptr;
    char inbuf[1025];
    const char *name = setting;
    FILE *fp;

    if (!setting || !*setting)
        bb_error_msg(ERR_INVALID_KEY, setting);

    tmpname = concat_path_file(PROC_PATH, name);
    outname = xstrdup(tmpname + strlen(PROC_PATH));

    while ((cptr = strchr(tmpname, '.')) != NULL)
        *cptr = '/';
    while ((cptr = strchr(outname, '/')) != NULL)
        *cptr = '.';

    if ((fp = fopen(tmpname, "r")) == NULL) {
        switch (errno) {
        case ENOENT:
            bb_error_msg(ERR_INVALID_KEY, outname);
            break;
        case EACCES:
            bb_error_msg(ERR_PERMISSION_DENIED, outname);
            break;
        default:
            bb_error_msg(ERR_UNKNOWN_READING, errno, outname);
            break;
        }
        retval = -1;
    } else {
        while (fgets(inbuf, sizeof(inbuf) - 1, fp)) {
            if (output) {
                dwrite_str(STDOUT_FILENO, outname);
                dwrite_str(STDOUT_FILENO, " = ");
            }
            dwrite_str(STDOUT_FILENO, inbuf);
        }
        fclose(fp);
    }

    free(tmpname);
    free(outname);
    return retval;
}						/* end sysctl_read_setting() */
开发者ID:nskeeper,项目名称:Lantern,代码行数:51,代码来源:sysctl.c


示例20: bb_perror_msg

extern char *find_real_root_device_name(const char* name)
{
	DIR *dir;
	struct dirent *entry;
	struct stat statBuf, rootStat;
	char *fileName = NULL;
	dev_t dev;

	if (stat("/", &rootStat) != 0)
		bb_perror_msg("could not stat '/'");
	else {
		/* This check is here in case they pass in /dev name */
		if ((rootStat.st_mode & S_IFMT) == S_IFBLK)
			dev = rootStat.st_rdev;
		else
			dev = rootStat.st_dev;

		dir = opendir("/dev");
		if (!dir)
			bb_perror_msg("could not open '/dev'");
		else {
			while((entry = readdir(dir)) != NULL) {
				const char *myname = entry->d_name;
				/* Must skip ".." since that is "/", and so we
				 * would get a false positive on ".."  */
				if (myname[0] == '.' && myname[1] == '.' && !myname[2])
					continue;

				fileName = concat_path_file("/dev", myname);

				/* Some char devices have the same dev_t as block
				 * devices, so make sure this is a block device */
				if (stat(fileName, &statBuf) == 0 &&
						S_ISBLK(statBuf.st_mode)!=0 &&
						statBuf.st_rdev == dev)
					break;
				free(fileName);
				fileName=NULL;
			}
			closedir(dir);
		}
	}
	if(fileName==NULL)
		fileName = bb_xstrdup("/dev/root");
	return fileName;
}
开发者ID:guadalinex-archive,项目名称:guadalinex-2005,代码行数:46,代码来源:find_root_device.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ concatenate函数代码示例发布时间:2022-05-30
下一篇:
C++ concat3函数代码示例发布时间: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