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

C++ pathconf函数代码示例

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

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



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


示例16: load_plugins

static int load_plugins(void)
{
	const char *fsdir = getenv("FSIMAGE_FSDIR");
	struct dirent *dp = NULL;
	struct dirent *dpp;
	DIR *dir = NULL;
	char *tmp = NULL;
	size_t name_max;
	int err;
	int ret = -1;

	if (fsdir == NULL)
		fsdir = FSIMAGE_FSDIR;

	if ((name_max = pathconf(fsdir, _PC_NAME_MAX)) == -1)
		goto fail;

	if ((tmp = malloc(name_max + 1)) == NULL)
		goto fail;

	if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
		goto fail;

	if ((dir = opendir(fsdir)) == NULL)
		goto fail;

	bzero(dp, sizeof (struct dirent) + name_max + 1);

	while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
		if (strcmp(dpp->d_name, ".") == 0)
			continue;
		if (strcmp(dpp->d_name, "..") == 0)
			continue;

		(void) snprintf(tmp, name_max, "%s/%s/fsimage.so", fsdir,
			dpp->d_name);

		if (init_plugin(tmp) != 0)
			goto fail;
	}

	ret = 0;

fail:
	err = errno;
	if (dir != NULL)
		(void) closedir(dir);
	free(tmp);
	free(dp);
	errno = err;
	return (ret);
}
开发者ID:0day-ci,项目名称:xen,代码行数:52,代码来源:fsimage_plugin.c


示例17: uv_fs_readlink

int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
    uv_fs_cb cb) {
  ssize_t size;
  int status;
  char* buf;

  status = -1;

  uv_fs_req_init(loop, req, UV_FS_READLINK, path, cb);

  if (cb) {
    if ((req->eio = eio_readlink(path, EIO_PRI_DEFAULT, uv__fs_after, req))) {
      uv_ref(loop);
      return 0;
    } else {
      uv_err_new(loop, ENOMEM);
      return -1;
    }
  } else {
    /* pathconf(_PC_PATH_MAX) may return -1 to signify that path
     * lengths have no upper limit or aren't suitable for malloc'ing.
     */
    if ((size = pathconf(path, _PC_PATH_MAX)) == -1) {
#if defined(PATH_MAX)
      size = PATH_MAX;
#else
      size = 4096;
#endif
    }

    if ((buf = malloc(size + 1)) == NULL) {
      uv_err_new(loop, ENOMEM);
      return -1;
    }

    if ((size = readlink(path, buf, size)) == -1) {
      req->errorno = errno;
      req->result = -1;
      free(buf);
    } else {
      /* Cannot conceivably fail since it shrinks the buffer. */
      buf = realloc(buf, size + 1);
      buf[size] = '\0';
      req->result = 0;
      req->ptr = buf;
    }

    return 0;
  }

  assert(0 && "unreachable");
}
开发者ID:adrienschuler,项目名称:node,代码行数:52,代码来源:fs.c


示例18: cacl_set

/*
 * Set an ACL, translates acl to ace_t when appropriate.
 */
static int
cacl_set(acl_inp *acl_inp, acl_t *aclp, int type)
{
	int error = 0;
	int acl_flavor_target;
	struct stat64 statbuf;
	int stat_error;
	int isdir;


	if (type == ACL_PATH) {
		stat_error = stat64(acl_inp->file, &statbuf);
		if (stat_error)
			return (-1);
		acl_flavor_target = pathconf(acl_inp->file, _PC_ACL_ENABLED);
	} else {
		stat_error = fstat64(acl_inp->fd, &statbuf);
		if (stat_error)
			return (-1);
		acl_flavor_target = fpathconf(acl_inp->fd, _PC_ACL_ENABLED);
	}

	/*
	 * If target returns an error or 0 from pathconf call then
	 * fall back to UFS/POSIX Draft interface.
	 * In the case of 0 we will then fail in either acl(2) or
	 * acl_translate().  We could erroneously get 0 back from
	 * a file system that is using fs_pathconf() and not answering
	 * the _PC_ACL_ENABLED question itself.
	 */
	if (acl_flavor_target == 0 || acl_flavor_target == -1)
		acl_flavor_target = _ACL_ACLENT_ENABLED;

	isdir = S_ISDIR(statbuf.st_mode);

	if ((error = acl_translate(aclp, acl_flavor_target, isdir,
	    statbuf.st_uid, statbuf.st_gid)) != 0) {
		return (error);
	}

	if (type == ACL_PATH) {
		error = acl(acl_inp->file,
		    (aclp->acl_type == ACE_T) ? ACE_SETACL : SETACL,
		    aclp->acl_cnt, aclp->acl_aclp);
	} else {
		error = facl(acl_inp->fd,
		    (aclp->acl_type == ACE_T) ? ACE_SETACL : SETACL,
		    aclp->acl_cnt, aclp->acl_aclp);
	}

	return (error);
}
开发者ID:BjoKaSH,项目名称:ZCE-CDDL-FILES,代码行数:55,代码来源:aclutils.c


