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


C++ canonicalize_file_name函数代码示例

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


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

示例1: AbsolutizeAndSimplifyPathname

ERRORCODE_T AbsolutizeAndSimplifyPathname(
    const char *pPathname,const char *pBaseDirectory,char **ppResolved)
{
  ERRORCODE_T ErrorCode;
  char *pLongPathname;


  DEBUGLOG_Printf5("AbsolutizeAndSimplifyPathname(%p(%s),%p(%s),%p)",
      pPathname,pPathname,pBaseDirectory,pBaseDirectory,ppResolved);
  DEBUGLOG_LogIn();

  /* Parameter checking. */
  if ( (pPathname==NULL) || (ppResolved==NULL) )
    ErrorCode=ERRORCODE_NULLPARAMETER;
  else
  {
    /* Check if the relative pathname is actually absolute. */
    if (*pPathname==DIRECTORY_SEPARATOR_CHAR)
    {
      /* Relative pathname is actually an absolute pathname. Only
          canonicalize the "relative" pathname. */
      *ppResolved=canonicalize_file_name(pPathname);
      if (*ppResolved==NULL)
        ErrorCode=ERRORCODE_SYSTEMFAILURE;
      else
        ErrorCode=ERRORCODE_SUCCESS;
    }
    else
    {
      /* Got a relative pathname. Make sure base is absolute. */
      if (pBaseDirectory==NULL)
          ErrorCode=ERRORCODE_NULLPARAMETER;
      else
      {
        /* Make sure the base pathname is absolute. */
        if (*pBaseDirectory!=DIRECTORY_SEPARATOR_CHAR)
          ErrorCode=ERRORCODE_INVALIDDATA;
        else
        {
          /* Combine directory and relative path. */
          if (asprintf(&pLongPathname,"%s/%s",pBaseDirectory,pPathname)==-1)
          {
            *ppResolved=NULL;
            ErrorCode=ERRORCODE_SYSTEMFAILURE;
          }
          else
          {
            *ppResolved=canonicalize_file_name(pLongPathname);
            free((char*)pLongPathname);
            ErrorCode=ERRORCODE_SUCCESS;
          }
        }
      }
    }
  }

  DEBUGLOG_LogOut();
  return(ErrorCode);
}
开发者ID:damentz,项目名称:moonphase,代码行数:59,代码来源:utility.c

示例2: ASSERT

bool SyscallPolicy::hasPermissionForPath(const char* path, Permission permission) const
{
    // The root directory policy needs to be set because it is the
    // ultimate fallback when rewinding directories.
    ASSERT(m_directoryPermission.contains("/"));

    if (permission == NotAllowed)
        return false;

    char* basePath = strdup(path);
    char* canonicalPath = canonicalize_file_name(basePath);

    while (canonicalPath) {
        struct stat pathStat;
        if (stat(canonicalPath, &pathStat) == -1) {
            free(basePath);
            free(canonicalPath);
            return false;
        }

        if (S_ISDIR(pathStat.st_mode))
            break;

        PermissionMap::const_iterator policy = m_filePermission.find(String(canonicalPath));
        if (policy != m_filePermission.end()) {
            free(basePath);
            free(canonicalPath);
            return (permission & policy->value) == permission;
        }

        // If not a directory neither a file with a policy defined,
        // we set canonicalPath to zero to force a rewind to the parent
        // directory.
        free(canonicalPath);
        canonicalPath = 0;
    }

    while (!canonicalPath) {
        char* currentBaseDirectory = dirname(basePath);
        canonicalPath = canonicalize_file_name(currentBaseDirectory);
    }

    PermissionMap::const_iterator policy = m_directoryPermission.find(String(canonicalPath));
    while (policy == m_directoryPermission.end()) {
        char* currentBaseDirectory = dirname(canonicalPath);
        policy = m_directoryPermission.find(String(currentBaseDirectory));
    }

    free(basePath);
    free(canonicalPath);

    if ((permission & policy->value) == permission)
        return true;

    // Don't warn if the file doesn't exist at all.
    if (!access(path, F_OK) || errno != ENOENT)
        fprintf(stderr, "Blocked impermissible %s access to %s\n", SyscallPolicy::permissionToString(permission), path);
    return false;
}
开发者ID:cheekiatng,项目名称:webkit,代码行数:59,代码来源:SyscallPolicy.cpp

示例3: equivalent

