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


C++ pathconf函数代码示例

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


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

示例1: get_pathconf_name_max

static int get_pathconf_name_max(char *dir, long *name_max) {
#if defined(HAVE_PATHCONF)
  *name_max = pathconf(dir, _PC_NAME_MAX);
  return 0;
#else
  errno = ENOSYS;
  return -1;
#endif /* HAVE_PATHCONF */
}
开发者ID:Nakor78,项目名称:proftpd,代码行数:9,代码来源:support.c

示例2: main

int
main(int argc, char *argv[])
{
	char *progname;
	char *ttyname;
	int fd;
	int dofree;

	dofree = 0;

	progname = basename(argv[0]);
	if (argc != 2)
		errx(EX_USAGE, "usage: %s <ttyname>\n", progname);
	if (geteuid() != 0)
		errx(EX_NOPERM, "Sorry\n");

	if (argv[1][0] == '/') {
		ttyname = argv[1];
	} else {
		size_t len, maxpath, result;

		len = strlen(argv[1]) + sizeof(DEVPATHNAME) + 1;

		maxpath = pathconf(DEVPATHNAME, _PC_PATH_MAX);
		if (len > maxpath) {
			warnc(ENAMETOOLONG, ttyname);
			exit(EX_DATAERR);
		}

		ttyname = malloc(len);
		if (ttyname == NULL) {
			warnc(ENOMEM, "malloc");
			exit(EX_OSERR);
		}
		dofree = 1;

		result = snprintf(ttyname, len, "%s/%s", DEVPATHNAME, argv[1]);
		if (result >= len)
			warnc(ENOMEM, "snprintf");
	}

	fd = open(ttyname, O_RDWR);
	if (fd == -1) {
		warnc(errno, "open %s", ttyname);
		if (dofree)
			free(ttyname);
		exit(EX_OSERR);
	}

	if (0 != ioctl(fd, TIOCNXCL, 0))
		warnc(errno, "ioctl TIOCNXCL %s", ttyname);

	if (dofree)
		free(ttyname);
	exit(0);
}
开发者ID:edgar-pek,项目名称:PerspicuOS,代码行数:56,代码来源:tionxcl.c

示例3: uv__fs_pathmax_size

static ssize_t uv__fs_pathmax_size(const char* path) {
  ssize_t pathmax;

  pathmax = pathconf(path, _PC_PATH_MAX);

  if (pathmax == -1)
    pathmax = UV__FS_PATH_MAX;

  return pathmax;
}
开发者ID:shantanusharma,项目名称:node,代码行数:10,代码来源:fs.c

示例4: sml_pathconf

size_t
sml_pathconf(char *file, size_t name)
{
    size_t res;
    int n = sml_pathconf_number(name);
    errno = 0;
    res = pathconf(file, n);
    if (res == -1 && errno == 0) res = -2;
    return res;
}
开发者ID:ee08b397,项目名称:mlkit,代码行数:10,代码来源:Posix.c

示例5: TEST

TEST(UNISTD_TEST, pathconf_fpathconf) {
  TemporaryFile tf;
  long rc = 0L;
  // As a file system's block size is always power of 2, the configure values
  // for ALLOC and XFER should be power of 2 as well.
  rc = pathconf(tf.filename, _PC_ALLOC_SIZE_MIN);
  ASSERT_TRUE(rc > 0 && powerof2(rc));
  rc = pathconf(tf.filename, _PC_REC_MIN_XFER_SIZE);
  ASSERT_TRUE(rc > 0 && powerof2(rc));
  rc = pathconf(tf.filename, _PC_REC_XFER_ALIGN);
  ASSERT_TRUE(rc > 0 && powerof2(rc));

  rc = fpathconf(tf.fd, _PC_ALLOC_SIZE_MIN);
  ASSERT_TRUE(rc > 0 && powerof2(rc));
  rc = fpathconf(tf.fd, _PC_REC_MIN_XFER_SIZE);
  ASSERT_TRUE(rc > 0 && powerof2(rc));
  rc = fpathconf(tf.fd, _PC_REC_XFER_ALIGN);
  ASSERT_TRUE(rc > 0 && powerof2(rc));
}
开发者ID:0xDEC0DE8,项目名称:platform_bionic,代码行数:19,代码来源:unistd_test.cpp

示例6: path_max

int path_max( const char * filename )
  {
  long result;
  if( !filename ) filename = "/";
  errno = 0;
  result = pathconf( filename, _PC_PATH_MAX );
  if( result < 0 ) { if( errno ) result = 256; else result = 1024; }
  else if( result < 256 ) result = 256;
  return result;
  }
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:10,代码来源:buffer.c

