[easytag] Use GLib POSIX wrapper functions consistently



commit a21d043d7d63bf773be4bf6420d6f321f293c681
Author: David King <amigadave amigadave com>
Date:   Thu Jan 7 17:09:26 2016 +0000

    Use GLib POSIX wrapper functions consistently
    
    As EasyTAG only handles filenames being in the GLib filename encoding,
    be careful to use functions which accept that encoding.

 src/browser.c                  |   18 ++++++++++--------
 src/cddb_dialog.c              |    5 +++--
 src/file.c                     |    4 ++--
 src/file_list.c                |    1 -
 src/tags/ape_tag.c             |    3 ++-
 src/tags/libapetag/apetaglib.c |    5 +++--
 src/tags/libapetag/apetaglib.h |    8 --------
 7 files changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 196e123..6db9fa3 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -29,8 +29,8 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <stdlib.h>
-#include <dirent.h>
 #include <string.h>
 #include <errno.h>
 
@@ -4182,7 +4182,7 @@ static void
 Rename_Directory (EtBrowser *self)
 {
     EtBrowserPrivate *priv;
-    DIR   *dir;
+    GDir *dir;
     gchar *directory_parent;
     gchar *directory_last_name;
     gchar *directory_new_name;
@@ -4278,15 +4278,17 @@ Rename_Directory (EtBrowser *self)
     new_path = g_strconcat(directory_parent, directory_new_name_file, NULL);
     new_path_utf8 = filename_to_display(new_path);
 
-    /* TODO: Replace with g_open_dir() (or more likely g_file_move()). */
+    /* TODO: Replace with g_file_move(). */
     /* Check if the new directory name doesn't already exists, and detect if
      * it's only a case change (needed for vfat) */
-    if ( (dir=opendir(new_path))!=NULL )
+    /* TODO: Handle the GError, such as by checking for G_FILE_ERROR_NOENT. */
+    if ((dir = g_dir_open (new_path, 0, NULL)) != NULL)
     {
         GtkWidget *msgdialog;
         //gint response;
 
-        closedir(dir);
+        g_dir_close (dir);
+
         if (strcasecmp(last_path,new_path) != 0)
         {
     // TODO
@@ -4348,11 +4350,11 @@ Rename_Directory (EtBrowser *self)
     if ( (fd_tmp = mkstemp(tmp_path)) >= 0 )
     {
         close(fd_tmp);
-        unlink(tmp_path);
+        g_unlink (tmp_path);
     }
 
     /* Rename the directory from 'last name' to 'tmp name' */
-    if ( rename(last_path,tmp_path)!=0 )
+    if (g_rename (last_path, tmp_path) != 0)
     {
         GtkWidget *msgdialog;
 
@@ -4381,7 +4383,7 @@ Rename_Directory (EtBrowser *self)
     }
 
     /* Rename the directory from 'tmp name' to 'new name' (final name) */
-    if ( rename(tmp_path,new_path)!=0 )
+    if (g_rename (tmp_path, new_path) != 0)
     {
         GtkWidget *msgdialog;
 
diff --git a/src/cddb_dialog.c b/src/cddb_dialog.c
index a308e37..ee02b7a 100644
--- a/src/cddb_dialog.c
+++ b/src/cddb_dialog.c
@@ -22,6 +22,7 @@
 #include "cddb_dialog.h"
 
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
@@ -785,7 +786,7 @@ Cddb_Write_Result_To_File (EtCDDBDialog *self,
     file_path = g_build_filename (g_get_user_cache_dir (), PACKAGE_TARNAME,
                                   CDDB_RESULT_FILE, NULL);
 
-    if ((file = fopen (file_path, "w+")) != NULL)
+    if ((file = g_fopen (file_path, "w+")) != NULL)
     {
         gchar cddb_out[MAX_STRING_LEN+1];
         gint  bytes_read = 0;
@@ -2949,7 +2950,7 @@ Cddb_Read_Line (FILE **file, gchar **cddb_out)
         file_path = g_build_filename (g_get_user_cache_dir (), PACKAGE_TARNAME,
                                       CDDB_RESULT_FILE, NULL);
 
-        if ((*file = fopen (file_path, "r")) == 0)
+        if ((*file = g_fopen (file_path, "r")) == 0)
         {
             Log_Print (LOG_ERROR, _("Cannot open file ā€˜%sā€™: %s"), file_path,
                        g_strerror (errno));
diff --git a/src/file.c b/src/file.c
index cb61fca..450728e 100644
--- a/src/file.c
+++ b/src/file.c
@@ -21,9 +21,9 @@
 #include "file.h"
 
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <unistd.h>
 #include <utime.h>
 
@@ -1421,7 +1421,7 @@ ET_Save_File_Tag_To_HD (ET_File *ETFile, GError **error)
                                     "file-update-parent-modification-time"))
         {
             gchar *path = g_path_get_dirname (cur_filename);
-            utime (path, NULL);
+            g_utime (path, NULL);
             g_free (path);
         }
 
diff --git a/src/file_list.c b/src/file_list.c
index 70672db..894cd7b 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <utime.h>
 
 #include "application_window.h"
 #include "charset.h"
diff --git a/src/tags/ape_tag.c b/src/tags/ape_tag.c
index dad1fa7..b56ab9a 100644
--- a/src/tags/ape_tag.c
+++ b/src/tags/ape_tag.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <glib/gstdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -56,7 +57,7 @@ ape_tag_read_file_tag (GFile *file,
 
     filename = g_file_get_path (file);
 
-    if ((fp = fopen (filename, "rb")) == NULL)
+    if ((fp = g_fopen (filename, "rb")) == NULL)
     {
         g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                      _("Error while opening file: %s"),
diff --git a/src/tags/libapetag/apetaglib.c b/src/tags/libapetag/apetaglib.c
index d021efc..17074fc 100644
--- a/src/tags/libapetag/apetaglib.c
+++ b/src/tags/libapetag/apetaglib.c
@@ -29,6 +29,7 @@
 #ifndef __BORLANDC__
 #    include <unistd.h>
 #endif
+#include <glib/gstdio.h>
 #include "apetaglib.h"
 #include "../genres.h"
 #include "../win32/win32dep.h"
@@ -816,7 +817,7 @@ apetag_read (apetag *mem_cnt, const char *filename, int flag)
         return ATL_NOINIT;
     }
     
-    fp = fopen (filename, "rb");
+    fp = g_fopen (filename, "rb");
     if (fp == NULL)
         return ATL_FOPEN;
 
@@ -902,7 +903,7 @@ apetag_save (const char *filename, apetag *mem_cnt, int flag)
         return ATL_NOINIT;
     }
 
-    fp = fopen (filename, "rb+");
+    fp = g_fopen (filename, "rb+");
     if (fp == NULL) {
         PRINT_ERR ( "ERROR->apetaglib->apetag_save::fopen (r+)\n");
         return ATL_FOPEN;
diff --git a/src/tags/libapetag/apetaglib.h b/src/tags/libapetag/apetaglib.h
index 15ab8f2..a415313 100644
--- a/src/tags/libapetag/apetaglib.h
+++ b/src/tags/libapetag/apetaglib.h
@@ -33,14 +33,6 @@
 #define index(a,b) strchr(a,b)
 #endif
 
-#ifdef __WIN32__
-#define USE_CHSIZE
-#define strcasecmp(a,b) stricmp(a,b)
-#define index(a,b) strchr(a,b)
-#define S_IRGRP S_IRUSR
-#define S_IWGRP S_IWUSR
-#endif
-
 /**\{*/
 #ifdef APE_TAG_DEBUG
 #define PRINT_D(x) fprintf( stdout, x )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]