static int equivalent(const char *a, const char *b) {
        _cleanup_free_ char *x = NULL, *y = NULL;

        x = canonicalize_file_name(a);
        if (!x)
                return -errno;

        y = canonicalize_file_name(b);
        if (!y)
                return -errno;

        return path_equal(x, y);
}
开发者ID:RoadRunnr,项目名称:systemd,代码行数:13,代码来源:delta.c

示例4: eval_link

static void eval_link(char *pid, char *link_rel, enum field field, char **ptr,
    char *format_str, struct obstack *mem_pool)
{
    char *link_file, *link;
    
    /* path to the link file like. /proc/{pid}/{link_rel} */
    link_file = proc_pid_file(pid, link_rel, mem_pool);

    /* It's okay to use canonicalize_file_name instead of readlink on linux
     * for the cwd symlink, since on linux the links we care about will never
     * be relative links (cwd, exec) 
     * Doing this because readlink works on static buffers */
    link = canonicalize_file_name(link_file);

    /* we no longer need need the path to the link file */
    obstack_free(mem_pool, link_file);

    if (link == NULL)
        return;

    /* copy the path onto our obstack, set the value (somewhere in pts)
     * and free the results of canonicalize_file_name */
    obstack_printf(mem_pool, link);
    obstack_1grow(mem_pool, '\0');

    *ptr = (char *) obstack_finish(mem_pool);
    free(link);

    /* enable whatever field we successfuly retrived */
    field_enable(format_str, field);
}
开发者ID:carnil,项目名称:perl-proc-processtable,代码行数:31,代码来源:Linux.c

示例5: set_game_filename

static void set_game_filename(const char *name)
{
  n_free(game_filename);
  game_filename = 0;

#if defined(_GNU_SOURCE)
  game_filename = canonicalize_file_name(name);
#else
#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
  game_filename = (char *) n_malloc(PATH_MAX);
  if(!realpath(name, game_filename)) {
    n_free(game_filename);
    game_filename = 0;
  }
#else
#ifdef __DJGPP__
  game_filename = (char *) n_malloc(FILENAME_MAX);
  _fixpath(name, game_filename);
#endif
#endif
#endif

  if(!game_filename)
    game_filename = n_strdup(name);
}
开发者ID:sussman,项目名称:twisty,代码行数:25,代码来源:startunix.c

示例6: main

int main(int argc, char **argv) {
    struct stat buf;
    char *tpath;
    if (argc != 3) {
        fprintf(stderr, "Too few arguments. Usage: relink <symlink> <new-target>\n");
        return EXIT_FAILURE;
    }
    if (lstat(argv[1], &buf) != 0) {
        fprintf(stderr, "Can not read file: %s\n", argv[1]);
        return EXIT_FAILURE;
    }
    if (access(argv[2], F_OK) != 0) {
        fprintf(stderr, "Can not symlink to a non-existent file: %s\n", argv[2]);
        return EXIT_FAILURE;
    }
    if (S_ISLNK(buf.st_mode) == 0) {
        fprintf(stderr, "Can not relink a non-symlink: %s\n", argv[1]);
        return EXIT_FAILURE;
    }
    if (unlink(argv[1]) != 0) {
        fprintf(stderr, "Could not unlink symlink: %s\n", argv[1]);
        return EXIT_FAILURE;
    }
    if ((tpath = canonicalize_file_name(argv[2])) == NULL) {
        fprintf(stderr, "canonicalize_file_name() failed\n");
        return EXIT_FAILURE;
    }
    if (symlink(argv[2], tpath) != 0) {
        fprintf(stderr, "symlink() failed\n");
        free(tpath);
        return EXIT_FAILURE;
    }
    free(tpath);
    return EXIT_SUCCESS;
}
开发者ID:2ion,项目名称:scripts,代码行数:35,代码来源:relink.c

示例7: get_name

/* Return the canonical name of DIR in malloc'd storage.  */
static char *
get_name (char const *dir)
{
  char *result;
  if (REPLACE_OPEN_DIRECTORY || !HAVE_CANONICALIZE_FILE_NAME)
    {
      /* The function canonicalize_file_name has not yet been ported
         to mingw, with all its drive letter and backslash quirks.
         Fortunately, getcwd is reliable in this case, but we ensure
         we can get back to where we started before using it.  Treat
         "." as a special case, as it is frequently encountered.  */
      char *cwd = getcwd (NULL, 0);
      int saved_errno;
      if (dir[0] == '.' && dir[1] == '\0')
        return cwd;
      if (chdir (cwd))
        return NULL;
      result = chdir (dir) ? NULL : getcwd (NULL, 0);
      saved_errno = errno;
      if (chdir (cwd))
        abort ();
      free (cwd);
      errno = saved_errno;
    }
  else
    {
      /* Avoid changing the directory.  */
      result = canonicalize_file_name (dir);
    }
  return result;
}
开发者ID:dalinaum,项目名称:gnu-cpio-for-mac,代码行数:32,代码来源:fchdir.c