示例7: test_chown

static void
test_chown(void)
{
//#define TEST_CHOWN
#if defined(TEST_CHOWN)
    printf("LINK_MAX = %ld\n", pathconf("/", _PC_LINK_MAX));

    print(sysconf(_POSIX_CHOWN_RESTRICTED));
#endif  //TEST_CHOWN
}
开发者ID:codeliuer,项目名称:learn-code,代码行数:10,代码来源:test.c

示例8: SystemNative_GetMaximumPath

extern "C" int64_t SystemNative_GetMaximumPath()
{
    int64_t result = pathconf("/", _PC_PATH_MAX);
    if (result == -1)
    {
        result = PATH_MAX;
    }

    return result;
}
开发者ID:6xiaoxian9,项目名称:corefx,代码行数:10,代码来源:pal_process.cpp

示例9: jlog_logio_cleanse

static int
jlog_logio_cleanse(noit_log_stream_t ls) {
    jlog_asynch_ctx *actx;
    jlog_ctx *log;
    DIR *d;
    struct dirent *de, *entry;
    int cnt = 0;
    char path[PATH_MAX], current_log[9];
    int size = 0;

    actx = (jlog_asynch_ctx *)ls->op_ctx;
    if(!actx) return -1;
    log = actx->log;
    if(!log) return -1;
    if(jlog_lspath_to_fspath(ls, path, sizeof(path), NULL) <= 0) return -1;
    d = opendir(path);
    snprintf(current_log, sizeof(current_log), "%08x", log->current_log);

#ifdef _PC_NAME_MAX
    size = pathconf(path, _PC_NAME_MAX);
    if(size < 0) size = PATH_MAX + 128;
#endif
    size = MIN(size, PATH_MAX + 128);
    de = alloca(size);

    if(!d) return -1;
    while(portable_readdir_r(d, de, &entry) == 0 && entry != NULL) {
        u_int32_t logid;
        /* the current log file isn't a deletion target. period. */
        if(is_datafile(entry->d_name, &logid) &&
                strcmp(current_log, entry->d_name)) {
            int rv;
            struct stat st;
            char fullfile[PATH_MAX];
            char fullidx[PATH_MAX];

            snprintf(fullfile, sizeof(fullfile), "%s/%s", path, entry->d_name);
            snprintf(fullidx, sizeof(fullidx), "%s/%s" INDEX_EXT,
                     path, entry->d_name);
            /* coverity[fs_check_call] */
            while((rv = stat(fullfile, &st)) != 0 && errno == EINTR);
            if(rv == 0) {
                int readers;
                readers = __jlog_pending_readers(log, logid);
                if(readers == 0) {
                    /* coverity[toctou] */
                    unlink(fullfile);
                    unlink(fullidx);
                }
            }
        }
    }
    closedir(d);
    return cnt;
}
开发者ID:jjbuchan,项目名称:reconnoiter,代码行数:55,代码来源:noit_log.c

示例10: explore_dir

/* ------------------------------------------------------------------
 * Opens and iterates through a given directory, operating on allowed
 * files found within it.  . and .. are skipped, as are files beginning
 * with . unless it's been enabled in the flags.  All other entries,
 * both files and directories, are thrown to process_entry to determine
 * whether they're a file/directory/link, and to read/explore them if
 * appropriate.  If threads are being used, they wait for their children
 * threads to terminate after they themselves are done with their work.
 *
 * flags:	The usual I/O option flags.
 * list_head:	A list of already visited directories.  Always will have
 *		the working directory low was called from as the tail,
 *		and will always have the current directory being explored
 *		as the head (so the src = list_head->next->path assignment
 *		is always safe).
 * fullpath:	The realpath of the current directory being explored.
 * dir_depth:	Passed to process_entry.
 * ------------------------------------------------------------------
 */
