예제 #1
0
파일: pref.c 프로젝트: proudzhu/gpicview
void save_preferences()
{
    FILE* f;
    char* dir = g_build_filename( g_get_user_config_dir(), CFG_DIR, NULL );
    char* path = g_build_filename( g_get_user_config_dir(),  CFG_FILE, NULL );
    if( ! g_file_test( dir, G_FILE_TEST_IS_DIR ) )
    {
        g_mkdir( g_get_user_config_dir(), 0766 );
        g_mkdir( dir, 0766 );
    }
    g_free( dir );

    if(  (f = fopen( path, "w" )) )
    {
        fputs( "[General]\n", f );
        fprintf( f, "auto_save_rotated=%d\n", pref.auto_save_rotated );
        fprintf( f, "ask_before_save=%d\n", pref.ask_before_save );
        fprintf( f, "ask_before_delete=%d\n", pref.ask_before_delete );
        fprintf( f, "rotate_exif_only=%d\n", pref.rotate_exif_only );
        fprintf( f, "open_maximized=%d\n", pref.open_maximized );
        fprintf( f, "bg=#%02x%02x%02x\n", pref.bg.red/256, pref.bg.green/256, pref.bg.blue/256 );
        fprintf( f, "bg_full=#%02x%02x%02x\n", pref.bg_full.red/256, pref.bg_full.green/256, pref.bg_full.blue/256 );
        fprintf( f, "slide_delay=%d\n", pref.slide_delay );

        fprintf( f, "jpg_quality=%d\n", pref.jpg_quality );
        fprintf( f, "png_compression=%d\n", pref.png_compression );

        fprintf( f, "show_toolbar=%d\n", pref.show_toolbar );

        fclose( f );
    }
    g_free( path );
}
예제 #2
0
/**
 * gimp_thumb_ensure_thumb_dir:
 * @size: a GimpThumbSize
 * @error: return location for possible errors
 *
 * This function checks if the directory that is required to store
 * thumbnails for a particular @size exist and attempts to create it
 * if necessary.
 *
 * You shouldn't have to call this function directly since
 * gimp_thumbnail_save_thumb() and gimp_thumbnail_save_failure() will
 * do this for you.
 *
 * Return value: %TRUE is the directory exists, %FALSE if it could not
 *               be created
 **/
gboolean
gimp_thumb_ensure_thumb_dir (GimpThumbSize   size,
                             GError        **error)
{
  g_return_val_if_fail (gimp_thumb_initialized, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  size = gimp_thumb_size (size);

  if (g_file_test (thumb_subdirs[size], G_FILE_TEST_IS_DIR))
    return TRUE;

  if (g_file_test (thumb_dir, G_FILE_TEST_IS_DIR) ||
      (g_mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0))
    {
      if (size == 0)
        g_mkdir (thumb_fail_subdir, S_IRUSR | S_IWUSR | S_IXUSR);

      g_mkdir (thumb_subdirs[size], S_IRUSR | S_IWUSR | S_IXUSR);
    }

  if (g_file_test (thumb_subdirs[size], G_FILE_TEST_IS_DIR))
    return TRUE;

  g_set_error (error,
               GIMP_THUMB_ERROR, GIMP_THUMB_ERROR_MKDIR,
               _("Failed to create thumbnail folder '%s'."),
               thumb_subdirs[size]);

  return FALSE;
}
예제 #3
0
int
make_config_dirs (void)
{
    char *buf;

    if (g_mkdir (get_xdir (), 0700) != 0)
        return -1;

    buf = g_build_filename (get_xdir (), "addons", NULL);
    if (g_mkdir (buf, 0700) != 0)
    {
        g_free (buf);
        return -1;
    }
    g_free (buf);

    buf = g_build_filename (get_xdir (), HEXCHAT_SOUND_DIR, NULL);
    if (g_mkdir (buf, 0700) != 0)
    {
        g_free (buf);
        return -1;
    }
    g_free (buf);

    return 0;
}
예제 #4
0
void save_config_file(void)				//not called in gint main
{
	FILE *fp;
	gchar *path;
	GtkItemFactory *ifactory;			//GtkItemFactory ??
	gint width, height;
	gchar *fontname;
	gboolean wordwrap, linenumbers, autoindent;
	
	gtk_window_get_size(GTK_WINDOW(pub->mw->window), &width, &height);
	fontname = get_font_name_from_widget(pub->mw->view);
	ifactory = gtk_item_factory_from_widget(pub->mw->menubar);
	wordwrap = gtk_check_menu_item_get_active(
		GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory,
			"/Options/Word Wrap")));
	linenumbers = gtk_check_menu_item_get_active(
		GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory,
			"/Options/Line Numbers")));
	autoindent = gtk_check_menu_item_get_active(
		GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item(ifactory,
			"/Options/Auto Indent")));
										//saves the variables for conf file