示例8: verify_file

int verify_file(const char *filename) {
  char *buffer = malloc(100);
  char *canonicalized_filename = malloc(100);

  /* 
    This function canonicalizes all user input. Ensure that this is used, followed by white list validation and then processing of the file.
    In this case, it will strip all the ../ characters or resolve the soft link and reveal the actual path that is used.
  */
  canonicalized_filename = canonicalize_file_name(filename);
  printf("%s\n", canonicalized_filename);

  /*
    Do validation here... before the file is actually opened. Maybe stuff like, the file needs to be opened must exist in a specific directory.
    That would result in a failed attempt to open /etc/passwd.
  */
  FILE *fd = fopen(filename, "r");
  if (fd == NULL) {
    printf("File cannot be opened\n");
  }
  else {
    fread(buffer, 2, 100, fd);
    printf("%s\n",buffer);
  }
  return 0;
}
开发者ID:arvinddoraiswamy,项目名称:Csec,代码行数:25,代码来源:fio02.c

示例9: canonicalize_file_name

void DynamoModelLoader::load(char* srcpath) {
    int status;
    char *path;

    path = canonicalize_file_name(srcpath);
    QString model_name = QString(path);
    model_name.remove(MODEL_SOURCE_SUFFIX);

    if (model_name.isNull() || model_name.isEmpty())
        return;

    if (model_makefile_path.isNull() || model_makefile_path.isEmpty()) {
        ERROR_MSG("invalid model makefile name\n");
        return;
    }

    QString cmd = QString("cd %1; %2 %3 %4%5") .arg(getcwd(NULL, 0)) .arg(
                      MAKE_CMD_PREFIX) .arg(model_makefile_path) .arg(model_name) .arg(
                      MODEL_SUFFIX);

    QString module_name = QString("%1%2") .arg(model_name) .arg(MODEL_SUFFIX);

    DEBUG_MSG("about to compile model with command %s\n", cmd.toLatin1().constData());
    status = CmdLine::getInstance()->execute(cmd.toStdString());

    if (status != 0) {
        ERROR_MSG("build process error\n");
        return;
    }

    Plugin::Manager::getInstance()->load(module_name.toLatin1());

    if (path != NULL)
        free(path);
}
开发者ID:yzerlaut,项目名称:rtxi,代码行数:35,代码来源:dynamo_model_loader.cpp

示例10: scan_playlist

static void scan_playlist(struct uade_config *uc)
{
  struct playlist_iterator pli;
  char *songfile;
  struct uade_state state = {.config = *uc};

  playlist_iterator(&pli, &uade_playlist);

  while (1) {
    songfile = playlist_iterator_get(&pli);
    if (songfile == NULL)
      break;

    if (!uade_is_our_file(songfile, 1, &state))
      continue;

    songfile = canonicalize_file_name(songfile);

    if (songfile)
      printf("%s\n", songfile);

    free(songfile);
    songfile = NULL;
  }
}
开发者ID:9a3eedi,项目名称:Droidsound,代码行数:25,代码来源:uade123.c

示例11: guess_efi_drive

static char *
guess_efi_drive (const char *orig_path)
{
  char *canon;
  char *ptr;
  canon = canonicalize_file_name (orig_path);
  if (!canon)
    return NULL;
  ptr = strrchr (orig_path, '/');
  if (ptr)
    ptr++;
  else
    ptr = canon;
  if ((ptr[0] == 's' || ptr[0] == 'h') && ptr[1] == 'd')
    {
      int num = ptr[2] - 'a';
      free (canon);
      return xasprintf ("hd%d", num);
    }
  if (ptr[0] == 'f' && ptr[1] == 'd')
    {
      int num = atoi (ptr + 2);
      free (canon);
      return xasprintf ("fd%d", num);
    }
  free (canon);
  return NULL;
}
开发者ID:jnbek,项目名称:grub2-fedora,代码行数:28,代码来源:grub-probe.c

示例12: slash

