So... I applied my search-and-replace skills, and the attached patch came out. You should notice that most of the changes are replacements of blah(...) with g_blah(...). I also altered the meaning of the block of #define's as noted in my other post.

HOWEVER! There are two BIG catches:

1) I didn't test it. Lame, I know, but setting up the environment for compilation is too much work. Since I didn't make any significant structural changes, it should compile, and since the g_ functions are equivalent to plain functions on Unix, there should be no behavioural differences on that platform. If anybody who can compile a Windows build does so, I'll be grateful.

2) Unfortunately, this patch is not enough. First of all, there is "uulib" which uses fopen, but doesn't use Glib. I don't know how is it used, so I'm unable to predict what consequences it entails. Second, and much more important, is the usage of C++ streams throughout Pan. Obviously, Glib doesn't include wrappers for them, so the half of the I/O that uses streams is still broken. Fixing it is possible, but the only solution I see is writing a g_fopen-like wrapper for fstream::open, and changing the code to use it. Possible, but tedious.

Opinions?

Roman.
Index: pan/gui/post-ui.cc
===================================================================
--- pan/gui/post-ui.cc  (revision 362)
+++ pan/gui/post-ui.cc  (working copy)
@@ -801,7 +801,7 @@
  }

  // cleanup
-  ::remove (fname);
+  g_remove (fname);
  g_free (fname);
  g_strfreev (argv);

Index: pan/gui/group-prefs.cc
===================================================================
--- pan/gui/group-prefs.cc      (revision 362)
+++ pan/gui/group-prefs.cc      (working copy)
@@ -127,7 +127,7 @@
    out << "</group>\n";
  }
  out.close ();
-  chmod (_filename.c_str(), 0600);
+  g_chmod (_filename.c_str(), 0600);
}

namespace
Index: pan/gui/gui.cc
===================================================================
--- pan/gui/gui.cc      (revision 362)
+++ pan/gui/gui.cc      (working copy)
@@ -342,7 +342,7 @@
{
  const std::string accel_filename (get_accel_filename());
  gtk_accel_map_save (accel_filename.c_str());
-  chmod (accel_filename.c_str(), 0600);
+  g_chmod (accel_filename.c_str(), 0600);

  if (hpane)
    _prefs.set_int ("main-window-hpane-position", 
gtk_paned_get_position(GTK_PANED(hpane)));
Index: pan/gui/prefs-file.cc
===================================================================
--- pan/gui/prefs-file.cc       (revision 362)
+++ pan/gui/prefs-file.cc       (working copy)
@@ -62,5 +62,5 @@
      << s
      << "</preferences>\n";
  out.close ();
-  chmod (_filename.c_str(), 0600);
+  g_chmod (_filename.c_str(), 0600);
}
Index: pan/tasks/decoder.cc
===================================================================
--- pan/tasks/decoder.cc        (revision 362)
+++ pan/tasks/decoder.cc        (working copy)
@@ -101,7 +101,7 @@
        file :: ensure_dir_exists (save_path.c_str());
        gchar * basename (g_path_get_basename (it->c_str()));
        gchar * filename (g_build_filename (save_path.c_str(), basename, NULL));
-        FILE * fp = fopen (filename, "w+");
+        FILE * fp = g_fopen (filename, "w+");

        mut.lock();
        current_file = filename;
Index: pan/data-impl/server.cc
===================================================================
--- pan/data-impl/server.cc     (revision 362)
+++ pan/data-impl/server.cc     (working copy)
@@ -52,7 +52,7 @@
    const std::string newsrc_filename (_servers[server].newsrc_filename);
    _servers.erase (server);
    save_server_properties (*_data_io);
-    std::remove (newsrc_filename.c_str());
+    g_remove (newsrc_filename.c_str());
    rebuild_backend ();
  }
}
Index: pan/data-impl/headers.cc
===================================================================
--- pan/data-impl/headers.cc    (revision 362)
+++ pan/data-impl/headers.cc    (working copy)
@@ -970,7 +970,7 @@
    std::ofstream o (filename.c_str(), std::ofstream::app|std::ofstream::out);
    o << '\n' << str << '\n';
    o.close ();
-    ::chmod (filename.c_str(), 0600);
+    g_chmod (filename.c_str(), 0600);
  }

  if (do_rescore)
@@ -1003,7 +1003,7 @@
  std::ofstream o (f.c_str(), std::ofstream::trunc|std::ofstream::out);
  o << buf;
  o.close ();
-  ::chmod (f.c_str(), 0600);
+  g_chmod (f.c_str(), 0600);

  // rescore
  if (do_rescore)
Index: pan/data-impl/data-io.cc
===================================================================
--- pan/data-impl/data-io.cc    (revision 362)
+++ pan/data-impl/data-io.cc    (working copy)
@@ -124,7 +124,7 @@
DataIO :: clear_group_headers (const Quark& group)
{
  const std::string filename (get_group_headers_filename (group));
-  std::remove (filename.c_str());
+  g_remove (filename.c_str());
}