#if GLIB_CHECK_VERSION(2, 6, 0)
	path = g_build_filename(g_get_user_config_dir(), PACKAGE, NULL);	//fetches the address for conf and makes a dir for first 
	if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {				//use if not present
# if GLIB_CHECK_VERSION(2, 8, 0)
		g_mkdir_with_parents(path, 0700);
# else
		g_mkdir(g_get_user_config_dir(), 0700);
		g_mkdir(path, 0700);
# endif
	}
	g_free(path);
	path = g_build_filename(g_get_user_config_dir(),
	    PACKAGE, PACKAGE "rc", NULL);
#else
	path = g_build_filename(g_get_home_dir(), "." PACKAGE, NULL);
#endif
	fp = fopen(path, "w");
	if (!fp) {
		g_print("%s: can't save config file - %s\n", PACKAGE, path);
		return;
	}
	g_free(path);
	
	fprintf(fp, "%s\n", PACKAGE_VERSION);
	fprintf(fp, "%d\n", width);
	fprintf(fp, "%d\n", height);
	fprintf(fp, "%s\n", fontname); 
	fprintf(fp, "%d\n", wordwrap);
	fprintf(fp, "%d\n", linenumbers);
	fprintf(fp, "%d\n", autoindent);
	fclose(fp);
	
	g_free(fontname);
}
예제 #5
0
int
make_dcc_dirs (void)
{
    if (g_mkdir (prefs.hex_dcc_dir, 0700) != 0)
        return -1;

    if (g_mkdir (prefs.hex_dcc_completed_dir, 0700) != 0)
        return -1;

    return 0;
}
예제 #6
0
/**
 * gimp_thumb_ensure_thumb_dir_local:
 * @dirname: the basename of the dir, without the actual dirname itself
 * @size:    a GimpThumbSize
 * @error:   return location for possible errors
 *
 * This function checks if the directory that is required to store
 * local thumbnails for a particular @size exist and attempts to
 * create it if necessary.
 *
 * You shouldn't have to call this function directly since
 * gimp_thumbnail_save_thumb_local() will do this for you.
 *
 * Return value: %TRUE is the directory exists, %FALSE if it could not
 *               be created
 *
 * Since: GIMP 2.2
 **/