/* Sets the original and the current installation prefix of this module.
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
static char *
set_orig_prefix (const char *orig_prefix_arg)
{
      char *memory;
//	  printf ("orig_prefix_arg: %s\n", orig_prefix_arg);
	  if (!orig_prefix_arg) {
		orig_prefix = NULL;
		orig_prefix_len = 0;
		return NULL;
	  }
	  if (orig_prefix)
		  free (orig_prefix);

	  memory = canonicalize_file_name (orig_prefix_arg);
//	  printf ("memory: %s\n", memory);
//	  memory = (char *) malloc (orig_prefix_len + 1);
      if (!memory) {
	  	set_werrno;
		orig_prefix = NULL;
		orig_prefix_len = 0;
		return NULL;
      }
	  win2unixpath (memory);
//	  win2posixpath (orig_prefix_arg, memory);
	  orig_prefix = memory;
	  orig_prefix_len = strlen (orig_prefix);
//	  printf ("orig_prefix: %s\n", orig_prefix);
	  if (ISDIRSEP (orig_prefix[orig_prefix_len-1])) {
	  	orig_prefix[orig_prefix_len-1] = '\0';
	  	orig_prefix_len--;
	  }
//	  printf ("orig_prefix: %s\n", orig_prefix);
//	  printf ("orig_prefix_len: %d\n", orig_prefix_len);
	  return orig_prefix;
}
开发者ID:jkitchin,项目名称:emacs-win,代码行数:40,代码来源:relocatex.c

示例13: addRule

void SeccompFiltersWebProcessEfl::platformInitialize()
{
    // TODO: We should block all the syscalls and whitelist
    // what we need + trap what should be handled by the broker.
    addRule("open", Trap);
    addRule("openat", Trap);
    addRule("creat", Trap);

    // Needed by Eeze on NetworkStateNotifierEfl.
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/bus"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/class"), SyscallPolicy::Read);
    m_policy.addDirectoryPermission(ASCIILiteral("/sys/devices"), SyscallPolicy::Read);
    m_policy.addFilePermission(ASCIILiteral("/etc/udev/udev.conf"), SyscallPolicy::Read);

    // Place where the theme and icons are installed.
    char* dataDir = canonicalize_file_name(DATA_DIR);
    if (dataDir) {
        m_policy.addDirectoryPermission(String::fromUTF8(dataDir), SyscallPolicy::Read);
        free(dataDir);
    }

#if USE(GSTREAMER)
    // Video playback requires access to the root of the user cache dir which
    // is not right. We need to check with these directories on gstreamer
    // can be configured.
    char* homeDir = getenv("HOME");
    if (homeDir)
        m_policy.addDirectoryPermission(String::fromUTF8(homeDir) + "/.cache", SyscallPolicy::ReadAndWrite);
#endif

    SeccompBroker::launchProcess(this, m_policy);
}
开发者ID:cheekiatng,项目名称:webkit,代码行数:32,代码来源:SeccompFiltersWebProcessEfl.cpp

示例14: guess_baremetal_drive

static char *
guess_baremetal_drive (const char *orig_path)
{
  char *canon;
  char *ptr;
  canon = canonicalize_file_name (orig_path);
  if (!canon)
    return NULL;
  ptr = strrchr (orig_path, '/');
  if (ptr)
    ptr++;
  else
    ptr = canon;
  if (ptr[0] == 'h' && ptr[1] == 'd')
    {
      int num = ptr[2] - 'a';
      free (canon);
      return xasprintf ("ata%d", num);
    }
  if (ptr[0] == 's' && ptr[1] == 'd')
    {
      int num = ptr[2] - 'a';
      free (canon);
      return xasprintf ("ahci%d", num);
    }
  free (canon);
  return NULL;
}
开发者ID:jnbek,项目名称:grub2-fedora,代码行数:28,代码来源:grub-probe.c

示例15: tr_sys_path_resolve

char *
tr_sys_path_resolve (const char  * path,
                     tr_error   ** error)
{
  char * ret = NULL;
  char * tmp = NULL;

  assert (path != NULL);

#if defined (HAVE_CANONICALIZE_FILE_NAME)

  ret = canonicalize_file_name (path);

#endif

#if defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L

  /* Better safe than sorry: realpath () officially supports NULL as destination
     starting off POSIX.1-2008. */

  if (ret == NULL)
    ret = realpath (path, NULL);

#endif

  if (ret == NULL)
    {
      tmp = tr_new (char, PATH_MAX);
      ret = realpath (path, tmp);
      if (ret != NULL)
        ret = tr_strdup (ret);
    }
开发者ID:Elbandi,项目名称:transmission,代码行数:32,代码来源:file-posix.c


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