示例19: check_extension

static void
check_extension (char *file, size_t filelen, char e)
{
  char *base = last_component (file);
  size_t baselen = base_len (base);
  size_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;

  if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
    {
      /* The new base name is long enough to require a pathconf check.  */
      long name_max;

      /* Temporarily modify the buffer into its parent directory name,
         invoke pathconf on the directory, and then restore the buffer.  */
      char tmp[sizeof "."];
      memcpy (tmp, base, sizeof ".");
      strcpy (base, ".");
      errno = 0;
      name_max = pathconf (file, _PC_NAME_MAX);
      if (0 <= name_max || errno == 0)
        {
          long size = baselen_max = name_max;
          if (name_max != size)
            baselen_max = SIZE_MAX;
        }
      memcpy (base, tmp, sizeof ".");
    }

  if (HAVE_DOS_FILE_NAMES && baselen_max <= 12)
    {
      /* Live within DOS's 8.3 limit.  */
      char *dot = strchr (base, '.');
      if (!dot)
        baselen_max = 8;
      else
        {
          char const *second_dot = strchr (dot + 1, '.');
          baselen_max = (second_dot
                         ? second_dot - base
                         : dot + 1 - base + 3);
        }
    }

  if (baselen_max < baselen)
    {
      baselen = file + filelen - base;
      if (baselen_max <= baselen)
        baselen = baselen_max - 1;
      base[baselen] = e;
      base[baselen + 1] = '\0';
    }
}
开发者ID:andreas-gruenbacher,项目名称:gnulib,代码行数:52,代码来源:backupfile.c


示例20: strlen

u_char *unchroot_filename(u_char *filename, const u_char *chrootdir) {
    // Chroot filename. Relative paths default to the home directory anyway, so these may be automatically
    // chrooted to the users home directory. Absolite paths are concatenated with the home directory, as they are assumed to
    // already by chrooted (and if they're not, it is an attempt to break out the chroot).
    u_char *rewrite_filename, *translated_path;
    int file_len;
    int chrootdir_len = strlen((char*) chrootdir);
    int maxpathlen;
    
    debug("%s: Request to unchroot path: %s", __FUNCTION__, filename);
    // Allocate space for new filename
    file_len = strlen((char*) filename);
    file_len += chrootdir_len;
    
    if ((char) *filename != '/')
	file_len++;	/* additional slash */
    
    rewrite_filename = xmalloc(file_len + 1);  /* for the null byte */
    
    // Chroot directory
    strlcpy((char*) rewrite_filename, (char*) chrootdir, chrootdir_len + 1);

    // Trailing slash for relative paths    
    if ((char) *filename != '/')
	strncat((char*) rewrite_filename, "/", 1); /* additional slash */

    // Actual path    
    strncat((char*) rewrite_filename, (char*) filename, (file_len - chrootdir_len));

    // Validate with realpath
    maxpathlen = pathconf("/", _PC_PATH_MAX);
    maxpathlen++;
    translated_path = xmalloc(maxpathlen + 1);
    
    realpath((char*) rewrite_filename, (char*) translated_path);
    free(rewrite_filename);
    
    // Verify translated path is within chroot path
    if ((void*) strstr((char*) translated_path, (char*) chrootdir) != (void*) translated_path) {
	// Path has fallen outside translated path, rewrite to home directory
	debug("%s: Path escapes chroot root path. Defaulting to chroot root path", __FUNCTION__);
	free(translated_path);
	translated_path = (u_char*) chrootdir;
    }
    
    // Replace original with new
    xfree(filename);
    filename = translated_path;
    debug("%s: Unchrooted path: %s", __FUNCTION__, filename);
    
    return filename;
}
开发者ID:spaulg,项目名称:sftp-chroot,代码行数:52,代码来源:unchroot_packets.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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