Exemple #1
0
/**
 * Get the path to the config directory.
 *
 * @param config_home_out Path to configuration directory.
 * @return NSERROR_OK on sucess and \a config_home_out updated else error code.
 */
static nserror get_config_home(char **config_home_out)
{
	nserror ret;
	char *home_dir;
	char *xdg_config_dir;
	char *config_home;

	home_dir = getenv("HOME");

	/* The old $HOME/.netsurf/ directory should be used if it
	 * exists and is accessible.
	 */
	if (home_dir != NULL) {
		ret = check_dirname(home_dir, ".netsurf", &config_home);
		if (ret == NSERROR_OK) {
			LOG("\"%s\"", config_home);
			*config_home_out = config_home;
			return ret;
		}
	}

	/* $XDG_CONFIG_HOME defines the base directory
	 * relative to which user specific configuration files
	 * should be stored.
	 */
	xdg_config_dir = getenv("XDG_CONFIG_HOME");

	if ((xdg_config_dir == NULL) || (*xdg_config_dir == 0)) {
		/* If $XDG_CONFIG_HOME is either not set or empty, a
		 * default equal to $HOME/.config should be used.
		 */

		/** @todo the meaning of empty is never defined so I
		 * am assuming it is a zero length string but is it
		 * supposed to mean "whitespace" and if so what counts
		 * as whitespace? (are tabs etc. counted or should
		 * isspace() be used)
		 */

		/* the HOME envvar is required */
		if (home_dir == NULL) {
			return NSERROR_NOT_DIRECTORY;
		}

		ret = check_dirname(home_dir, ".config/netsurf", &config_home);
		if (ret != NSERROR_OK) {
			return ret;
		}
	} else {
		ret = check_dirname(xdg_config_dir, "netsurf", &config_home);
		if (ret != NSERROR_OK) {
			return ret;
		}
	}

	LOG("\"%s\"", config_home);

	*config_home_out = config_home;
	return NSERROR_OK;
}
Exemple #2
0
/*
 *  call-seq:
 *     Dir.delete( string ) => 0
 *     Dir.rmdir( string ) => 0
 *     Dir.unlink( string ) => 0
 *
 *  Deletes the named directory. Raises a subclass of
 *  <code>SystemCallError</code> if the directory isn't empty.
 */
static VALUE
dir_s_rmdir(VALUE obj, VALUE dir)
{
    check_dirname(&dir);
    if (rmdir(RSTRING_PTR(dir)) < 0)
	rb_sys_fail(RSTRING_PTR(dir));

    return INT2FIX(0);
}
Exemple #3
0
/**
 * Get the path to the cache directory.
 *
 * @param cache_home_out Path to cache directory.
 * @return NSERROR_OK on sucess and \a cache_home_out updated else error code.
 */
static nserror get_cache_home(char **cache_home_out)
{
	nserror ret;
	char *xdg_cache_dir;
	char *cache_home;
	char *home_dir;

	/* $XDG_CACHE_HOME defines the base directory relative to
	 * which user specific non-essential data files should be
	 * stored.
	 */
	xdg_cache_dir = getenv("XDG_CACHE_HOME");

	if ((xdg_cache_dir == NULL) || (*xdg_cache_dir == 0)) {
		/* If $XDG_CACHE_HOME is either not set or empty, a
		 * default equal to $HOME/.cache should be used.
		 */

		home_dir = getenv("HOME");

		/* the HOME envvar is required */
		if (home_dir == NULL) {
			return NSERROR_NOT_DIRECTORY;
		}

		ret = check_dirname(home_dir, ".cache/netsurf", &cache_home);
		if (ret != NSERROR_OK) {
			return ret;
		}
	} else {
		ret = check_dirname(xdg_cache_dir, "netsurf", &cache_home);
		if (ret != NSERROR_OK) {
			return ret;
		}
	}

	LOG("\"%s\"", cache_home);

	*cache_home_out = cache_home;
	return NSERROR_OK;
}
Exemple #4
0
/*
 *  call-seq:
 *     Dir.chroot( string ) => 0
 *
 *  Changes this process's idea of the file system root. Only a
 *  privileged process may make this call. Not available on all
 *  platforms. On Unix systems, see <code>chroot(2)</code> for more
 *  information.
 */
static VALUE
dir_s_chroot(VALUE dir, VALUE path)
{
#if defined(HAVE_CHROOT) && !defined(__CHECKER__)
    check_dirname(&path);

    if (chroot(RSTRING_PTR(path)) == -1)
	rb_sys_fail(RSTRING_PTR(path));

    return INT2FIX(0);
#else
    rb_notimplement();
    return Qnil;		/* not reached */
#endif
}
Exemple #5
0
/*
 *  call-seq:
 *     Dir.mkdir( string [, integer] ) => 0
 *
 *  Makes a new directory named by <i>string</i>, with permissions
 *  specified by the optional parameter <i>anInteger</i>. The
 *  permissions may be modified by the value of
 *  <code>File::umask</code>, and are ignored on NT. Raises a
 *  <code>SystemCallError</code> if the directory cannot be created. See
 *  also the discussion of permissions in the class documentation for
 *  <code>File</code>.
 *
 */
static VALUE
dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
{
    VALUE path, vmode;
    int mode;

    if (rb_scan_args(argc, argv, "11", &path, &vmode) == 2) {
	mode = NUM2INT(vmode);
    }
    else {
	mode = 0777;
    }

    check_dirname(&path);
    if (mkdir(RSTRING_PTR(path), mode) == -1)
	rb_sys_fail(RSTRING_PTR(path));

    return INT2FIX(0);
}
/**
 * Unit test for dbus-sysdeps.c.
 * 
 * @returns #TRUE on success.
 */
