"gtk_entry_get_text()" returns a "const char *" - assign the result to
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 31 Dec 2004 00:26:36 +0000 (00:26 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 31 Dec 2004 00:26:36 +0000 (00:26 +0000)
one.

"get_basename()" doesn't modify its argument, and its callers don't
modify the substring pointed to by the result, so make it take a "const
char *" as an argument and return a "const char *".

"find_last_pathname_separator()" doesn't modify its argument, so make it
a "const char *" - but some of its callers pass a non-"const" "char *"
and modify the result, so don't make its return value a "const char *".
And, as none of its callers are outside "filesystem.c", make it static.

In "about_folders_page_new()", have separate variables for pathnames
returned as "const char *" (which are cached by the routine that returns
them, so you can't modify them - and can't free them, so get rid of the
commented-out "g_free()" calls for them) and pathnames returned as "char
*" (which are allocated anew for each call, and can be modified, but
have to be freed).

Clean up white space.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@12881 f5534014-38df-0310-8fa8-9805f1628bb7

14 files changed:
epan/filesystem.c
epan/filesystem.h
file.c
file.h
gtk/about_dlg.c
gtk/dcerpc_stat.c
gtk/fc_stat.c
gtk/file_dlg.c
gtk/io_stat.c
gtk/ldap_stat.c
gtk/main.c
gtk/rpc_stat.c
gtk/smb_stat.c
gtk/tap_dfilter_dlg.c

index bf559bbab2727c4daedc2a925e2ab643de117905..212f4a5f6c6a731a029b0cabd0a2c3b3daad37f7 100644 (file)
@@ -60,8 +60,8 @@
  * character in the pathname, or NULL if the pathname contains no
  * separators.
  */
