static gboolean gb_vim_command_edit (GtkWidget *active_widget, const gchar *command, const gchar *options, GError **error) { IdeWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; g_assert (GTK_IS_WIDGET (active_widget)); if (dzl_str_empty0 (options)) { dzl_gtk_widget_action (GTK_WIDGET (active_widget), "win", "open-with-dialog", NULL); return TRUE; } if (!(workbench = ide_widget_get_workbench (active_widget)) || !(context = ide_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } if (g_path_is_absolute (options)) file = g_file_new_for_path (options); else file = g_file_get_child (workdir, options); ide_workbench_open_files_async (workbench, &file, 1, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, NULL); g_clear_object (&file); return TRUE; }
gchar * rs_metadata_dotdir_helper(const gchar *filename, const gchar *extension) { gchar *basename; gchar *dotdir; gchar *temp; g_assert(filename != NULL); g_assert(g_path_is_absolute(filename)); g_assert((dotdir = rs_dotdir_get(filename))); g_assert((basename = g_path_get_basename(filename))); temp = g_strdup_printf("%s/%s.%s", dotdir, basename, extension); g_free(dotdir); g_free(basename); return temp; }
/** * Helper function to correctly take into account the users base-dir setting for * paths that might be relative. * Note: Because this function potentially frees the pointer to gchar* that's passed in and cannot lock * on that, it is _not_ threadsafe. You have to ensure threadsafety yourself! * @returns TRUE if it modified the filename, FALSE if it didn't */ gboolean chassis_resolve_path(const char *base_dir, gchar **filename) { gchar *new_path = NULL; if (!base_dir || !filename || !*filename) return FALSE; /* don't even look at absolute paths */ if (g_path_is_absolute(*filename)) return FALSE; new_path = g_build_filename(base_dir, G_DIR_SEPARATOR_S, *filename, NULL); g_log_dbproxy(g_debug, "adjusting relative path (%s) to base_dir (%s). New path: %s", *filename, base_dir, new_path); g_free(*filename); *filename = new_path; return TRUE; }
GdkPixbuf * nautilus_ui_get_menu_icon (const char *icon_name) { NautilusIconInfo *info; GdkPixbuf *pixbuf; int size; size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); if (g_path_is_absolute (icon_name)) { info = nautilus_icon_info_lookup_from_path (icon_name, size); } else { info = nautilus_icon_info_lookup_from_name (icon_name, size); } pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size); g_object_unref (info); return pixbuf; }
GList * gimp_palette_load_act (const gchar *filename, GError **error) { GimpPalette *palette; gchar *palette_name; gint fd; guchar color_bytes[4]; g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (g_path_is_absolute (filename), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); fd = g_open (filename, O_RDONLY | _O_BINARY, 0); if (! fd) { g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (filename), g_strerror (errno)); return NULL; } palette_name = g_filename_display_basename (filename); palette = GIMP_PALETTE (gimp_palette_new (palette_name)); g_free (palette_name); while (read (fd, color_bytes, 3) == 3) { GimpRGB color; gimp_rgba_set_uchar (&color, color_bytes[0], color_bytes[1], color_bytes[2], 255); gimp_palette_add_entry (palette, -1, NULL, &color); } close (fd); return g_list_prepend (NULL, palette); }
char * panel_launcher_get_uri (const char *location) { char *path; char *uri; if (!g_ascii_strncasecmp (location, "file:", strlen ("file:"))) return g_strdup (location); if (!g_path_is_absolute (location)) path = panel_make_full_path (NULL, location); else path = g_strdup (location); uri = g_filename_to_uri (path, NULL, NULL); g_free (path); return uri; }
static gboolean check_path (const char *path) { g_return_val_if_fail (path, FALSE); if (!g_path_is_absolute (path)) { g_warning ("%s: not an absolute path: %s", __FUNCTION__, path); return FALSE; } if (access (path, R_OK) != 0) { g_warning ("%s: cannot open '%s': %s", __FUNCTION__, path, strerror (errno)); return FALSE; } return TRUE; }
static void run_command(int fd_out, const char *cmd) { gint argc = 0; gchar **argv = NULL; if (!g_shell_parse_argv(cmd, &argc, &argv, NULL)) exit(1); dup2_or_exit(fd_out, fileno(stdout)); dup2_or_exit(fd_out, fileno(stderr)); const char *real_cmd = argv[0]; if (!g_path_is_absolute(real_cmd)) real_cmd = g_find_program_in_path(real_cmd); execv(real_cmd, argv); g_strfreev(argv); exit(1); }
static void show_completed_file (GFile *hit, gboolean is_dir, const char *arg) { char *path, *cwd, *display, *t; GFile *cwd_f; GFile *home; if (g_file_is_native (hit)) { cwd = g_get_current_dir (); cwd_f = g_file_new_for_path (cwd); g_free (cwd); home = g_file_new_for_path (g_get_home_dir ()); if ((g_file_has_prefix (hit, home) || g_file_equal (hit, home)) && arg[0] == '~') { t = g_file_get_relative_path (home, hit); path = g_strconcat ("~", (t != NULL) ? "/": "", t, NULL); g_free (t); } else if (g_file_has_prefix (hit, cwd_f) && !g_path_is_absolute (arg)) path = g_file_get_relative_path (cwd_f, hit); else path = g_file_get_path (hit); g_object_unref (cwd_f); g_object_unref (home); display = shell_quote (path); g_free (path); } else display = g_file_get_uri (hit); g_print ("%s%s\n", display, (is_dir)?"/":""); g_free (display); }
static AsIcon * as_app_desktop_create_icon (AsApp *app, const gchar *name, AsAppParseFlags flags) { AsIcon *icon = as_icon_new (); gchar *dot; g_autofree gchar *name_fixed = NULL; /* local */ if (g_path_is_absolute (name)) { as_icon_set_kind (icon, AS_ICON_KIND_LOCAL); as_icon_set_filename (icon, name); return icon; } /* work around a common mistake in desktop files */ name_fixed = g_strdup (name); dot = g_strstr_len (name_fixed, -1, "."); if (dot != NULL && (g_strcmp0 (dot, ".png") == 0 || g_strcmp0 (dot, ".xpm") == 0 || g_strcmp0 (dot, ".svg") == 0)) { *dot = '\0'; } /* stock */ if (as_utils_is_stock_icon_name (name_fixed)) { as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, name_fixed); return icon; } /* stock, but kinda sneaky */ if ((flags & AS_APP_PARSE_FLAG_USE_FALLBACKS) > 0 && _as_utils_is_stock_icon_name_fallback (name_fixed)) { as_icon_set_kind (icon, AS_ICON_KIND_STOCK); as_icon_set_name (icon, name_fixed); return icon; } /* just use default of UNKNOWN */ as_icon_set_name (icon, name_fixed); return icon; }
static void gth_application_init (GthApplication *app) { #ifdef GDK_WINDOWING_X11 GDesktopAppInfo *app_info; app_info = g_desktop_app_info_new ("gthumb.desktop"); if (app_info == NULL) return; if (g_desktop_app_info_has_key (app_info, "Name")) { char *app_name; app_name = g_desktop_app_info_get_string (app_info, "Name"); g_set_application_name (app_name); g_free (app_name); } if (g_desktop_app_info_has_key (app_info, "Icon")) { char *icon; icon = g_desktop_app_info_get_string (app_info, "Icon"); if (g_path_is_absolute (icon)) gtk_window_set_default_icon_from_file (icon, NULL); else gtk_window_set_default_icon_name (icon); g_free (icon); } g_object_unref (app_info); #else /* manually set name and icon */ g_set_application_name (_("gThumb")); gtk_window_set_default_icon_name ("gthumb"); #endif }
inline void button_clicked_entry_browse_directory (GtkWidget* widget, GtkEntry* entry) { gtkutil::FileChooser dirChooser(gtk_widget_get_toplevel(widget), _("Choose Directory"), true, true); std::string curEntry = gtk_entry_get_text(entry); if (g_path_is_absolute(curEntry.c_str())) curEntry.clear(); dirChooser.setCurrentPath(curEntry); std::string filename = dirChooser.display(); if (GTK_IS_WINDOW(gtk_widget_get_toplevel(widget))) { gtk_window_present(GTK_WINDOW(gtk_widget_get_toplevel(widget))); } if (!filename.empty()) { gtk_entry_set_text(entry, filename.c_str()); } }
void gtr_open_file (const char * path) { char * uri; GFile * file = g_file_new_for_path (path); g_object_unref (G_OBJECT (file)); if (g_path_is_absolute (path)) uri = g_strdup_printf ("file://%s", path); else { char * cwd = g_get_current_dir (); uri = g_strdup_printf ("file://%s/%s", cwd, path); g_free (cwd); } gtr_open_uri (uri); g_free (uri); }
void gtr_open_file (const char * path) { char * uri; if (g_path_is_absolute (path)) { uri = g_strdup_printf ("file://%s", path); } else { char * cwd = g_get_current_dir (); uri = g_strdup_printf ("file://%s/%s", cwd, path); g_free (cwd); } gtr_open_uri (uri); g_free (uri); }
void waveform_peakgen(Waveform* w, const char* peak_filename, WfCallback2 callback, gpointer user_data) { if(!peakgen.msg_queue) wf_worker_init(&peakgen); typedef struct { char* infilename; const char* peak_filename; struct { bool failed; // returned true if peakgen failed } out; WfCallback2 callback; void* user_data; } PeakJob; PeakJob* job = g_new0(PeakJob, 1); *job = (PeakJob) { .infilename = g_path_is_absolute(w->filename) ? g_strdup(w->filename) : g_build_filename(g_get_current_dir(), w->filename, NULL), .peak_filename = peak_filename, .callback = callback, .user_data = user_data, }; void peakgen_execute_job(Waveform* w, gpointer _job) { // runs in worker thread PeakJob* job = _job; if(!wf_peakgen__sync(job->infilename, job->peak_filename)) { #ifdef DEBUG if(wf_debug) gwarn("peakgen failed"); #endif job->out.failed = true; // writing to object owned by main thread } } void peakgen_free(gpointer item) { PeakJob* job = item; g_free0(job->infilename); g_free(job); }
static gboolean try_to_expand_path (gpointer callback_data) { AthenaLocationEntry *entry; GtkEditable *editable; char *suffix, *user_location, *absolute_location, *uri_scheme; int user_location_length, pos; entry = ATHENA_LOCATION_ENTRY (callback_data); editable = GTK_EDITABLE (entry); user_location = gtk_editable_get_chars (editable, 0, -1); user_location_length = g_utf8_strlen (user_location, -1); entry->details->idle_id = 0; uri_scheme = g_uri_parse_scheme (user_location); if (!g_path_is_absolute (user_location) && uri_scheme == NULL && user_location[0] != '~') { absolute_location = g_build_filename (entry->details->current_directory, user_location, NULL); suffix = g_filename_completer_get_completion_suffix (entry->details->completer, absolute_location); g_free (absolute_location); } else { suffix = g_filename_completer_get_completion_suffix (entry->details->completer, user_location); } g_free (user_location); g_free (uri_scheme); /* if we've got something, add it to the entry */ if (suffix != NULL) { pos = user_location_length; gtk_editable_insert_text (editable, suffix, -1, &pos); pos = user_location_length; gtk_editable_select_region (editable, pos, -1); g_free (suffix); } return FALSE; }
/* Given (eg.) "/poop/somefile.png", write @im to the thumbnail name, * (eg.) "/poop/tn_somefile.jpg". */ static int thumbnail_write( VipsImage *im, const char *filename ) { char *file; char *p; char buf[FILENAME_MAX]; char *output_name; file = g_path_get_basename( filename ); /* Remove the suffix from the file portion. */ if( (p = strrchr( file, '.' )) ) *p = '\0'; /* output_format can be an absolute path, in which case we discard the * path from the incoming file. */ vips_snprintf( buf, FILENAME_MAX, output_format, file ); if( g_path_is_absolute( output_format ) ) output_name = g_strdup( buf ); else { char *dir; dir = g_path_get_dirname( filename ); output_name = g_build_filename( dir, buf, NULL ); g_free( dir ); } vips_info( "vipsthumbnail", "thumbnailing %s as %s", filename, output_name ); g_free( file ); if( vips_image_write_to_file( im, output_name, NULL ) ) { g_free( output_name ); return( -1 ); } g_free( output_name ); return( 0 ); }
void fl_set_initial_dir(const gchar *dir) { working_dir = g_string_sized_new(200); working_dir_utf8 = g_string_sized_new(200); if (dir == NULL) fl_set_working_dir_utf8(g_elist_first(dir_mru->list)->data); else { if (g_path_is_absolute(dir)) fl_set_working_dir(dir); else { /* make the path absolute */ char *cur = g_get_current_dir(); char *abs = fu_join_path(cur, dir); fl_set_working_dir(abs); free(cur); free(abs); } } }
static struct song * playlist_check_load_song(const struct song *song, const char *uri, bool secure) { struct song *dest; if (uri_has_scheme(uri)) { dest = song_remote_new(uri); } else if (g_path_is_absolute(uri) && secure) { dest = song_file_load(uri, NULL); if (dest == NULL) return NULL; } else { dest = db_get_song(uri); if (dest == NULL) /* not found in database */ return NULL; } return apply_song_metadata(dest, song); }
/** * Save a map file (outer function). This function tries to backup the map * file before calling MapResource_saveFile() to do the actual saving of * data. */ bool MapResource_save (const MapFormat& format, scene::Node& root, const std::string& path, const std::string& name) { std::string fullpath = path + name; if (g_path_is_absolute(fullpath.c_str())) { // Save a backup if possible. This is done by renaming the original, // which won't work if the existing map is currently open by another process // in the background. if (file_exists(fullpath) && !file_saveBackup(fullpath)) { globalErrorStream() << "ERROR: could not rename: " << fullpath << " to backup." << "\n"; } // Save the actual file return MapResource_saveFile(format, root, map::Map_Traverse, fullpath); } else { globalErrorStream() << "ERROR: map path is not fully qualified: " << fullpath << "\n"; return false; } }
gboolean rs_metadata_load(RSMetadata *metadata, const gchar *filename) { g_return_val_if_fail(RS_IS_METADATA(metadata), FALSE); g_return_val_if_fail(filename != NULL, FALSE); g_return_val_if_fail(g_path_is_absolute(filename), FALSE); if (!rs_metadata_cache_load(metadata, filename)) { if (rs_metadata_load_from_file(metadata, filename)) { rs_metadata_cache_save(metadata, filename); generate_lens_identifier(metadata); return TRUE; } return FALSE; } generate_lens_identifier(metadata); return TRUE; }
static void swfdec_test_test_load_plugin (SwfdecTestTest *test, const char *filename) { memset (&test->plugin, 0, sizeof (SwfdecTestPlugin)); /* initialize test->plugin */ /* FIXME: This assumes filenames - do we wanna allow http? */ if (g_path_is_absolute (filename)) { test->plugin.filename = g_strdup (filename); } else { char *cur = g_get_current_dir (); test->plugin.filename = g_build_filename (cur, filename, NULL); g_free (cur); } test->plugin.trace = swfdec_test_test_trace; test->plugin.launch = swfdec_test_test_launch; test->plugin.quit = swfdec_test_test_quit; test->plugin.error = swfdec_test_test_error; test->plugin.request_socket = swfdec_test_test_request_socket; /* load the right values */ if (swfdec_test_plugin_name) { void (*init) (SwfdecTestPlugin *plugin); char *dir = g_build_filename (g_get_home_dir (), ".swfdec-test", NULL); char *name = g_module_build_path (dir, swfdec_test_plugin_name); g_free (dir); test->module = g_module_open (name, G_MODULE_BIND_LOCAL); if (test->module == NULL) { swfdec_test_throw (swfdec_gc_object_get_context (test), "could not find player \"%s\"", swfdec_test_plugin_name); return; } if (!g_module_symbol (test->module, "swfdec_test_plugin_init", (gpointer) &init)) { g_module_close (test->module); test->module = NULL; } init (&test->plugin); } else { swfdec_test_plugin_swfdec_new (&test->plugin); } test->plugin_loaded = TRUE; }
G_MODULE_EXPORT gchar * am_realpath (const gchar *path) { gchar *abpath; gchar opath[PATH_MAX]; if (g_path_is_absolute (path)) { return g_strdup (path); } if (path[0] == '~') { const gchar *home = getenv ("HOME"); if (home == NULL) { home = g_get_home_dir (); } if (home == NULL) { return NULL; } abpath = g_build_filename (home, path + 1, NULL); } else { #ifdef WIN32 getcwd (sizeof (opath), opath); strcat (opath, "\\"); strcat (opath, path); #else if (realpath (path, opath) == NULL) { return NULL; } #endif abpath = g_strdup (opath); } return abpath; }
/* ExpandFilename : "expand" the given file/dirname to make it absolute (if `makeAbsolute' is TRUE), remove leading ~ terms. Returns a newly allocated string. Cleans up name a bit by removing extra slashes and ./'es. NB. filename gets (temporarily) modified so don't pass any constant strings in here. `pwd' contains the current (perceived) working directory. Set this to NULL to use the actual cwd. */ char *ExpandFilename (char *filename, gboolean makeAbsolute, char *pwd) { char *root = NULL; char *ret; if (!g_path_is_absolute (filename)) { if (*filename == '~') { /* home dir relative */ if (filename[1] == '\0' || filename[1] == G_DIR_SEPARATOR) { root = GetHomeDir (g_get_user_name ()); filename++; } else if (isalnum (filename[1])) { /* ~whoever/a/b/c */ char savedChar; char *endPtr = filename + 1; while (isalnum (*endPtr)) endPtr++; savedChar = *endPtr; root = GetHomeDir (filename + 1); *endPtr = savedChar; filename = endPtr; } /* else leave the ~ in place, dunno what it means */ } else if (makeAbsolute) /* starts with ./ (add current dir) or not / */ root = g_strdup (pwd ? pwd : g_get_current_dir ()); } ret = (char *) g_malloc ((root ? strlen (root) : 0) + strlen (filename) + 2); *ret = '\0'; if (root) { sprintf (ret, "%s%c", root, G_DIR_SEPARATOR); g_free (root); } strcat (ret, filename); CleanUpFilename (ret); return ret; }
static gboolean gb_vim_command_edit (GtkSourceView *source_view, const gchar *command, const gchar *options, GError **error) { GbWorkbench *workbench; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *file = NULL; if (ide_str_empty0 (options)) { gb_widget_activate_action (GTK_WIDGET (source_view), "workbench", "open", NULL); return TRUE; } if (!(workbench = gb_widget_get_workbench (GTK_WIDGET (source_view))) || !(context = gb_workbench_get_context (workbench)) || !(vcs = ide_context_get_vcs (context)) || !(workdir = ide_vcs_get_working_directory (vcs))) { g_set_error (error, GB_VIM_ERROR, GB_VIM_ERROR_NOT_SOURCE_VIEW, _("Failed to locate working directory")); return FALSE; } if (g_path_is_absolute (options)) file = g_file_new_for_path (options); else file = g_file_get_child (workdir, options); gb_workbench_open (workbench, file); g_clear_object (&file); return TRUE; }
static gchar * preset_create_filename (const gchar *basename, const gchar *dest_dir) { gchar *fullpath; gchar *safe_name; gint i; gint unum = 1; g_return_val_if_fail (basename != NULL, NULL); g_return_val_if_fail (dest_dir != NULL, NULL); g_return_val_if_fail (g_path_is_absolute (dest_dir), NULL); safe_name = g_filename_from_utf8 (basename, -1, NULL, NULL, NULL); if (safe_name[0] == '.') safe_name[0] = '-'; for (i = 0; safe_name[i]; i++) if (safe_name[i] == G_DIR_SEPARATOR || g_ascii_isspace (safe_name[i])) safe_name[i] = '-'; fullpath = g_build_filename (dest_dir, safe_name, NULL); while (g_file_test (fullpath, G_FILE_TEST_EXISTS)) { gchar *filename; g_free (fullpath); filename = g_strdup_printf ("%s-%d", safe_name, unum++); fullpath = g_build_filename (dest_dir, filename, NULL); g_free (filename); } g_free (safe_name); return fullpath; }
static NMVPNService * get_service_by_namefile (NMVPNManager *self, const char *namefile) { NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); GHashTableIter iter; gpointer data; g_return_val_if_fail (namefile, NULL); g_return_val_if_fail (g_path_is_absolute (namefile), NULL); g_hash_table_iter_init (&iter, priv->services); while (g_hash_table_iter_next (&iter, NULL, &data)) { NMVPNService *candidate = NM_VPN_SERVICE (data); const char *service_namefile; service_namefile = nm_vpn_service_get_name_file (candidate); if (!strcmp (namefile, service_namefile)) return candidate; } return NULL; }
gchar *create_full_path(gchar const * filename, gchar *basedir) { gchar *absolute_filename; gchar *tmpcdir; if (g_path_is_absolute(filename)) { absolute_filename = g_strdup(filename); } else { if (basedir) { tmpcdir = ending_slash(basedir); } else { gchar *curdir = g_get_current_dir(); tmpcdir = ending_slash(curdir); g_free(curdir); } absolute_filename = g_strconcat(tmpcdir, filename, NULL); g_free(tmpcdir); } absolute_filename = most_efficient_filename(absolute_filename); return absolute_filename; }
static GOutputStream * prepare_write_stream (const gchar *filename, gchar **filename_used) { GOutputStream *stream; GFile *file; if (g_path_is_absolute (filename)) { file = g_file_new_for_path (filename); *filename_used = g_strdup (filename); stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL)); g_object_unref (file); } else { stream = get_stream_for_filename (filename, filename_used); } return stream; }
/* get the full file path of a command-line argument * N.B. the result should be freed and may contain '/../' or '/./ ' */ gchar *main_get_argv_filename(const gchar *filename) { gchar *result; if (g_path_is_absolute(filename) || utils_is_uri(filename)) result = g_strdup(filename); else { /* use current dir */ gchar *cur_dir = NULL; if (original_cwd == NULL) cur_dir = g_get_current_dir(); else cur_dir = g_strdup(original_cwd); result = g_strjoin( G_DIR_SEPARATOR_S, cur_dir, filename, NULL); g_free(cur_dir); } return result; }