/****
@@ -202,14 +202,14 @@

    const std::string tmpfile (filename + ".tmp");
    if (ok) {
-      unlink (filename.c_str());
-      if (rename (tmpfile.c_str(), filename.c_str()))
+      g_unlink (filename.c_str());
+      if (g_rename (tmpfile.c_str(), filename.c_str()))
        std::cerr << LINE_ID << " ERROR renaming from [" << tmpfile << "] to [" << filename << 
"]: " << g_strerror(errno) << '\n';
-      if (chmod (filename.c_str(), 0600))
+      if (g_chmod (filename.c_str(), 0600))
        std::cerr << LINE_ID << " ERROR chmodding [" << filename << "]: " << 
g_strerror(errno) << '\n';
    } else {
      Log::add_err_va (_("Unable to save \"%s\" %s"), filename.c_str(), 
file::pan_strerror(my_errno));
-      ::remove (tmpfile.c_str());
+      g_remove (tmpfile.c_str());
    }
  }
}
Index: pan/data-impl/profiles.cc
===================================================================
--- pan/data-impl/profiles.cc   (revision 362)
+++ pan/data-impl/profiles.cc   (working copy)
@@ -293,7 +293,7 @@
  std::ofstream out (f.c_str());
  serialize (out);
  out.close ();
-  ::chmod (f.c_str(), 0600);
+  g_chmod (f.c_str(), 0600);
}

ProfilesImpl :: ~ProfilesImpl ()
Index: pan/data/article-cache.cc
===================================================================
--- pan/data/article-cache.cc   (revision 362)
+++ pan/data/article-cache.cc   (working copy)
@@ -156,7 +156,7 @@
      {
         struct stat stat_p;
         g_snprintf (filename, sizeof(filename), "%s%c%s", _path.c_str(), 
G_DIR_SEPARATOR, fname);
-         if (!stat (filename, &stat_p))
+         if (!g_stat (filename, &stat_p))
         {
            char str[2048];
            const int len (filename_to_message_id (str, sizeof(str), fname));
@@ -229,7 +229,7 @@
  FILE * fp = 0;
  char filename[PATH_MAX];
  if (get_filename (filename, sizeof(filename), message_id))
-    fp = fopen (filename, "wb+");
+    fp = g_fopen (filename, "wb+");

  if (!fp)
  {
@@ -322,7 +322,7 @@
      if (_locks.find(mid) == _locks.end()) {
        char buf[PATH_MAX];
        get_filename (buf, sizeof(buf), mid);
-        unlink (buf);
+        g_unlink (buf);
        _current_bytes -= it->_size;
        removed.insert (mid);
        debug ("removing [" << mid << "] as we resize the queue");
@@ -355,7 +355,7 @@
   if (get_filename (filename, sizeof(filename), mid))
   {
      errno = 0;
-      FILE * fp = fopen (filename, "rb");
+      FILE * fp = g_fopen (filename, "rb");
      if (!fp)
         Log::add_err_va (_("Error opening file \"%s\" %s"), filename, 
file::pan_strerror(errno));
      else {
Index: pan/general/line-reader.cc
===================================================================
--- pan/general/line-reader.cc  (revision 362)
+++ pan/general/line-reader.cc  (working copy)
@@ -19,7 +19,7 @@
  _end (_buf),
  _pos (_buf),
  _alloc_size (INITIAL_BUF_SIZE),
-  _fp (fopen (filename.to_string().c_str(), "rb"))
+  _fp (g_fopen (filename.to_string().c_str(), "rb"))
{
}

Index: pan/general/file-util.h
===================================================================
--- pan/general/file-util.h     (revision 362)
+++ pan/general/file-util.h     (working copy)
@@ -35,6 +35,12 @@
extern "C" {
  #include <glib/gstdio.h>
}
+
+#if !GLIB_CHECK_VERSION(2,8,0)
+#define g_chmod chmod
+#else
+
+#else // fall back to libc equivalents
#define g_freopen freopen
#define g_fopen fopen
#define g_rmdir rmdir
@@ -42,6 +48,7 @@
#define g_unlink unlink
#define g_lstat lstat
#define g_stat stat
+#define g_mkdir mkdir
#define g_rename rename
#define g_open open
#endif
Index: pan/general/file-util.cc
===================================================================
--- pan/general/file-util.cc    (revision 362)
+++ pan/general/file-util.cc    (working copy)
@@ -90,13 +90,7 @@
  else
  {
    errno = 0;
-#if GLIB_CHECK_VERSION(2,6,0)
    retval = g_mkdir (path, mode);
-#elif defined(G_OS_WIN32)
-    retval = mkdir (path);
-#else
-    retval = mkdir (path, mode);
-#endif
    if (errno == EEXIST)
      retval = 0;
  }
_______________________________________________
Pan-users mailing list
Pan-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/pan-users

Reply via email to