gboolean
gimp_thumb_ensure_thumb_dir_local (const gchar    *dirname,
                                   GimpThumbSize   size,
                                   GError        **error)
{
  gchar *basedir;
  gchar *subdir;

  g_return_val_if_fail (gimp_thumb_initialized, FALSE);
  g_return_val_if_fail (dirname != NULL, FALSE);
  g_return_val_if_fail (g_path_is_absolute (dirname), FALSE);
  g_return_val_if_fail (size > GIMP_THUMB_SIZE_FAIL, FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  size = gimp_thumb_size (size);

  subdir = g_build_filename (dirname,
                             ".thumblocal", thumb_sizenames[size],
                             NULL);

  if (g_file_test (subdir, G_FILE_TEST_IS_DIR))
    {
      g_free (subdir);
      return TRUE;
    }

  basedir = g_build_filename (dirname, ".thumblocal", NULL);

  if (g_file_test (basedir, G_FILE_TEST_IS_DIR) ||
      (g_mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0))
    {
      g_mkdir (subdir, S_IRUSR | S_IWUSR | S_IXUSR);
    }

  g_free (basedir);

  if (g_file_test (subdir, G_FILE_TEST_IS_DIR))
    {
      g_free (subdir);
      return TRUE;
    }

  g_set_error (error,
               GIMP_THUMB_ERROR, GIMP_THUMB_ERROR_MKDIR,
               _("Failed to create thumbnail folder '%s'."),
               subdir);
  g_free (subdir);

  return FALSE;
}
예제 #7
0
파일: files.c 프로젝트: debrouxl/tiemu
int tiemu_file_mkdir(const char *pathname)
{
#ifdef __WIN32__
	if(g_mkdir(pathname, S_IRWXU) < 0)
#else
	if(g_mkdir(pathname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0)
#endif
	{
		msg_box1(_("Information"), _("Unable to create the directory.\n\n"));
		return -1;
	}

	return 0;
}
예제 #8
0
void create_dir(char *path)
{
	char dirname[256];
	char *p = path;
	char *q = dirname;

	while(*p) {
		if(('\\' == *p) || ('/' == *p)) {
			if(':' != *(p-1)) g_mkdir(dirname, 0755);
		}
		*q++ = *p++;
		*q = '\0';
	}
	g_mkdir(dirname, 0755);
}
예제 #9
0
static gboolean
ValidateEnvironment(gboolean requireRootPriv)     // IN
{
   gboolean ret = FALSE;

   if (requireRootPriv && !CheckRootPriv()) {
      Error("Current user has insufficient privileges.\n");
      goto exit;
   }

   if (!initialized) {
      CertKey_InitOpenSSLLib();
      initialized = TRUE;
   }

   if (!g_file_test(guestProxySslConf, G_FILE_TEST_IS_REGULAR)) {
      Error("Couldn't find the GuestProxy Config file at '%s'.\n",
            guestProxySslConf);
      goto exit;
   }

   /* Create guest proxy data directories on-demand */
   if (!g_file_test(guestProxyDir, G_FILE_TEST_IS_DIR)) {
      if (g_mkdir(guestProxyDir, 0755) < 0) {
         Error("Couldn't create the directory '%s'.\n", guestProxyDir);
         goto exit;
      }
   }

   if (!g_file_test(guestProxyServerDir, G_FILE_TEST_IS_DIR)) {
      if (g_mkdir(guestProxyServerDir, 0755) < 0) {
         Error("Couldn't create the directory '%s'.\n", guestProxyServerDir);
         goto exit;
      }
   }

   if (!g_file_test(guestProxyTrustedDir, G_FILE_TEST_IS_DIR)) {
      if (g_mkdir(guestProxyTrustedDir, 0700) < 0) {
         Error("Couldn't create the directory '%s'.\n", guestProxyTrustedDir);
         goto exit;
      }
   }

   ret = TRUE;

exit:
   return ret;
}
예제 #10
0
파일: dir.c 프로젝트: rpeyron/viking
const gchar *a_get_viking_dir()
{
  static gchar *viking_dir = NULL;

  // TODO: use g_get_user_config_dir ?

  if (!viking_dir) {
    const gchar *home = g_getenv("HOME");
    if (!home || g_access(home, W_OK))
      home = g_get_home_dir ();
#ifdef HAVE_MKDTEMP
    if (!home || g_access(home, W_OK))
    {
      static gchar temp[] = {"/tmp/vikXXXXXX"};
      home = mkdtemp(temp);
    }
#endif
    if (!home || g_access(home, W_OK))
      /* Fatal error */
      g_critical("Unable to find a base directory");

    /* Build the name of the directory */
#ifdef __APPLE__
    viking_dir = g_build_filename(home, "/Library/Application Support/Viking", NULL);
#else
    viking_dir = g_build_filename(home, ".viking", NULL);
#endif
    if (g_file_test(viking_dir, G_FILE_TEST_EXISTS) == FALSE)
      g_mkdir(viking_dir, 0755);
  }

  return viking_dir;
}
예제 #11
0
static char *
make_worktree_for_download (SeafCloneManager *mgr,
                            const char *wt_tmp,
                            GError **error)
{
    char *worktree;

    if (g_access (wt_tmp, F_OK) == 0) {
        worktree = try_worktree (wt_tmp);
    } else {
        worktree = g_strdup(wt_tmp);
    }

    if (!check_worktree_path (mgr, worktree, error)) {
        g_free (worktree);
        return NULL;
    }

    if (g_mkdir (worktree, 0777) < 0) {
        seaf_warning ("[clone mgr] Failed to create dir %s.\n", worktree);
        g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
                     "Failed to create worktree");
        g_free (worktree);
        return NULL;
    }

    return worktree;
}
예제 #12
0
/**
 * caja_get_desktop_directory:
 *
 * Get the path for the directory containing files on the desktop.
 *
 * Return value: the directory path.
 **/
char *
caja_get_desktop_directory (void)
{
    char *desktop_directory;

    desktop_directory = get_desktop_path ();

    /* Don't try to create a home directory */
    if (!g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_DESKTOP_IS_HOME_DIR))
    {
        if (!g_file_test (desktop_directory, G_FILE_TEST_EXISTS))
        {
            g_mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
            /* FIXME bugzilla.gnome.org 41286:
             * How should we handle the case where this mkdir fails?
             * Note that caja_application_startup will refuse to launch if this
             * directory doesn't get created, so that case is OK. But the directory
             * could be deleted after Caja was launched, and perhaps
             * there is some bad side-effect of not handling that case.
             */
        }
    }

    return desktop_directory;
}
예제 #13
0
/**
 * create_user_plugin_dirs:
 *
 * Creates plug-in directory tree in user's home directory (or whereever is
 * it on Win32).
 *
 * Returns: Whether all the directories either exists or were successfully
 * created.
 **/