dbus_bool_t
_dbus_sysdeps_test (void)
{
  DBusString str;
  double val;
  int pos;

#ifdef DBUS_WIN
  check_dirname ("foo\\bar", "foo");
  check_dirname ("foo\\\\bar", "foo");
  check_dirname ("foo/\\/bar", "foo");
  check_dirname ("foo\\bar/", "foo");
  check_dirname ("foo//bar\\", "foo");
  check_dirname ("foo\\bar/", "foo");
  check_dirname ("foo/bar\\\\", "foo");
  check_dirname ("\\foo", "\\");
  check_dirname ("\\\\foo", "\\");
  check_dirname ("\\", "\\");
  check_dirname ("\\\\", "\\");
  check_dirname ("\\/", "\\");
  check_dirname ("/\\/", "/");
  check_dirname ("c:\\foo\\bar", "c:\\foo");
  check_dirname ("c:\\foo", "c:\\");
  check_dirname ("c:/foo", "c:/");
  check_dirname ("c:\\", "c:\\");
  check_dirname ("c:/", "c:/");
  check_dirname ("", ".");  
#else  
  check_dirname ("foo", ".");
  check_dirname ("foo/bar", "foo");
  check_dirname ("foo//bar", "foo");
  check_dirname ("foo///bar", "foo");
  check_dirname ("foo/bar/", "foo");
  check_dirname ("foo//bar/", "foo");
  check_dirname ("foo///bar/", "foo");
  check_dirname ("foo/bar//", "foo");
  check_dirname ("foo//bar////", "foo");
  check_dirname ("foo///bar///////", "foo");
  check_dirname ("/foo", "/");
  check_dirname ("////foo", "/");
  check_dirname ("/foo/bar", "/foo");
  check_dirname ("/foo//bar", "/foo");
  check_dirname ("/foo///bar", "/foo");
  check_dirname ("/", "/");
  check_dirname ("///", "/");
  check_dirname ("", ".");  
#endif

  _dbus_string_init_const (&str, "3.5");
  if (!_dbus_string_parse_double (&str,
				  0, &val, &pos))
    {
      _dbus_warn ("Failed to parse double");
      exit (1);
    }
  if (ABS(3.5 - val) > 1e-6)
    {
      _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
      exit (1);
    }
  if (pos != 3)
    {
      _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
      exit (1);
    }

  _dbus_string_init_const (&str, "0xff");
  if (_dbus_string_parse_double (&str,
                                 0, &val, &pos))
    {
      _dbus_warn ("Should not have parsed hex as double\n");
      exit (1);
    }

#ifdef DBUS_WIN
  check_path_absolute ("c:/", TRUE);
  check_path_absolute ("c:/foo", TRUE);
  check_path_absolute ("", FALSE);
  check_path_absolute ("foo", FALSE);
  check_path_absolute ("foo/bar", FALSE);
  check_path_absolute ("", FALSE);
  check_path_absolute ("foo\\bar", FALSE);
  check_path_absolute ("c:\\", TRUE);
  check_path_absolute ("c:\\foo", TRUE);
  check_path_absolute ("c:", TRUE);
  check_path_absolute ("c:\\foo\\bar", TRUE);
  check_path_absolute ("\\", TRUE);
  check_path_absolute ("/", TRUE);
#else  
  check_path_absolute ("/", TRUE);
  check_path_absolute ("/foo", TRUE);
  check_path_absolute ("", FALSE);
  check_path_absolute ("foo", FALSE);
  check_path_absolute ("foo/bar", FALSE);
#endif
  
  return TRUE;
}
Exemple #7
0
/* get the dirname of a path */
void test_core_path__00_dirname(void)
{
	check_dirname(NULL, ".");
	check_dirname("", ".");
	check_dirname("a", ".");
	check_dirname("/", "/");
	check_dirname("/usr", "/");
	check_dirname("/usr/", "/");
	check_dirname("/usr/lib", "/usr");
	check_dirname("/usr/lib/", "/usr");
	check_dirname("/usr/lib//", "/usr");
	check_dirname("usr/lib", "usr");
	check_dirname("usr/lib/", "usr");
	check_dirname("usr/lib//", "usr");
	check_dirname(".git/", ".");

	check_dirname(REP16("/abc"), REP15("/abc"));

#ifdef GIT_WIN32
	check_dirname("C:/", "C:/");
	check_dirname("C:", "C:/");
	check_dirname("C:/path/", "C:/");
	check_dirname("C:/path", "C:/");
	check_dirname("//computername/", "//computername/");
	check_dirname("//computername", "//computername/");
	check_dirname("//computername/path/", "//computername/");
	check_dirname("//computername/path", "//computername/");
	check_dirname("//computername/sub/path/", "//computername/sub");
	check_dirname("//computername/sub/path", "//computername/sub");
#endif
}
Exemple #8
0
/* get the dirname of a path */
void test_core_path__00_dirname(void)
{
	check_dirname(NULL, ".");
	check_dirname("", ".");
	check_dirname("a", ".");
	check_dirname("/", "/");
	check_dirname("/usr", "/");
	check_dirname("/usr/", "/");
	check_dirname("/usr/lib", "/usr");
	check_dirname("/usr/lib/", "/usr");
	check_dirname("/usr/lib//", "/usr");
	check_dirname("usr/lib", "usr");
	check_dirname("usr/lib/", "usr");
	check_dirname("usr/lib//", "usr");
	check_dirname(".git/", ".");

	check_dirname(REP16("/abc"), REP15("/abc"));
}