Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 592601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:45:24+00:00 2026-05-13T15:45:24+00:00

I’m trying to use g_rename and compiler gives me strange message error: called object

  • 0

I’m trying to use g_rename and compiler gives me strange message error: called object ‘rename’ is not a function for line in code

if (g_rename(old_file_name, full_new_file_name) == -1)

I don’t understand why.

I’m compiling with command

cc -Wall -g `pkg-config --cflags --libs gtk+-2.0` app.c -o app

Gcc version = gcc (Ubuntu 4.4.1-4ubuntu8) 4.4.1

Gtk+ version = 2.18.3-1ubuntu


Here is the full code:

#include <gtk/gtk.h>
#include <string.h>
#include <glib.h>
#include <glib/gstdio.h>

void
destroy (GtkWidget*, gpointer);
void
file_chooser_file_set(GtkWidget*, gpointer);

void
rename_clicked(GtkWidget*, gpointer);

int main (int argc, char* argv[]){
  GtkWidget *window, *vbox, *hbox, *rename, *text_rename, *file_chooser;

  gtk_init (&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "File renamer");
  g_signal_connect(G_OBJECT(window),
                    "destroy",
                    G_CALLBACK(destroy),
                    NULL);

  vbox = gtk_vbox_new(FALSE, 5);

  file_chooser = gtk_file_chooser_button_new("Choose file to rename:", GTK_FILE_CHOOSER_ACTION_OPEN);
  g_signal_connect(G_OBJECT(file_chooser),
                    "file-set",
                    G_CALLBACK(file_chooser_file_set),
                    NULL);

  gtk_box_pack_start(GTK_BOX(vbox),
                      GTK_WIDGET(file_chooser),
                      TRUE,
                      FALSE,
                      5);

  hbox = gtk_hbox_new(FALSE, 5);

  rename = gtk_button_new_with_label("Rename");

  gtk_box_pack_end(GTK_BOX(hbox),
                      GTK_WIDGET(rename),
                      FALSE,
                      FALSE,
                      5);

  text_rename = gtk_entry_new();
  g_signal_connect(G_OBJECT(rename),
                    "clicked",
                    G_CALLBACK(rename_clicked),
                    text_rename);
  gtk_box_pack_start(GTK_BOX(hbox),
                      GTK_WIDGET(text_rename),
                      TRUE,
                      TRUE,
                      5);

  gtk_box_pack_start(GTK_BOX(vbox),
                      GTK_WIDGET(hbox),
                      FALSE,
                      FALSE,
                      5);

  gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox));
  gtk_widget_show_all(GTK_WIDGET(window));

  g_object_set_data(G_OBJECT(file_chooser),
                    "text_rename",
                    (gpointer) text_rename);
  g_object_set_data(G_OBJECT(file_chooser),
                    "rename",
                    (gpointer) rename);

  g_object_set_data(G_OBJECT(rename),
                    "file_chooser",
                    (gpointer)file_chooser);
  gtk_main();

  return 0;
}

#define _CHECK_FATAL_ERROR( e )\
  if ( (e) ) { \
    g_error("Fatal error: %s", (e)->message); \
    g_error_free( (e) );\
  }

#define _PATH_BUFFER_LENGTH 200
void
rename_clicked(GtkWidget* rename, gpointer text_entry) {
  gchar *new_file_name;
  gchar *old_file_name;
  gchar *full_new_file_name = g_new0(gchar, _PATH_BUFFER_LENGTH);
  GtkFileChooserButton *file_chooser;

  GError *error = NULL;

  GRegex *remove_file_name;

  remove_file_name = g_regex_new("/[^/]+$",
                                0,
                                0,
                                &error);
  _CHECK_FATAL_ERROR( error );


  file_chooser = GTK_FILE_CHOOSER_BUTTON(g_object_get_data(G_OBJECT(rename), "file_chooser"));

  new_file_name = g_strdup( gtk_entry_get_text(GTK_ENTRY(text_entry)) );
  old_file_name = g_strdup(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_chooser)));
  if ( !( new_file_name && old_file_name ) )
    g_error("Error while allocating memory!");

  /*BEGIN*/
  /* full_new_file_name = dirname( old_file_name ) . new_file_name */
    gchar *path;

    path = g_regex_replace(remove_file_name,
                            old_file_name,
                            strlen(old_file_name),
                            0,
                            "/",
                            0,
                            &error);
    _CHECK_FATAL_ERROR( error );

    //Path
    full_new_file_name[0] = 0;
    g_strlcat(full_new_file_name, path, _PATH_BUFFER_LENGTH);
    //name
    g_strlcat(full_new_file_name, new_file_name, _PATH_BUFFER_LENGTH);
//    g_print("Full file name: %s\n", full_new_file_name);
    g_free( path );
  /*END*/

  if (g_rename(old_file_name, full_new_file_name) == -1)
    g_error("Error while renaming %s to %s", old_file_name, full_new_file_name);

  gtk_widget_set_sensitive(GTK_WIDGET(rename), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(text_entry), FALSE);

  g_free( new_file_name );
  g_free( full_new_file_name );
  g_free( old_file_name );
  g_regex_unref( remove_file_name );
}

void
file_chooser_file_set(GtkWidget* file_chooser, gpointer null) {
  GtkButton *rename;
  GtkEntry  *text_rename;

  rename      = GTK_BUTTON(g_object_get_data(G_OBJECT(file_chooser),
                                             "rename") );
  text_rename = GTK_ENTRY(g_object_get_data(G_OBJECT(file_chooser),
                                            "text_rename"));

  gtk_widget_set_sensitive(GTK_WIDGET(rename), TRUE);
  gtk_widget_set_sensitive(GTK_WIDGET(text_rename), TRUE);
}

void destroy (GtkWidget* widget, gpointer data) {
  gtk_main_quit();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:45:24+00:00Added an answer on May 13, 2026 at 3:45 pm

    First of all you need to have libgtk2.0-dev and glibc-dev installed on your machine.
    On Unix systems g_rename is by default an alias for the C library function rename.
    You need to #include <stdio.h> to be able to use the rename function without getting that error. What you’re seeing is really a bug in the gstdio.h header file which should include stdio.h for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.