コード例 #1
0
ファイル: file_util.c プロジェクト: pvons/wireshark
/**
 * g_stat:
 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
 * @buf: a pointer to a <structname>stat</structname> struct, which
 *    will be filled with the file information
 *
 * A wrapper for the POSIX stat() function. The stat() function
 * returns information about a file.
 *
 * See the C library manual for more details about stat().
 *
 * Returns: 0 if the information was successfully retrieved, -1 if an error
 *    occurred
 *
 * Since: 2.6
 */
int
ws_stdio_stat64 (const gchar *filename,
	ws_statb64 *buf)
{
      wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
      int retval;
      int save_errno;
      size_t len;

      if (wfilename == NULL)
	{
	  errno = EINVAL;
	  return -1;
	}

      len = wcslen (wfilename);
      while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
	len--;
      if (len > 0 &&
	  (!g_path_is_absolute (filename) || len > (size_t) (g_path_skip_root (filename) - filename)))
	wfilename[len] = '\0';

      retval = _wstati64 (wfilename, buf);
      save_errno = errno;

      g_free (wfilename);

      errno = save_errno;
      return retval;
}
コード例 #2
0
ファイル: gstdio.c プロジェクト: 01org/android-bluez-glib
/**
 * g_stat:
 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
 * @buf: a pointer to a <structname>stat</structname> struct, which
 *    will be filled with the file information
 *
 * A wrapper for the POSIX stat() function. The stat() function
 * returns information about a file. On Windows the stat() function in
 * the C library checks only the FAT-style READONLY attribute and does
 * not look at the ACL at all. Thus on Windows the protection bits in
 * the st_mode field are a fabrication of little use.
 *
 * On Windows the Microsoft C libraries have several variants of the
 * <structname>stat</structname> struct and stat() function with names
 * like "_stat", "_stat32", "_stat32i64" and "_stat64i32". The one
 * used here is for 32-bit code the one with 32-bit size and time
 * fields, specifically called "_stat32".
 *
 * In Microsoft's compiler, by default "struct stat" means one with
 * 64-bit time fields while in MinGW "struct stat" is the legacy one
 * with 32-bit fields. To hopefully clear up this messs, the gstdio.h
 * header defines a type GStatBuf which is the appropriate struct type
 * depending on the platform and/or compiler being used. On POSIX it
 * is just "struct stat", but note that even on POSIX platforms,
 * "stat" might be a macro.
 *
 * See your C library manual for more details about stat().
 *
 * Returns: 0 if the information was successfully retrieved, -1 if an error
 *    occurred
 *
 * Since: 2.6
 */
int
g_stat (const gchar *filename,
        GStatBuf    *buf)
{
#ifdef G_OS_WIN32
    wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
    int retval;
    int save_errno;
    int len;

    if (wfilename == NULL)
    {
        errno = EINVAL;
        return -1;
    }

    len = wcslen (wfilename);
    while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
        len--;
    if (len > 0 &&
            (!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename))
        wfilename[len] = '\0';

    retval = _wstat (wfilename, buf);
    save_errno = errno;

    g_free (wfilename);

    errno = save_errno;
    return retval;
#else
    return stat (filename, buf);
#endif
}
コード例 #3
0
ファイル: m_file.c プロジェクト: camgunz/d2k
char* M_StripAbsolutePath(const char *path) {
  const gchar *no_root = g_path_skip_root(path);

  if (no_root != NULL && *no_root == '0')
    return NULL;

  return strdup(no_root);
}
コード例 #4
0
ファイル: gfileutils.c プロジェクト: thewb/mokoiax
/**
 * g_mkdir_with_parents:
 * @pathname: a pathname in the GLib file name encoding
 * @mode: permissions to use for newly created directories
 *
 * Create a directory if it doesn't already exist. Create intermediate
 * parent directories as needed, too.
 *
 * Returns: 0 if the directory already exists, or was successfully
 * created. Returns -1 if an error occurred, with errno set.
 *
 * Since: 2.8
 */