-char *
-find_last_pathname_separator(char *path)
+static char *
+find_last_pathname_separator(const char *path)
 {
        char *separator;
 
@@ -72,7 +72,7 @@ find_last_pathname_separator(char *path)
         * We have to scan for '\' or '/'.
         * Get to the end of the string.
         */
-       separator = path + strlen(path);        /* points to ending '\0' */
+       separator = strchr(path, '\0');         /* points to ending '\0' */
        while (separator > path) {
                c = *--separator;
                if (c == '\\' || c == '/')
@@ -93,10 +93,10 @@ find_last_pathname_separator(char *path)
 /*
  * Given a pathname, return the last component.
  */
-char *
-get_basename(char *path)
+const char *
+get_basename(const char *path)
 {
-       char *filename;
+       const char *filename;
 
        g_assert(path != NULL);
        filename = find_last_pathname_separator(path);
index 4f013f66bd5763aa8428e47bbaed0f8e01792e7b..d965c263001d4901c211d5b2c139c9f248e09f10 100644 (file)
 #ifndef FILESYSTEM_H
 #define FILESYSTEM_H
 
-/*
- * Given a pathname, return a pointer to the last pathname separator
- * character in the pathname, or NULL if the pathname contains no
- * separators.
- */
-char *find_last_pathname_separator(char *);
-
 /*
  * Given a pathname, return the last component.
  */
-char *get_basename(char *);
+const char *get_basename(const char *);
 
 /*
  * Given a pathname, return a string containing everything but the
diff --git a/file.c b/file.c
index 44a040aaa661cbf71b1b50a1e4be7fb0f72996b1..a57bd0d033f42c60ff65358aac2363fa0b9a017b 100644 (file)
--- a/file.c
+++ b/file.c
@@ -301,14 +301,14 @@ cf_close(capture_file *cf)
 static void
 set_display_filename(capture_file *cf)
 {
-  gchar  *name_ptr;
-  size_t  msg_len;
+  const gchar *name_ptr;
+  size_t       msg_len;
   static const gchar done_fmt_nodrops[] = " File: %s %s %02u:%02u:%02u";
   static const gchar done_fmt_drops[] = " File: %s %s %02u:%02u:%02u Drops: %u";
-  gchar  *done_msg;
-  gchar  *win_name_fmt = "%s - Ethereal";
-  gchar  *win_name;
-  gchar  *size_str;
+  gchar       *done_msg;
+  gchar       *win_name_fmt = "%s - Ethereal";
+  gchar       *win_name;
+  gchar       *size_str;
 
   name_ptr = cf_get_display_name(cf);
        
@@ -345,28 +345,29 @@ set_display_filename(capture_file *cf)
 read_status_t
 cf_read(capture_file *cf)
 {
-  int        err;
-  gchar      *err_info;
-  gchar      *name_ptr, *load_msg, *load_fmt = "%s";
-  char       *errmsg;
-  char        errmsg_errno[1024+1];
-  gchar       err_str[2048+1];
-  long        data_offset;
-  progdlg_t  *progbar = NULL;
-  gboolean    stop_flag;
+  int         err;
+  gchar       *err_info;
+  const gchar *name_ptr;
+  gchar       *load_msg, *load_fmt = "%s";
+  char        *errmsg;
+  char         errmsg_errno[1024+1];
+  gchar        err_str[2048+1];
+  long         data_offset;
+  progdlg_t   *progbar = NULL;
+  gboolean     stop_flag;
   /*
    * XXX - should be "off_t", but Wiretap would need more work to handle
    * the full size of "off_t" on platforms where it's more than a "long"
    * as well.
    */
-  long        file_pos;
-  float       prog_val;
-  int         fd;
-  struct stat cf_stat;
-  GTimeVal    start_time;
-  gchar       status_str[100];
-  int         progbar_nextstep;
-  int         progbar_quantum;
+  long         file_pos;
+  float        prog_val;
+  int          fd;
+  struct stat  cf_stat;
+  GTimeVal     start_time;
+  gchar        status_str[100];
+  int          progbar_nextstep;
+  int          progbar_quantum;
 
   cum_bytes=0;
   reset_tap_listeners();
@@ -682,10 +683,10 @@ cf_finish_tail(capture_file *cf, int *err)
 }
 #endif /* HAVE_LIBPCAP */
 
-gchar *
+const gchar *
 cf_get_display_name(capture_file *cf)
 {
-  gchar *displayname;
+  const gchar *displayname;
 
   /* Return a name to use in displays */
   if (!cf->is_tempfile) {
@@ -3042,7 +3043,8 @@ gboolean
 cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format)
 {
   gchar        *from_filename;
-  gchar        *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
+  const gchar  *name_ptr;
+  gchar        *save_msg, *save_fmt = " Saving: %s...";
   size_t        msg_len;
   int           err;
   gboolean      do_copy;
diff --git a/file.h b/file.h
index f3ab319bca70700ebcc5c7e8d165edf4562415a2..0b91efff865e76a0ad95fa26c7696db73b44a93c 100644 (file)
--- a/file.h
+++ b/file.h
@@ -51,7 +51,7 @@ read_status_t cf_continue_tail(capture_file *, int, int *);
 read_status_t cf_finish_tail(capture_file *, int *);
 /* size_t read_frame_header(capture_file *); */
 gboolean cf_save(char *fname, capture_file * cf, packet_range_t *range, guint save_format);
-gchar *cf_get_display_name(capture_file *);
+const gchar *cf_get_display_name(capture_file *);
 
 gboolean
 cf_merge_files(const char *out_filename, int out_fd, int in_file_count,
index f2bff7f274c6ae1c416f8f8407b46a50c7eb414e..d23699346115f5387efe84943aa7dec3055c51f0 100644 (file)
@@ -204,11 +204,11 @@ static GtkWidget *
 about_folders_page_new(void)
 {
   GtkWidget   *table;
-  const char *path;
+  const char *constpath;
+  char *path;
   gchar *titles[] = { "Name", "Folder", "Typical Files"};
   GtkWidget *scrolledwindow;
 
-
   scrolledwindow = scrolled_window_new(NULL, NULL);
 #if GTK_MAJOR_VERSION >= 2
   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), 
@@ -235,20 +235,18 @@ about_folders_page_new(void)
   g_free((void *) path);
 
   /* global conf */
-  path = get_datafile_dir();
-  about_folders_row(table, "Global configuration", path,
+  constpath = get_datafile_dir();
+  about_folders_row(table, "Global configuration", constpath,
       "\"dfilters\", \"preferences\", \"manuf\", ...");
-  /*g_free(path);*/
 
   /* system */
-  path = get_systemfile_dir();
-  about_folders_row(table, "System", path,
+  constpath = get_systemfile_dir();
+  about_folders_row(table, "System", constpath,
       "\"ethers\", \"ipxnets\"");
-  /*g_free(path);*/
 
   /* program */
   path = g_strdup(ethereal_path);
-  path = get_dirname((char *) path);
+  path = get_dirname(path);
   about_folders_row(table, "Program", path,
       "program files");
   g_free((void *) path);
index e9a532c37be193f13ae756d4c169fbab3a4c1afd..6c0d67cdc9dff92896948c9af436d55623898de0 100644 (file)
@@ -352,7 +352,7 @@ static void
 dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("dcerpc,srt");
        g_string_sprintfa(str,
@@ -364,7 +364,7 @@ dcerpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
            dcerpc_uuid_program->Data4[4], dcerpc_uuid_program->Data4[5],
            dcerpc_uuid_program->Data4[6], dcerpc_uuid_program->Data4[7],
            dcerpc_version, 0);
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str, ",%s", filter);
        }
index 13d9c94046afdd2e2e0fcdd4b2f18ee3d0953250..8e177effc119457e2af835a3a622da3ef7397f2b 100644 (file)
@@ -214,10 +214,10 @@ static void
 fcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("fc,srt");
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str,",%s", filter);
        }
index e4ecd5990f2a97812951f4f8f4e25196460dda99..c43e398091ce6ab44a1b9957a28b20bde3ffab2a 100644 (file)
@@ -161,7 +161,7 @@ preview_set_filename(GtkWidget *prev, const gchar *cf_name)
     }
 
     label = OBJECT_GET_DATA(prev, PREVIEW_FILENAME_KEY);
-    gtk_label_set_text(GTK_LABEL(label), get_basename((char *)cf_name));
+    gtk_label_set_text(GTK_LABEL(label), get_basename(cf_name));
 
     if (test_for_directory(cf_name) == EISDIR) {
         label = OBJECT_GET_DATA(prev, PREVIEW_FORMAT_KEY);
@@ -645,10 +645,11 @@ file_open_cmd_cb(GtkWidget *widget, gpointer data _U_) {
 /* user pressed "open" button */
 static void
 file_open_ok_cb(GtkWidget *w, gpointer fs) {
-  gchar     *cf_name, *rfilter, *s;
-  GtkWidget *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
-  dfilter_t *rfcode = NULL;
-  int        err;
+  gchar       *cf_name, *s;
+  const gchar *rfilter;
+  GtkWidget   *filter_te, *m_resolv_cb, *n_resolv_cb, *t_resolv_cb;
+  dfilter_t   *rfcode = NULL;
+  int          err;
 
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@@ -656,7 +657,7 @@ file_open_ok_cb(GtkWidget *w, gpointer fs) {
   cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
 #endif
   filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
-  rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
+  rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
   if (!dfilter_compile(rfilter, &rfcode)) {
     bad_dfilter_alert_box(rfilter);
     g_free(cf_name);
@@ -992,14 +993,15 @@ file_merge_cmd_cb(GtkWidget *widget, gpointer data _U_) {
 
 static void
 file_merge_ok_cb(GtkWidget *w, gpointer fs) {
-  gchar     *cf_name, *rfilter, *s;
-  GtkWidget *filter_te, *rb;
-  dfilter_t *rfcode = NULL;
-  int        err;
-  gboolean   merge_ok;
-  char      *in_filenames[2];
-  int        out_fd;
-  char       tmpname[128+1];
+  gchar       *cf_name, *s;
+  const gchar *rfilter;
+  GtkWidget   *filter_te, *rb;
+  dfilter_t   *rfcode = NULL;
+  int          err;
+  gboolean     merge_ok;
+  char        *in_filenames[2];
+  int          out_fd;
+  char         tmpname[128+1];
 
 #if (GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 4) || GTK_MAJOR_VERSION > 2
   cf_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs)));
@@ -1007,7 +1009,7 @@ file_merge_ok_cb(GtkWidget *w, gpointer fs) {
   cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
 #endif
   filter_te = OBJECT_GET_DATA(w, E_RFILTER_TE_KEY);
-  rfilter = (gchar *)gtk_entry_get_text(GTK_ENTRY(filter_te));
+  rfilter = gtk_entry_get_text(GTK_ENTRY(filter_te));
   if (!dfilter_compile(rfilter, &rfcode)) {
     bad_dfilter_alert_box(rfilter);
     g_free(cf_name);
index 4659a125c349cc9d5318b1228b2543d0e542d8da..3fbcd1b06df1a994328acc7a71fc14528274d0c3 100644 (file)
@@ -979,7 +979,7 @@ gtk_iostat_draw(void *g)
    pruned 
 */
 static GString *
-enable_graph(io_stat_graph_t *gio, char *filter, char *field)
+enable_graph(io_stat_graph_t *gio, const char *filter, const char *field)
 {
        char real_filter[260];
 
@@ -1505,12 +1505,12 @@ create_ctrl_area(io_stat_t *io, GtkWidget *box)
 static gint
 filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
 {
-       char *filter;
-       char *field;
+       const char *filter;
+       const char *field;
        header_field_info *hfi;
        dfilter_t *dfilter;
 
-       field=(char *)gtk_entry_get_text(GTK_ENTRY(gio->calc_field));
+       field=gtk_entry_get_text(GTK_ENTRY(gio->calc_field));
 
        /* this graph is not active, just update display and redraw */
        if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gio->display_button))){
@@ -1612,7 +1612,7 @@ filter_callback(GtkWidget *widget _U_, io_stat_graph_t *gio)
        }
 
        /* first check if the filter string is valid. */
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
+       filter=gtk_entry_get_text(GTK_ENTRY(gio->filter_field));
        if(!dfilter_compile(filter, &dfilter)) {
                bad_dfilter_alert_box(filter);
                disable_graph(gio);
index c63497cb6f50798014cb96bfbf9ac72a517bb646..9e040685308e786bdf1de3f744780d064df59f70 100644 (file)
@@ -249,10 +249,10 @@ static void
 ldapstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("ldap,srt");
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str,",%s", filter);
        }
index b05076a09885e0e87a0c76d54728d7c678392a75..87032f41257ec5d5d28d8a5534361d63e12e38a3 100644 (file)
@@ -1525,7 +1525,7 @@ int
 main(int argc, char *argv[])
 {
 #ifdef HAVE_LIBPCAP
-  char                *command_name;
+  const char          *command_name;
 #endif
   char                *s;
   int                  i;
index 31f58edd23824e9ba49418bcc9df90cc965bda85..004f3a3cd950104cedb988fe2534622121c9f2de 100644 (file)
@@ -316,11 +316,11 @@ static void
 rpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("rpc,srt");
        g_string_sprintfa(str, ",%d,%d", rpc_program, rpc_version);
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str, ",%s", filter);
        }
index c9197e32cf4b81fbae4abc02b726e2d679938eac..97ea3497d6dba4fab2e0871073e4159e3272b4cc 100644 (file)
@@ -252,10 +252,10 @@ static void
 smbstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
 {
        GString *str;
-       char *filter;
+       const char *filter;
 
        str = g_string_new("smb,srt");
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(filter_entry));
        if(filter[0]!=0){
                g_string_sprintfa(str,",%s", filter);
        }
index 9cf5671eba64206c54b5388bcc629f77c816de4c..be713cd8367aa37b140a94b52057f89508133dbf 100644 (file)
@@ -85,16 +85,16 @@ dlg_destroy_cb(GtkWidget *item _U_, gpointer dialog_data)
 static void
 tap_dfilter_dlg_start_button_clicked(GtkWidget *item _U_, gpointer dialog_data)
 {
-       char *filter;
+       const char *filter;
        char str[256];
        
        tap_dfilter_dlg_list_item *dlg_data = (tap_dfilter_dlg_list_item *) dialog_data;
 
-       filter=(char *)gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
+       filter=gtk_entry_get_text(GTK_ENTRY(dlg_data->filter_entry));
        if(filter[0]==0){
                g_snprintf(str, sizeof(str), "%s", dlg_data->cont.init_string);
        } else {
-               g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);              
+               g_snprintf(str, sizeof(str), "%s,%s", dlg_data->cont.init_string, filter);
        }
        (dlg_data->cont.tap_init_cb)(str);
 }