int explore_dir(params *P, visited_dir *list_head, char *nextpath, 
		int dir_depth)
{
	DIR *d;
	struct dirent *entry;
	struct dirent **done;
	int len;
	
	if ( (d = opendir(nextpath)) == 0)
	{
		return print_file_error(P, errno, nextpath);
	}
	
	if (((P->max_dir_depth) - dir_depth) > read_stat(P, t_ddepth))
		update_stat(P, t_ddepth, ((P->max_dir_depth) - dir_depth));
	
	len = offsetof(struct dirent, d_name) + 
		pathconf(nextpath, _PC_NAME_MAX) + 1;
	if ((entry = malloc(len)) == NULL || 
			(done = malloc(sizeof(struct dirent*))) == NULL)
	{
		fprintf(stderr, "Malloc failed in explore_dir.\n");
		return -1;
	}
	done = &entry;

	while ( (readdir_r(d, entry, done)) == 0 && (*done != NULL))
	{
		/* don't process '.' or '..' in a directory! */
		if ( (strcmp(entry->d_name, THIS_DIR) == 0) 
			|| (strcmp(entry->d_name, PARENT_DIR) == 0))
			continue;

		/* do all files but ones beginning with a dot,
		 * unless we've enabled it! */
		if (entry->d_name[0] == '.')
		{
			if (enabled(P, READ_DOT_FILES))
			{
				process_entry(P, list_head, entry->d_name,
					nextpath, dir_depth, 0);
			}
			else
				inc_stat(P, t_dotfiles, 1);
		}
		else
			process_entry(P, list_head, entry->d_name, nextpath,
				dir_depth, 0);
	}
	closedir(d);
	wait_for_children(list_head);
	free(nextpath);
	return 0;	
}
开发者ID:spoocecow,项目名称:cs720-rlow,代码行数:73,代码来源:low-base.c

示例11: read_syshugepages

static int read_syshugepages(const char* path, const char* node)
{
  static const char hugepages_dir[] = "hugepages";
  DIR *dir;
  struct dirent *result;
  char path2[PATH_MAX];
  struct entry_info e_info;
  long lim;

  dir = opendir(path);
  if (dir == NULL) {
    ERROR("%s: cannot open directory %s", g_plugin_name, path);
    return -1;
  }

  errno = 0;
  if ((lim = pathconf(path, _PC_NAME_MAX)) == -1) {
    /* Limit not defined if errno == 0, otherwise error */
    if (errno != 0) {
      ERROR("%s: pathconf failed", g_plugin_name);
      closedir(dir);
      return -1;
    } else {
      lim = PATH_MAX;
    }
  }

  /* read "hugepages-XXXXXkB" entries */
  while ((result = readdir(dir)) != NULL) {
    if (strncmp(result->d_name, hugepages_dir, sizeof(hugepages_dir)-1)) {
      /* not node dir */
      errno = 0;
      continue;
    }

    /* /sys/devices/system/node/node?/hugepages/ */
    ssnprintf(path2, (size_t) lim, "%s/%s", path, result->d_name);

    e_info.d_name = result->d_name;
    e_info.node = node;
    walk_directory(path2, read_hugepage_entry, &e_info, 0);
    errno = 0;
  }

  /* Check if NULL return from readdir() was an error */
  if (errno != 0) {
      ERROR("%s: readdir failed", g_plugin_name);
      closedir(dir);
      return -1;
  }

  closedir(dir);
  return 0;
}
开发者ID:bzed,项目名称:collectd,代码行数:54,代码来源:hugepages.c

示例12: get_path_max

static int get_path_max(const char *path)
{
#ifdef PATH_MAX
	return PATH_MAX;
#else
	int path_max = pathconf(path, _PC_PATH_MAX);
	if (path_max <= 0)
		path_max = 4096;
	return path_max;
#endif
}
开发者ID:AR-H,项目名称:geany,代码行数:11,代码来源:tm_work_object.c

示例13: getConfig

//' Retrieve one configuration setting
//'
//' This functions returns the configuration setting for a given input.
//' in a data.frame object. The system-level functions \code{sysconf},
//' \code{pathconf} and \code{confstr} provide the underlying information.
//'
//' @title Return a System Configuration Setting
//' @param var An character object specifying a value for which configuration
//' is queried.
//' @param path An optional character object specifying a path. Default is the
//' current directory.
//' @return A result value corresponding to the requested setting. The return
//' type can be either integer for a numeric value, character for text or NULL
//' in case to value could be retrieved.
//' @author Dirk Eddelbuettel
//' @seealso \code{\link{getAll}}
//' @examples
//' if (Sys.info()[["sysname"]] != "SunOS") {
//'     getConfig("_NPROCESSORS_CONF")   # number of processor
//'     getConfig("LEVEL1_ICACHE_SIZE")  # leve1 cache size
//'     getConfig("GNU_LIBC_VERSION")    # libc version
//' }
// [[Rcpp::export]]
SEXP getConfig(const std::string & var,
               const std::string & path = ".") {

    const char *vararg = var.c_str();
    const struct conf *c;

    for (c = vars; c->name != NULL; ++c) {
        if (strcmp (c->name, vararg) == 0 ||
            (strncmp (c->name, "_POSIX_", 7) == 0 && strcmp (c->name + 7, vararg) == 0)) {
            long int value;
            size_t clen;
            char *cvalue;
            switch (c->calltype) {
            case PATHCONF:
                value = pathconf (path.c_str(), c->call_name);
                if (value == -1) {
                    Rcpp::stop("Error with path arg: %s", path.c_str());
                } else {
                    return Rcpp::wrap(value);
                }

            case SYSCONF:
                value = sysconf (c->call_name);
                if (value == -1l) {
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
                    if (c->call_name == _SC_UINT_MAX || c->call_name == _SC_ULONG_MAX) {
                        return Rcpp::wrap(value);
                    } else {
#endif
                        Rcpp::stop("undefined");
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
                    }
#endif
                } else {
                    return Rcpp::wrap(value);
                }

            case CONFSTR:
                clen = confstr (c->call_name, (char *) NULL, 0);
                cvalue = R_alloc(clen, sizeof(char));
                if (cvalue == NULL) {
                    Rcpp::stop("memory exhausted");
                }
                if (confstr(c->call_name, cvalue, clen) != clen) {
                    Rcpp::stop("Error with confstr");
                }
                return Rcpp::wrap(std::string(cvalue));
            }
        }
    }
    // fallback
    return R_NilValue;
}
开发者ID:cran,项目名称:RcppGetconf,代码行数:76,代码来源:getconf.cpp