static gboolean
create_user_plugin_dirs(void)
{
    gchar *dir[3];
    gsize i;
    gboolean ok = TRUE;

    dir[0] = g_build_filename(gwy_get_user_dir(), "plugins", NULL);
    dir[1] = g_build_filename(gwy_get_user_dir(), "plugins", "process", NULL);
    dir[2] = g_build_filename(gwy_get_user_dir(), "plugins", "file", NULL);

    for (i = 0; i < G_N_ELEMENTS(dir); i++) {
        if (!g_file_test(dir[i], G_FILE_TEST_IS_DIR)) {
            gwy_debug("Trying to create user plugin directory %s", dir[i]);
            if (g_mkdir(dir[i], 0700)) {
                g_warning("Cannot create user plugin directory %s: %s",
                        dir[i], g_strerror(errno));
                ok = FALSE;
            }
        }
        g_free(dir[i]);
    }

    return ok;
}
예제 #14
0
파일: database.cpp 프로젝트: UIKit0/digikam
lfError lfDatabase::Save (const char *filename,
                          const lfMount *const *mounts,
                          const lfCamera *const *cameras,
                          const lfLens *const *lenses) const
{
    /* Special case: if filename begins with HomeDataDir and HomeDataDir
     * does not exist, try to create it (since we're in charge for this dir).
     */
    if (g_str_has_prefix (filename, HomeDataDir) &&
        g_file_test (HomeDataDir, G_FILE_TEST_IS_DIR))
        g_mkdir (HomeDataDir, 0777);

    char *output = Save (mounts, cameras, lenses);
    if (!output)
        return lfError (-ENOMEM);

    int fh = g_open (filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
    if (fh < 0)
    {
        g_free (output);
        return lfError (-errno);
    }

    int ol = strlen (output);
    ol = (write (fh, output, ol) == ol);
    close (fh);

    g_free (output);

    return ol ? LF_NO_ERROR : lfError (-ENOSPC);
}
static gboolean
ensure_dot_mate_exists (void)
{
	gboolean retval = TRUE;
	gboolean create_dirs;
	gchar *dirname;

	/* If the user does not have a writable HOME directory, then
	   avoid creating the directory. */
	create_dirs = (g_access (g_get_home_dir(), W_OK) == 0);

        if (create_dirs != TRUE)
		return TRUE;

	dirname = g_build_filename (g_get_home_dir (), ".mate2", NULL);

	if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) {
		if (g_mkdir (dirname, S_IRWXU) != 0) {
			g_warning ("Unable to create ~/.mate2 directory: %s",
				   g_strerror (errno));
			retval = FALSE;
		}
	} else if (!g_file_test (dirname, G_FILE_TEST_IS_DIR)) {
		g_warning ("Error: ~/.mate2 must be a directory.");
		retval = FALSE;
	}

	g_free (dirname);
	return retval;
}
void
_pidgin_smiley_theme_init(void)
{
	GList *it;
	const gchar *user_smileys_dir;
	const gchar *theme_name;

	probe_dirs = g_new0(gchar*, 3);
	probe_dirs[0] = g_build_filename(
		PURPLE_DATADIR, "pixmaps", "pidgin", "emotes", NULL);
	user_smileys_dir = probe_dirs[1] = g_build_filename(
		purple_user_dir(), "smileys", NULL);

	if (!g_file_test(user_smileys_dir, G_FILE_TEST_IS_DIR)) {
		if (g_mkdir(user_smileys_dir, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
			purple_debug_error("gtksmiley-theme",
				"Failed to create user smileys dir");
		}
	}

	/* setting theme by name (copy-paste from gtkprefs) */
	pidgin_smiley_theme_probe();
	theme_name = purple_prefs_get_string(
		PIDGIN_PREFS_ROOT "/smileys/theme");
	for (it = smiley_themes; it; it = g_list_next(it)) {
		PidginSmileyTheme *theme = it->data;

		if (g_strcmp0(pidgin_smiley_theme_get_name(theme), theme_name))
			continue;

		purple_smiley_theme_set_current(PURPLE_SMILEY_THEME(theme));
	}
}
예제 #17
0
파일: user_config.c 프로젝트: kaklik/ucview
static gchar *get_config_path( void )
{
   char *homepath;
   gchar *path;
   
   homepath = getenv( "HOME" );
   if( !homepath )
   {
      return NULL;
   }
   
   path = g_build_path( G_DIR_SEPARATOR_S, homepath, ".ucview", NULL );
   if( g_file_test( path, G_FILE_TEST_EXISTS ) )
   {
      if( !g_file_test( path, G_FILE_TEST_IS_DIR ) )
      {
	 g_warning( "%s is not a directory\n", path );
	 g_free( path );
	 return NULL;
      }
   }
   else
   {
      if( g_mkdir( path, 0755 ) )
      {
	 g_warning( "Failed to create '%s'\n", path );
	 g_free( path );
	 return NULL;
      }
   }

   return path;
}
예제 #18
0
/**
 * ephy_web_application_create:
 * @address: the address of the new web application
 * @name: the name for the new web application
 * @icon: the icon for the new web application
 * 
 * Creates a new Web Application for @address.
 * 
 * Returns: (transfer-full): the path to the desktop file representing the new application
 **/
char *
ephy_web_application_create (const char *address, const char *name, GdkPixbuf *icon)
{
  char *profile_dir = NULL;
  char *desktop_file_path = NULL;

  /* If there's already a WebApp profile for the contents of this
   * view, do nothing. */
  profile_dir = ephy_web_application_get_profile_directory (name);
  if (g_file_test (profile_dir, G_FILE_TEST_IS_DIR)) {
    LOG ("Profile directory %s already exists", profile_dir);
    goto out;
  }

  /* Create the profile directory, populate it. */
  if (g_mkdir (profile_dir, 488) == -1) {
    LOG ("Failed to create directory %s", profile_dir);
    goto out;
  }

  /* Things we need in a WebApp's profile:
     - Our own cookies file, copying the relevant cookies for the
       app's domain.
  */
  create_cookie_jar_for_domain (address, profile_dir);

  /* Create the deskop file. */
  desktop_file_path = create_desktop_file (address, profile_dir, name, icon);

out:
  if (profile_dir)
    g_free (profile_dir);

  return desktop_file_path;
}
예제 #19
0
파일: options_prefs.c 프로젝트: rosedu/osmo
gchar* 
prefs_get_config_filename (gchar *config_filename, GUI *appGUI) {

static gchar dirname[PATH_MAX], filename[PATH_MAX];
struct stat cfg;

    if (appGUI->config_path == NULL) {
#if defined(CONFIG_PATH) && defined(CONFIG_DIR)
        g_snprintf(dirname, PATH_MAX, "%s%c%s", CONFIG_PATH, G_DIR_SEPARATOR, CONFIG_DIR);
#elif defined(CONFIG_DIR)
        g_snprintf(dirname, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIR);
#elif defined(CONFIG_PATH)
        g_snprintf(dirname, PATH_MAX, "%s%c%s", CONFIG_PATH, G_DIR_SEPARATOR, CONFIG_DIRNAME);
#else
        g_snprintf(dirname, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME);
#endif
    } else {
        g_strlcpy (dirname, appGUI->config_path, PATH_MAX);
    }

    if(g_stat (dirname, &cfg) < 0)
        g_mkdir (dirname, S_IRUSR | S_IWUSR | S_IXUSR);

    if (g_access (dirname, R_OK | W_OK) == -1) {
        return NULL;
    }

    g_snprintf(filename, PATH_MAX, "%s%c%s", dirname, G_DIR_SEPARATOR, config_filename);

    return filename;
}
예제 #20
0
int test() {
	int K = 3;
	const gchar *strings[] = {
			"xabxa",
			"abxbx",
			"abcbx",
			NULL
	};

	VisualizerData data;
	data.dot = "dot";
	data.edgeLabelType = EDGE_LABEL_TYPE_SUBSTRING;
	data.counter = 0;
	data.dir = g_build_path(G_DIR_SEPARATOR_S, g_get_tmp_dir(), "cs-suffix-tree", NULL);
	g_mkdir(data.dir, 0777);

	printf("Generating images into %s... ", data.dir);
	SuffixTree *tree = t_new_callback(strings, visualize, &data);
//	visualize(tree, &data, 0, 0);
	printf("Done.\n");

	CommonString *cs = find_lcstr_tree(strings, tree);
	int k;
	for (k = 0; k < K-1; k++) {
		gchar *atLeast = (k < K-2 ? "at least " : "");
		printf("Longest in %s%d strings: %s\n", atLeast, k+2, cs_get_substring(&cs[k]));
	}

	g_free(data.dir);
	t_free(tree);
	cs_free(cs, K);
	return 0;
}
예제 #21
0
gboolean
lsq_tempfs_make_root_dir ( LSQArchive *archive )
{
    gint error = 0;
    gchar dirname[256];

    g_return_val_if_fail( LSQ_IS_ARCHIVE( archive ), FALSE );

    if ( NULL != archive->temp_dir )
    {
        return TRUE;
    }

    g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/", g_get_tmp_dir(), g_get_user_name() );
    if ( 0 != g_mkdir_with_parents( dirname, 0700 ) )
    {
        return FALSE;
    }

    do
    {
        g_snprintf( dirname, 256, "%s/" PACKAGE "-%s/cache-%d/", g_get_tmp_dir(), g_get_user_name(), suffix++ );
        error = g_mkdir( dirname, 0700 );
    }
    while ( 0 != error && EEXIST == errno );

    if ( 0 == error )
    {
        archive->temp_dir = g_strdup( dirname );
        return TRUE;
    }

    return FALSE;
}
예제 #22
0
static void
gfilter_save_args(GwyContainer *container,
                  GFilterArgs *args)
{
    gchar *filename;
    FILE *fh;
    guint i;

    gwy_container_set_boolean_by_name(container, update_key, args->update);
    gwy_container_set_int32_by_name(container, expanded_key, args->expanded);
    gwy_container_set_enum_by_name(container, logical_key, args->logical);

    for (i = 0; i < NQUANTITIES; i++) {
        gchar buf[sizeof(quantity_key) + 10];

        g_snprintf(buf, sizeof(buf), "%s%u", quantity_key, i+1);
        gwy_container_set_string_by_name(container, buf,
                                         g_strdup(args->ranges[i].quantity));
    }

    filename = g_build_filename(gwy_get_user_dir(), "grain_filter", NULL);
    if (!g_file_test(filename, G_FILE_TEST_IS_DIR))
        g_mkdir(filename, 0700);
    g_free(filename);

    filename = g_build_filename(gwy_get_user_dir(), "grain_filter", "ranges",
                                NULL);
    if ((fh = g_fopen(filename, "w"))) {
        g_hash_table_foreach(args->ranges_history, save_range, fh);
        fclose(fh);
    }
    g_free(filename);
}
예제 #23
0
static void
purple_buddy_icon_data_cache(PurpleStoredImage *img)
{
	const char *dirname;
	char *path;

	g_return_if_fail(img != NULL);

	if (!purple_buddy_icons_is_caching())
		return;

	dirname  = purple_buddy_icons_get_cache_dir();
	path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL);

	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
	{
		purple_debug_info("buddyicon", "Creating icon cache directory.\n");

		if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0)
		{
			purple_debug_error("buddyicon",
			                   "Unable to create directory %s: %s\n",
			                   dirname, g_strerror(errno));
		}
	}

	if (!g_file_test(path, G_FILE_TEST_IS_REGULAR))
	{
		purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img),
							purple_imgstore_get_size(img));
	}

	g_free(path);
}
예제 #24
0
파일: xpad-app.c 프로젝트: abhinandh/xpad
/**
 * Creates the directory if it does not exist.
 * Returns newly allocated dir name, NULL if an error occurred.
 */
