本文整理汇总了C++中IsPathSeparator函数的典型用法代码示例。如果您正苦于以下问题:C++ IsPathSeparator函数的具体用法?C++ IsPathSeparator怎么用?C++ IsPathSeparator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsPathSeparator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tree_cwd
/*
* Change to specified directory
*/
TREE_NODE *tree_cwd(char *path, TREE_ROOT *root, TREE_NODE *node)
{
if (path[0] == '.' && path[1] == '\0') {
return node;
}
/*
* Handle relative path
*/
if (path[0] == '.' && path[1] == '.' && (IsPathSeparator(path[2]) || path[2] == '\0')) {
TREE_NODE *parent = node->parent ? node->parent : node;
if (path[2] == 0) {
return parent;
} else {
return tree_cwd(path+3, root, parent);
}
}
if (IsPathSeparator(path[0])) {
Dmsg0(100, "Doing absolute lookup.\n");
return tree_relcwd(path+1, root, (TREE_NODE *)root);
}
Dmsg0(100, "Doing relative lookup.\n");
return tree_relcwd(path, root, node);
}
示例2: memset
// Removes any redundant separators that might be in the pathname.
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
// redundancies that might be in a pathname involving "." or "..".
// TODO([email protected]): handle Windows network shares (e.g. \\server\share).
void FilePath::Normalize() {
if (pathname_.c_str() == NULL) {
pathname_ = "";
return;
}
const char* src = pathname_.c_str();
char* const dest = new char[pathname_.length() + 1];
char* dest_ptr = dest;
memset(dest_ptr, 0, pathname_.length() + 1);
while (*src != '\0') {
*dest_ptr = *src;
if (!IsPathSeparator(*src)) {
src++;
} else {
#if GTEST_HAS_ALT_PATH_SEP_
if (*dest_ptr == kAlternatePathSeparator) {
*dest_ptr = kPathSeparator;
}
#endif
while (IsPathSeparator(*src))
src++;
}
dest_ptr++;
}
*dest_ptr = '\0';
pathname_ = dest;
delete[] dest;
}
示例3: tree_getpath_item
static void tree_getpath_item(TREE_NODE *node, POOLMEM **path)
{
if (!node) {
return;
}
tree_getpath_item(node->parent, path);
/*
* Fixup for Win32. If we have a Win32 directory and
* there is only a / in the buffer, remove it since
* win32 names don't generally start with /
*/
if (node->type == TN_DIR_NLS && IsPathSeparator((*path[0])) && (*path)[1] == '\0') {
pm_strcpy(path, "");
}
pm_strcat(path, node->fname);
/*
* Add a slash for all directories unless we are at the root,
* also add a slash to a soft linked file if it has children
* i.e. it is linked to a directory.
*/
if ((node->type != TN_FILE && !(IsPathSeparator((*path)[0]) && (*path)[1] == '\0')) ||
(node->soft_link && tree_node_has_child(node))) {
pm_strcat(path, "/");
}
}
示例4: do_strip
/*
* Do in place strip of path
*/
static bool do_strip(int count, char *in)
{
char *out = in;
int stripped;
int numsep = 0;
/* Copy to first path separator -- Win32 might have c: ... */
while (*in && !IsPathSeparator(*in)) {
out++; in++;
}
out++; in++;
numsep++; /* one separator seen */
for (stripped=0; stripped<count && *in; stripped++) {
while (*in && !IsPathSeparator(*in)) {
in++; /* skip chars */
}
if (*in) {
numsep++; /* count separators seen */
in++; /* skip separator */
}
}
/* Copy to end */
while (*in) { /* copy to end */
if (IsPathSeparator(*in)) {
numsep++;
}
*out++ = *in++;
}
*out = 0;
Dmsg4(500, "stripped=%d count=%d numsep=%d sep>count=%d\n",
stripped, count, numsep, numsep>count);
return stripped==count && numsep>count;
}
示例5: IsPathSeparator
// Returns true if pathname describes an absolute path.
bool FilePath::IsAbsolutePath() const {
const char* const name = pathname_.c_str();
#if GTEST_OS_WINDOWS
return pathname_.length() >= 3 &&
((name[0] >= 'a' && name[0] <= 'z') ||
(name[0] >= 'A' && name[0] <= 'Z')) &&
name[1] == ':' &&
IsPathSeparator(name[2]);
#else
return IsPathSeparator(name[0]);
#endif
}
示例6: split_path_and_file
/*
* Given a full filename, split it into its path
* and filename parts. They are returned in pool memory
* in the mdb structure.
*/
void split_path_and_file(JCR *jcr, B_DB *mdb, const char *fname)
{
const char *p, *f;
/* Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
* must be a path name (e.g. c:).
*/
for (p=f=fname; *p; p++) {
if (IsPathSeparator(*p)) {
f = p; /* set pos of last slash */
}
}
if (IsPathSeparator(*f)) { /* did we find a slash? */
f++; /* yes, point to filename */
} else {
f = p; /* no, whole thing must be path name */
}
/* If filename doesn't exist (i.e. root directory), we
* simply create a blank name consisting of a single
* space. This makes handling zero length filenames
* easier.
*/
mdb->fnl = p - f;
if (mdb->fnl > 0) {
mdb->fname = check_pool_memory_size(mdb->fname, mdb->fnl+1);
memcpy(mdb->fname, f, mdb->fnl); /* copy filename */
mdb->fname[mdb->fnl] = 0;
} else {
mdb->fname[0] = 0;
mdb->fnl = 0;
}
mdb->pnl = f - fname;
if (mdb->pnl > 0) {
mdb->path = check_pool_memory_size(mdb->path, mdb->pnl+1);
memcpy(mdb->path, fname, mdb->pnl);
mdb->path[mdb->pnl] = 0;
} else {
Mmsg1(&mdb->errmsg, _("Path length is zero. File=%s\n"), fname);
Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg);
mdb->path[0] = 0;
mdb->pnl = 0;
}
Dmsg2(500, "split path=%s file=%s\n", mdb->path, mdb->fname);
}
示例7: getPath
char *
getPath(
const char *pszFullPath
)
{
char szDrive[_MAX_DRIVE];
char szDir[_MAX_DIR];
char *szPath;
char *pszSlash;
// Separate the components of the fullpath
_splitpath(pszFullPath, szDrive, szDir, NULL, NULL);
// Allocate just enough memory to hold the drive/path combo then
// Glue just the drive and dir component back together.
szPath = (char *) rallocate(_tcslen(szDrive) + _tcslen(szDir) + 1);
_makepath(szPath, szDrive, szDir, NULL, NULL);
// Eliminate the trailing slash/blackslash to retain compatibility with
// the older version of getPath()
pszSlash = szPath + _tcslen(szPath) - 1;
if (IsPathSeparator(*pszSlash)) {
*pszSlash = '\0';
}
return szPath;
}
示例8: find_config_file
/*
* Returns false on error
* true on OK, with full_path set to where config file should be
*/
static bool
find_config_file(const char *config_file, char *full_path, int max_path)
{
int file_length = strlen(config_file) + 1;
/* If a full path specified, use it */
if (first_path_separator(config_file) != NULL) {
if (file_length > max_path) {
return false;
}
bstrncpy(full_path, config_file, file_length);
return true;
}
/* config_file is default file name, now find default dir */
const char *config_dir = get_default_configdir();
int dir_length = strlen(config_dir);
if ((dir_length + 1 + file_length) > max_path) {
return false;
}
memcpy(full_path, config_dir, dir_length + 1);
if (!IsPathSeparator(full_path[dir_length - 1])) {
full_path[dir_length++] = '/';
}
memcpy(&full_path[dir_length], config_file, file_length);
return true;
}
示例9: split_path_and_filename
static void split_path_and_filename(UAContext *ua, RESTORE_CTX *rx, char *name)
{
char *p, *f;
/* Find path without the filename.
* I.e. everything after the last / is a "filename".
* OK, maybe it is a directory name, but we treat it like
* a filename. If we don't find a / then the whole name
* must be a path name (e.g. c:).
*/
for (p=f=name; *p; p++) {
if (IsPathSeparator(*p)) {
f = p; /* set pos of last slash */
}
}
if (IsPathSeparator(*f)) { /* did we find a slash? */
f++; /* yes, point to filename */
} else { /* no, whole thing must be path name */
f = p;
}
/* If filename doesn't exist (i.e. root directory), we
* simply create a blank name consisting of a single
* space. This makes handling zero length filenames
* easier.
*/
rx->fnl = p - f;
if (rx->fnl > 0) {
rx->fname = check_pool_memory_size(rx->fname, 2*(rx->fnl)+1);
db_escape_string(ua->jcr, ua->db, rx->fname, f, rx->fnl);
} else {
rx->fname[0] = 0;
rx->fnl = 0;
}
rx->pnl = f - name;
if (rx->pnl > 0) {
rx->path = check_pool_memory_size(rx->path, 2*(rx->pnl)+1);
db_escape_string(ua->jcr, ua->db, rx->path, name, rx->pnl);
} else {
rx->path[0] = 0;
rx->pnl = 0;
}
Dmsg2(100, "split path=%s file=%s\n", rx->path, rx->fname);
}
示例10: archive_name
/*
* Open a device.
*/
void DEVICE::open_device(DCR *dcr, int omode)
{
POOL_MEM archive_name(PM_FNAME);
get_autochanger_loaded_slot(dcr);
/*
* Handle opening of File Archive (not a tape)
*/
pm_strcpy(archive_name, dev_name);
/*
* If this is a virtual autochanger (i.e. changer_res != NULL) we simply use
* the device name, assuming it has been appropriately setup by the "autochanger".
*/
if (!device->changer_res || device->changer_command[0] == 0) {
if (VolCatInfo.VolCatName[0] == 0) {
Mmsg(errmsg, _("Could not open file device %s. No Volume name given.\n"),
print_name());
clear_opened();
return;
}
if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) {
pm_strcat(archive_name, "/");
}
pm_strcat(archive_name, getVolCatName());
}
mount(dcr, 1); /* do mount if required */
open_mode = omode;
set_mode(omode);
/*
* If creating file, give 0640 permissions
*/
Dmsg3(100, "open disk: mode=%s open(%s, 0x%x, 0640)\n", mode_to_str(omode),
archive_name.c_str(), oflags);
if ((m_fd = d_open(archive_name.c_str(), oflags, 0640)) < 0) {
berrno be;
dev_errno = errno;
Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(),
be.bstrerror());
Dmsg1(100, "open failed: %s", errmsg);
}
if (m_fd >= 0) {
dev_errno = 0;
file = 0;
file_addr = 0;
}
Dmsg1(100, "open dev: disk fd=%d opened\n", m_fd);
}
示例11: IsAbsolutePath
// Returns true if pathname describes a root directory. (Windows has one
// root directory per disk drive.)
bool FilePath::IsRootDirectory() const {
#if GTEST_OS_WINDOWS
// TODO([email protected]): on Windows a network share like
// \\server\share can be a root directory, although it cannot be the
// current directory. Handle this properly.
return pathname_.length() == 3 && IsAbsolutePath();
#else
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
#endif
}
示例12: p
std::string FileSystemAbstraction::RemoveLocalPathPrefix(const std::string& path)
{
std::string p(path);
if ((p.length() >= 2) && (p[0] == '.') && IsPathSeparator(p[1])) {
p.erase(0, 2);
}
return p;
}
示例13: EZ_ENABLED
bool ezPathUtils::IsAbsolutePath(const char* szPath)
{
if (ezStringUtils::IsNullOrEmpty (szPath))
return false;
// szPath[0] will not be \0 -> so we can access szPath[1] without problems
#if EZ_ENABLED(EZ_PLATFORM_WINDOWS)
/// if it is an absolute path, character 0 must be ASCII (A - Z)
/// checks for local paths, i.e. 'C:\stuff' and UNC paths, i.e. '\\server\stuff'
/// not sure if we should handle '//' identical to '\\' (currently we do)
return ((szPath[1] == ':') || (IsPathSeparator(szPath[0]) && IsPathSeparator(szPath[1])));
#elif EZ_ENABLED(EZ_PLATFORM_LINUX)
return (szPath[0] == '/');
#elif EZ_ENABLED(EZ_PLATFORM_OSX)
return (szPath[0] == '/');
#else
#error Unknown platform.
#endif
}
示例14: load_plugins
/*
* Load all the plugins in the specified directory.
* Or when plugin_names is give it has a list of plugins
* to load from the specified directory.
*/
bool load_plugins(void *binfo,
void *bfuncs,
alist *plugin_list,
const char *plugin_dir,
alist *plugin_names,
const char *type,
bool is_plugin_compatible(Plugin *plugin))
{
struct stat statp;
bool found = false;
POOL_MEM fname(PM_FNAME);
bool need_slash = false;
int len;
Dmsg0(dbglvl, "load_plugins\n");
len = strlen(plugin_dir);
if (len > 0) {
need_slash = !IsPathSeparator(plugin_dir[len - 1]);
}
/*
* See if we are loading certain plugins only or all plugins of a certain type.
*/
if (plugin_names && plugin_names->size()) {
char *name;
POOL_MEM plugin_name(PM_FNAME);
foreach_alist(name, plugin_names) {
/*
* Generate the plugin name e.g. <name>-<daemon>.so
*/
Mmsg(plugin_name, "%s%s", name, type);
/*
* Generate the full pathname to the plugin to load.
*/
Mmsg(fname, "%s%s%s", plugin_dir, (need_slash) ? "/" : "", plugin_name.c_str());
/*
* Make sure the plugin exists and is a regular file.
*/
if (lstat(fname.c_str(), &statp) != 0 || !S_ISREG(statp.st_mode)) {
continue;
}
/*
* Try to load the plugin and resolve the wanted symbols.
*/
if (load_a_plugin(binfo, bfuncs, fname.c_str(), plugin_name.c_str(), type,
plugin_list, is_plugin_compatible)) {
found = true;
}
}
示例15: strip_double_slashes
static void strip_double_slashes(char *fname)
{
char *p = fname;
while (p && *p) {
p = strpbrk(p, "/\\");
if (p != NULL) {
if (IsPathSeparator(p[1])) {
strcpy(p, p+1);
}
p++;
}
}
}