From a57560f5dd1ed230816b9b2b6946cdcfaefbc198 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Thu, 25 Feb 1999 04:08:43 +0000 Subject: [PATCH] 1999-02-24 Miguel de Icaza * gicon.c (gicon_get_filename_for_icon): Return const char *, this tells the user of this routine "you better not touch or free this you dofus". * gnome-file-property-dialog.c (apply_metadata_change): Always set the name of the icon to the new value, as the entry will always match the imlib image anyways (due to the fixes I did to const correctness). (generate_icon_sel): Do not free the value. We do not own this return value. * gdesktop.c (is_mountable): NULL terminate string returned from readlink. Yes guys, readlink does not NULL terminate things. (do_mount_umount): ditto. * gnome-file-property-dialog.c (init_metadata): ditto --- gnome/ChangeLog | 19 +++++++++++++++++++ gnome/gdesktop.c | 16 +++++++++++----- gnome/gicon.c | 6 +++--- gnome/gicon.h | 2 +- gnome/gmount.c | 1 + gnome/gnome-file-property-dialog.c | 26 +++++++------------------- gnome/gpageprop.c | 7 +++++-- gnome/gprop.c | 4 ++-- gnome/gprop.h | 4 ++-- 9 files changed, 51 insertions(+), 34 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index ae70fd8f3..eb44c79d6 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,22 @@ +1999-02-24 Miguel de Icaza + + * gicon.c (gicon_get_filename_for_icon): Return const char *, this + tells the user of this routine "you better not touch or free this + you dofus". + + * gnome-file-property-dialog.c (apply_metadata_change): Always set + the name of the icon to the new value, as the entry will always + match the imlib image anyways (due to the fixes I did to const + correctness). + (generate_icon_sel): Do not free the value. We do not own this + return value. + + * gdesktop.c (is_mountable): NULL terminate string returned from + readlink. Yes guys, readlink does not NULL terminate things. + (do_mount_umount): ditto. + + * gnome-file-property-dialog.c (init_metadata): ditto + Tue Feb 23 17:41:45 1999 George Lebl * gmain.c: set the restart property of the gnome client to diff --git a/gnome/gdesktop.c b/gnome/gdesktop.c index cfd2c98ef..22ef495c0 100644 --- a/gnome/gdesktop.c +++ b/gnome/gdesktop.c @@ -914,7 +914,8 @@ is_mountable (char *filename, file_entry *fe, int *is_mounted, char **point) char buffer [128], *p; umode_t mode; struct stat s; - + int len; + if (point) *point = NULL; @@ -928,9 +929,11 @@ is_mountable (char *filename, file_entry *fe, int *is_mounted, char **point) if (!S_ISBLK (mode)) return FALSE; - if (readlink (filename, buffer, sizeof (buffer)) == -1) + len = readlink (filename, buffer, sizeof (buffer)); + if (len == -1) return FALSE; - + buffer [len] = 0; + p = is_block_device_mountable (buffer); if (!p) return FALSE; @@ -952,7 +955,8 @@ do_mount_umount (char *filename, gboolean is_mount) static char *umount_command; char *op; char buffer [128]; - + int count; + if (is_mount){ if (!mount_command) mount_command = find_command (mount_known_locations); @@ -963,8 +967,10 @@ do_mount_umount (char *filename, gboolean is_mount) op = umount_command; } - if (readlink (filename, buffer, sizeof (buffer)) == -1) + count = readlink (filename, buffer, sizeof (buffer)); + if (count == -1) return FALSE; + buffer [count] = 0; if (op){ char *command; diff --git a/gnome/gicon.c b/gnome/gicon.c index 939212f54..65d4c43f5 100644 --- a/gnome/gicon.c +++ b/gnome/gicon.c @@ -130,7 +130,7 @@ get_icon_set (const char *filename) if (iset) return iset; - im = gdk_imlib_load_image (filename); + im = gdk_imlib_load_image ((char *) filename); if (!im) return NULL; @@ -141,7 +141,7 @@ get_icon_set (const char *filename) /* Insert the icon information into the hash tables */ - g_hash_table_insert (name_hash, filename, iset); + g_hash_table_insert (name_hash, (char *) filename, iset); g_hash_table_insert (image_hash, iset->plain, iset); return iset; @@ -436,7 +436,7 @@ gicon_get_icon_for_file (char *directory, file_entry *fe, gboolean do_quick) * * Return value: The filename that contains the icon for the specified image. **/ -char * +const char * gicon_get_filename_for_icon (GdkImlibImage *image) { IconSet *iset; diff --git a/gnome/gicon.h b/gnome/gicon.h index 05dfc1634..787527726 100644 --- a/gnome/gicon.h +++ b/gnome/gicon.h @@ -17,7 +17,7 @@ void gicon_init (void); GdkImlibImage *gicon_get_icon_for_file (char *directory, file_entry *fe, gboolean do_quick); -char *gicon_get_filename_for_icon (GdkImlibImage *image); +const char *gicon_get_filename_for_icon (GdkImlibImage *image); #endif diff --git a/gnome/gmount.c b/gnome/gmount.c index 4a6a41d9b..6d6e38c5e 100644 --- a/gnome/gmount.c +++ b/gnome/gmount.c @@ -64,6 +64,7 @@ void free (void *ptr); #endif #ifdef MOUNTED_VMOUNT /* AIX. */ +#include #include #include #endif diff --git a/gnome/gnome-file-property-dialog.c b/gnome/gnome-file-property-dialog.c index 0559f0646..00d51edb4 100644 --- a/gnome/gnome-file-property-dialog.c +++ b/gnome/gnome-file-property-dialog.c @@ -211,6 +211,7 @@ create_general_properties (GnomeFilePropertyDialog *fp_dlg) if (n < 0) label = gtk_label_new (_("Target Name: INVALID LINK")); else { + buf [n] = 0; gen_string = g_strconcat (_("Target Name: "), buf, NULL); label = gtk_label_new (gen_string); g_free (gen_string); @@ -433,7 +434,7 @@ static GtkWidget * generate_icon_sel (GnomeFilePropertyDialog *fp_dlg) { GtkWidget *retval; - gchar *icon; + const gchar *icon; retval = gnome_icon_entry_new ("gmc_file_icon", "Select an Icon"); icon = gicon_get_filename_for_icon (fp_dlg->im); @@ -441,11 +442,9 @@ generate_icon_sel (GnomeFilePropertyDialog *fp_dlg) return retval; if (!icon[0]){ - g_free (icon); return retval; } gnome_icon_entry_set_icon (GNOME_ICON_ENTRY (retval), icon); - g_free (icon); return retval; } @@ -962,8 +961,10 @@ init_metadata (GnomeFilePropertyDialog *fp_dlg) file_name = fp_dlg->file_name; if (S_ISLNK (fp_dlg->st.st_mode)) { n = mc_readlink (fp_dlg->file_name, link_name, MC_MAXPATHLEN); - if (n > 0) + if (n > 0){ + link_name [n] = 0; file_name = link_name; + } } if (gnome_metadata_get (fp_dlg->file_name, "desktop-url", &size, &desktop_url) == 0) @@ -1281,22 +1282,9 @@ apply_metadata_change (GnomeFilePropertyDialog *fpd) /* And finally, we set the metadata on the icon filename */ text = gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (fpd->button)); /*gtk_entry_get_text (GTK_ENTRY (gnome_icon_entry_gtk_entry (GNOME_ICON_ENTRY (fpd->button))));*/ - - icon_name = gicon_get_filename_for_icon (fpd->im); + if (text) { - if (strcmp (text, icon_name)) - /* FIXME: We make a big assumption here. If the file doesn't exist, it will - * default to the basic icon. We prolly should check that this is a valid - * file here, but I'm too tired to do it now -- jrb */ - gnome_metadata_set (fpd->file_name, "icon-filename", strlen (text) + 1, text); - else { - /* If text is equal to icon_name it means the user did not - * touch it, not that he did remove it - */ - /* - gnome_metadata_remove (fpd->file_name, "icon-filename"); - */ - } + gnome_metadata_set (fpd->file_name, "icon-filename", strlen (text) + 1, text); g_free (text); } /* I suppose we should only do this if we know there's been a change -- I'll try to figure it diff --git a/gnome/gpageprop.c b/gnome/gpageprop.c index 4aa573590..4edbbc37d 100644 --- a/gnome/gpageprop.c +++ b/gnome/gpageprop.c @@ -94,6 +94,7 @@ item_properties (GtkWidget *parent, char *fname, DesktopIconInfo *dii) file_entry *fe; char *dirname; char *p; + const char *ifile; p = strrchr (fname, PATH_SEP); g_assert (p != NULL); @@ -103,9 +104,11 @@ item_properties (GtkWidget *parent, char *fname, DesktopIconInfo *dii) icon = gicon_get_icon_for_file (dirname, fe, FALSE); g_free (dirname); file_entry_free (fe); - icon_filename = gicon_get_filename_for_icon (icon); - if (icon_filename == NULL) + ifile = gicon_get_filename_for_icon (icon); + if (ifile == NULL) icon_filename = g_strdup (ICONDIR "i-regular.png"); + else + icon_filename = g_strdup (ifile); gene = gprop_general_new (fname, icon_filename); diff --git a/gnome/gprop.c b/gnome/gprop.c index 1bc2b5cc5..00a103ba1 100644 --- a/gnome/gprop.c +++ b/gnome/gprop.c @@ -37,7 +37,7 @@ free_stuff (GtkWidget *widget, gpointer data) /***** Filename *****/ GpropFilename * -gprop_filename_new (char *complete_filename, char *filename) +gprop_filename_new (const char *complete_filename, const char *filename) { GpropFilename *gp; GtkWidget *frame; @@ -475,7 +475,7 @@ change_icon (GtkEntry *entry, GpropGeneral *gp) } GpropGeneral * -gprop_general_new (char *title, char *icon_filename) +gprop_general_new (const char *title, const char *icon_filename) { GpropGeneral *gp; GtkWidget *frame; diff --git a/gnome/gprop.h b/gnome/gprop.h index 709ef0001..4985de525 100644 --- a/gnome/gprop.h +++ b/gnome/gprop.h @@ -22,7 +22,7 @@ typedef struct { GtkWidget *filename; } GpropFilename; -GpropFilename *gprop_filename_new (char *complete_filename, char *filename); +GpropFilename *gprop_filename_new (const char *complete_filename, const char *filename); void gprop_filename_get_data (GpropFilename *gp, char **filename); /***** Permissions *****/ @@ -54,7 +54,7 @@ typedef struct { GtkWidget *icon_pixmap; } GpropGeneral; -GpropGeneral *gprop_general_new (char *title, char *icon_filename); +GpropGeneral *gprop_general_new (const char *title, const char *icon_filename); void gprop_general_get_data (GpropGeneral *gp, char **title, char **icon_filename); typedef struct {