示例14: pathconf_path_max

int pathconf_path_max( size_t* length )
{
#if defined( PATH_MAX )
  return PATH_MAX;
#else /* defined( PATH_MAX ) */
  const int pathconf_result = pathconf("." , _PC_PATH_MAX );
  if( length ){
    *length = (size_t)(( pathconf_result ) < 0 ? 4098 : pathconf_result );
  }
  return pathconf_result;
#endif /* defined( PATH_MAX ) */
}
开发者ID:maildrop,项目名称:daemonic,代码行数:12,代码来源:daemonic.c

示例15: getAll

//' Retrieve all configuration settings
//'
//' This functions returns all configuration settings which can be queried
//' in a data.frame object. The system-level functions \code{sysconf},
//' \code{pathconf} and \code{confstr} provide all the underlying information.
//'
//' @title Return all System Configuration Settings
//' @param path An optional character object specifying a path. Default is the
//' current directory.
//' @return A data.frame with three colums for key, value and (source) type.
//' Not all keys return a value; in those cases an empty string is returned.
//' Type is one of \code{path}, \code{sys} and \code{conf} and signals how the
//' value was obtained.
//' @author Dirk Eddelbuettel
//' @seealso \code{\link{getConfig}}
//' @examples
//' if (Sys.info()[["sysname"]] != "SunOS") {
//'     head(getAll(), 30)
//'     subset(getAll(), type=="path")
//' }
// [[Rcpp::export]]
Rcpp::DataFrame getAll(const std::string & path = ".") {

    const struct conf *c;
    size_t clen;
    long int value;
    char *cvalue;

    std::vector<std::string> vname, vvalue, vtype;
    char buf[256];

    for (c = vars; c->name != NULL; ++c) {
        //printf("%-35s", c->name);
        vname.push_back(std::string(c->name).c_str());
        snprintf(buf, 1, "%s", "");   // fallback
        switch (c->calltype) {
        case PATHCONF:
            value = pathconf (path.c_str(), c->call_name);
            if (value != -1) {
                snprintf(buf, 255, "%ld", value);
            }
            vtype.push_back("path");
            break;
        case SYSCONF:
            value = sysconf (c->call_name);
            if (value == -1l) {
#if defined(_SC_UINT_MAX) && defined(_SC_ULONG_MAX)
                if (c->call_name == _SC_UINT_MAX || c->call_name == _SC_ULONG_MAX)
                    snprintf(buf, 255, "%lu", value);
#endif
            } else {
                snprintf(buf, 255, "%ld", value);
            }
            vtype.push_back("sys");
            break;
        case CONFSTR:
            clen = confstr (c->call_name, (char *) NULL, 0);
            cvalue = R_alloc(clen, sizeof(char));
            if (cvalue == NULL) {
                Rcpp::stop("Memory allocation error");
            }
            if (confstr (c->call_name, cvalue, clen) != clen) {
                Rcpp::stop("Confstr error");
            }
            snprintf(buf, 255, "%.*s", (int) clen, cvalue);
            vtype.push_back("conf");
            break;
        }
        vvalue.push_back(buf);
    }
    return Rcpp::DataFrame::create(Rcpp::Named("key") = vname,
                                   Rcpp::Named("value") = vvalue,
                                   Rcpp::Named("type") = vtype);
}
开发者ID:cran,项目名称:RcppGetconf,代码行数:74,代码来源:getconf.cpp


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