static gchar *
make_config_dir (void)
{
	gchar *dir = NULL;
	
	make_path (g_get_user_config_dir ());
	
	dir = g_build_filename (g_get_user_config_dir (), PACKAGE, NULL);
	
	if (!g_file_test (dir, G_FILE_TEST_EXISTS))
	{
		gchar *olddir;
		
		/* For backwards-compatibility, we see if the old location for
		   configuration files exists.  If so, we move it. */
		olddir = g_build_filename (g_get_home_dir (), "." PACKAGE, NULL);
		
		if (g_file_test (olddir, G_FILE_TEST_EXISTS))
			g_rename (olddir, dir);
		else
			g_mkdir (dir, 0700); /* give user all rights */
		
		g_free (olddir);
	}
	
	return dir;
}
예제 #25
0
int Inkscape::IO::mkdir_utf8name( char const *utf8name )
{
    static gint counter = 0;
    int retval = -1;

    DEBUG_MESSAGE( dumpMk, "entering mkdir_utf8name( '%s' )[%d]", utf8name, (counter++) );

#ifndef WIN32
    DEBUG_MESSAGE( dumpMk, "           STEP 0              ( '%s' )[%d]", utf8name, (counter++) );
    gchar *filename = g_filename_from_utf8( utf8name, -1, NULL, NULL, NULL );
    if ( filename )
    {
        DEBUG_MESSAGE( dumpMk, "           STEP 1              ( '%s' )[%d]", utf8name, (counter++) );
        retval = ::mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP);
        DEBUG_MESSAGE( dumpMk, "           STEP 2              ( '%s' )[%d]", utf8name, (counter++) );
        g_free(filename);
        DEBUG_MESSAGE( dumpMk, "           STEP 3              ( '%s' )[%d]", utf8name, (counter++) );
        filename = 0;
    }