int
g_mkdir_with_parents (const gchar *pathname,
		      int          mode)
{
  gchar *fn, *p;

  if (pathname == NULL || *pathname == '\0')
    {
      errno = EINVAL;
      return -1;
    }

  fn = g_strdup (pathname);

  if (g_path_is_absolute (fn))
    p = (gchar *) g_path_skip_root (fn);
  else
    p = fn;

  do
    {
      while (*p && !G_IS_DIR_SEPARATOR (*p))
	p++;
      
      if (!*p)
	p = NULL;
      else
	*p = '\0';
      
      if (!g_file_test (fn, G_FILE_TEST_EXISTS))
	{
	  if (g_mkdir (fn, mode) == -1)
	    {
	      int errno_save = errno;
	      g_free (fn);
	      errno = errno_save;
	      return -1;
	    }
	}
      else if (!g_file_test (fn, G_FILE_TEST_IS_DIR))
	{
	  g_free (fn);
	  errno = ENOTDIR;
	  return -1;
	}
      if (p)
	{
	  *p++ = G_DIR_SEPARATOR;
	  while (*p && G_IS_DIR_SEPARATOR (*p))
	    p++;
	}
    }
  while (p);

  g_free (fn);

  return 0;
}
コード例 #5
0
static void
do_cd (void)
{
	char *p;

	p = arg_data [arg_cur++];

	if (!p) {
		fprintf (vfserr, "Takes a directory argument\n");
		return;
	}

	if (!g_ascii_strcasecmp (p, "..")) {
		guint lp;
		char **tmp;
		GString *newp = g_string_new ("");
		const char *ptr = g_path_skip_root (cur_dir);

		g_string_append_len (newp, cur_dir, ptr - cur_dir);

		tmp = g_strsplit_set (ptr, DIR_SEPARATORS, -1);
		lp  = 0;
		if (!tmp [lp])
			return;

		while (tmp [lp + 1] && strlen (tmp [lp + 1]) > 0) {
			g_string_append_printf (newp, "%s" G_DIR_SEPARATOR_S, tmp [lp]);
			lp++;
		}
		cur_dir = newp->str;
		g_string_free (newp, FALSE);
	} else if (!g_ascii_strcasecmp (p, ".")) {
	} else {
		char *newpath;

		if (g_path_is_absolute (p)) {
			if (!G_IS_DIR_SEPARATOR (p [strlen (p) - 1]))
				newpath = g_strconcat (p, G_DIR_SEPARATOR_S, NULL);
			else
				newpath = g_strdup (p);
		} else {
			char *ptr;
			
			ptr = get_regexp_name (p, cur_dir, TRUE);
			if (!ptr) {
				fprintf (vfserr, "Can't find '%s'\n", p);
				return;
			}

			newpath = g_strconcat (cur_dir, ptr, G_DIR_SEPARATOR_S, NULL);
		}

		if (validate_path (newpath)) {
			cur_dir = newpath;
		} else
			fprintf (vfserr, "Invalid path %s\n", newpath);
	}
}
コード例 #6
0
ファイル: gproject-utils.c プロジェクト: JJ77/geany-plugins
static gchar *relpath(const gchar *origin_dir, const gchar *dest_dir)
{
	gchar *origin, *dest;
	gchar **originv, **destv;
	gchar *ret = NULL;
	guint i, j;

	origin = tm_get_real_path(origin_dir);
	dest = tm_get_real_path(dest_dir);

	if (EMPTY(origin) || EMPTY(dest) || origin[0] != dest[0])
	{
		g_free(origin);
		g_free(dest);
		return NULL;
	}

	originv = g_strsplit_set(g_path_skip_root(origin), "/\\", -1);
	destv = g_strsplit_set(g_path_skip_root(dest), "/\\", -1);

	for (i = 0; originv[i] != NULL && destv[i] != NULL; i++)
		if (g_strcmp0(originv[i], destv[i]) != 0)
			break;

	ret = g_strdup("");

	for (j = i; originv[j] != NULL; j++)
		setptr(ret, g_build_filename(ret, "..", NULL));

	for (j = i; destv[j] != NULL; j++)
		setptr(ret, g_build_filename(ret, destv[j], NULL));

	if (strlen(ret) == 0)
		setptr(ret, g_strdup("./"));

	g_free(origin);
	g_free(dest);
	g_strfreev(originv);
	g_strfreev(destv);

	return ret;
}
コード例 #7
0
ファイル: saveactions.c プロジェクト: Acidburn0zzz/geany
static gchar *backupcopy_skip_root(gchar *filename)
{
	/* first skip the root (e.g. c:\ on windows) */
	const gchar *dir = g_path_skip_root(filename);

	/* if this has failed, use the filename again */
	if (dir == NULL)
		dir = filename;
	/* check again for leading / or \ */
	while (*dir == G_DIR_SEPARATOR)
		dir++;

	return (gchar *) dir;
}
コード例 #8
0
ファイル: IconGtk.cpp プロジェクト: cheekiatng/webkit
// FIXME: Move the code to ChromeClient::iconForFiles().
PassRefPtr<Icon> Icon::createIconForFiles(const Vector<String>& filenames)
{
    if (filenames.isEmpty())
        return 0;

    if (filenames.size() == 1) {
        if (!g_path_skip_root(filenames[0].utf8().data()))
            return 0;

        String MIMEType = MIMETypeRegistry::getMIMETypeForPath(filenames[0]);
        String iconName = lookupIconName(MIMEType);

        RefPtr<Icon> icon = adoptRef(new Icon);
        icon->m_icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), iconName.utf8().data(), 16, GTK_ICON_LOOKUP_USE_BUILTIN, 0);
        if (!icon->m_icon)
            return 0;
        return icon.release();
    }

    //FIXME: Implement this
    return 0;
}
コード例 #9
0
ファイル: gstdio.c プロジェクト: endlessm/glib
static int
_g_win32_stat_utf8 (const gchar       *filename,
                    GWin32PrivateStat *buf,
                    gboolean           for_symlink)
{
  wchar_t *wfilename;
  int result;
  gsize len;

  if (filename == NULL)
    {
      errno = EINVAL;
      return -1;
    }

  len = strlen (filename);

  while (len > 0 && G_IS_DIR_SEPARATOR (filename[len - 1]))
    len--;

  if (len <= 0 ||
      (g_path_is_absolute (filename) && len <= g_path_skip_root (filename) - filename))
    len = strlen (filename);

  wfilename = g_utf8_to_utf16 (filename, len, NULL, NULL, NULL);

  if (wfilename == NULL)
    {
      errno = EINVAL;
      return -1;
    }

  result = _g_win32_stat_utf16_no_trailing_slashes (wfilename, -1, buf, for_symlink);

  g_free (wfilename);

  return result;
}
コード例 #10
0
ファイル: m_file.c プロジェクト: camgunz/d2k
bool M_IsRootFolder(const char *path) {
  const gchar *no_root = g_path_skip_root(path);

  return (no_root != NULL && *no_root == '0');
}
コード例 #11
0
static VALUE
rg_s_path_skip_root(G_GNUC_UNUSED VALUE self, VALUE fname)
{
    return CSTR2RVAL(g_path_skip_root(RVAL2CSTR(fname)));
}