#else
    DEBUG_MESSAGE( dumpMk, "   calling is_os_wide()       ( '%s' )[%d]", utf8name, (counter++) );

    // Mode should be ingnored inside of glib on the way in
    retval = g_mkdir( utf8name, 0 );
#endif

    DEBUG_MESSAGE( dumpMk, "leaving mkdir_utf8name( '%s' )[%d]", utf8name, (counter++) );

    return retval;
}
예제 #26
0
파일: seaf-test.c 프로젝트: 2bj/seafile
static void setup()
{
    client = ccnet_client_new ();
    if ( ccnet_client_load_confdir(client, CCNET_DIR) < 0 ) {
        fprintf (stderr, "Read config dir error\n");
        exit(1);
    }

    event_init ();

    if (g_access (TEST_DIR "worktree", F_OK) != 0 &&
        g_mkdir (TEST_DIR "worktree", 0777) < 0) {
        fprintf (stderr, "Failed to create worktree.\n");
        exit (1);
    }

    seaf = seafile_session_new (SEAF_DIR, 
                                WORKTREE_DIR,
                                client);
    if (!seaf) {
        fprintf (stderr, "Failed to create seafile session.\n");
        exit (1);
    }
    seafile_session_prepare (seaf);
}
예제 #27
0
파일: config.c 프로젝트: sfate/volumeicon
void config_initialize()
{
	// Build config directory name
	gchar * config_dir = g_build_filename(g_get_user_config_dir(),
		CONFIG_DIRNAME, NULL);
	m_config_file = g_build_filename(config_dir, CONFIG_FILENAME, NULL);

	// Make sure config directory exists
	if(!g_file_test(config_dir, G_FILE_TEST_IS_DIR))
		g_mkdir(config_dir, 0777);

	// If a config file doesn't exist, create one with defaults otherwise
	// read the existing one.
	if(!g_file_test(m_config_file, G_FILE_TEST_EXISTS))
	{
		config_load_default();
		config_write();
	}
	else
	{
		config_read();
	}

	g_free(config_dir);
}
예제 #28
0
/* must be called once device information is available via source properties */
void
rb_media_player_source_load		(RBMediaPlayerSource *source)
{
	RBMediaPlayerSourcePrivate *priv = MEDIA_PLAYER_SOURCE_GET_PRIVATE (source);
	char *device_id;
	char *sync_filename;
	char *sync_path;
	char *sync_dir;

	/* make sure the sync settings dir exists */
	sync_dir = g_build_filename (rb_user_data_dir (), "sync", NULL);
	g_mkdir (sync_dir, 0700);

	/* construct path to sync settings file */
	g_object_get (source, "serial", &device_id, NULL);
	if (device_id == NULL) {
		g_object_get (source, "name", &device_id, NULL);
	}
	sync_filename = g_strdup_printf ("device-%s.conf", device_id);
	sync_path = g_build_filename (sync_dir, sync_filename, NULL);
	g_free (sync_filename);
	g_free (device_id);
	g_free (sync_dir);

	priv->sync_settings = rb_sync_settings_new (sync_path);
	g_free (sync_path);
}
예제 #29
0
void
button_save_conf_clicked (GtkButton *button, gpointer user_data){
    
    GError *error=NULL;
    GKeyFile *key_file;
    gchar *filename;
    FZ_Advanced *field = user_data;
    /*if (!conn)
        if (connection() != 0){
            g_print("Configure a Conexão do Sistema");
            return;
        }
    */
    key_file = g_key_file_new();
    
    // Attrs
    gchar *host = gtk_entry_get_text(field->Host);
    if (!host)
        host = "localhost";
    g_key_file_set_value (key_file, "DBConf", "IP", host);
    //g_free (host);
    
    gint port = gtk_spin_button_get_value_as_int (field->Port);
    if (!port)
        port = 5432;
    g_key_file_set_integer (key_file, "DBConf", "port", port);
    
    gchar *login = gtk_entry_get_text(field->Login);
    g_key_file_set_value (key_file, "DBConf", "user", login);
    //g_free (login);
    
    gchar *password = gtk_entry_get_text(field->PassWord);
    int len_password = gtk_entry_get_text_length(field->PassWord);
    if (len_password){
        g_key_file_set_integer (key_file, "DBConf", "len", len_password);
        password = g_utf8_strreverse (password, len_password);
        password = g_base64_encode (password, len_password);
        g_key_file_set_value (key_file, "DBConf", "password", password);
        //g_free (password);
    }
    
    filename = g_strdup_printf("%s/%s", g_get_home_dir (), LOCAL_SHARE);
    
    if (!g_file_test (filename, G_FILE_TEST_IS_DIR))
        if ( g_mkdir(filename, 0777) == -1 )
            g_print("Error: Criar Dir.\n");
    
    filename = g_build_filename (filename, "firezero.conf", NULL);
    
    if (!g_key_file_save_to_file (key_file, filename, &error))
        g_print("ERROR: %s\n", error->message);//TODO Create Dialog
    
    g_key_file_free (key_file);
    g_free (filename);

    //
    //TODO using to field DBConf and to save in filename
    //
}
예제 #30
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;
}