emelfm2 0.1.0 bugs and patches

Hi,

although it was nice to see, that there was a new emelfm2 version, I
never had to fix so many bugs in it, so that it can work on *BSD (better
read: !Linux :-).  The unfortunate usage of GNU extensions causes
emelfm2 not to work (even not to build properly) on a system, which does
not use the GNU libc.

I patched several issues (the patches are attached) and will give you a
list of issues, which cannot be fixed at the moment (due to the lack of
equivalent implementations or similar issues).

Issues:

* Usage of constant THOUSANDS_SEP. THOUSANDS_SEP is not defined in
  POSIX, only THOUSEP is provided there. The THOUSANDS_SEP definition
  seems to be a GNUish definition and should not be used. It causes the
  following sources to break:
  plugins/e2p_du.c, line 187
  src/e2_filelist.c, line 1183

  See also the patch set.

* Constant usage of a TEMP_FAILURE_RETRY macro. It neither exists in
  POSIX nor ANSI and causes several several sources to break:
  src/e2_task_backend.c
  
  Solution: Use an own definition of TEMP_FAILURE_RETRY on demand:
  #ifndef TEMP_FAILURE_RETRY
  #define TEMP_FAILURE_RETRY(expr) \
    ({ long int _res; \
       do _res = (long int) (expr); \
       while (_res == -1L && errno == EINTR); \
       _res; })
  #endif

  I added this macro definition to the e2_task_backend.c file. Maybe
  a header would be the better place for it (see also the patch set).

* Usage of strndup and strdup call. strndup does not exist in ANSI nor
  POSIX nor the FreeBSD libc (it has only strdup) and causes the
  following sources
  to break:
  src/e2_task_backend.c, line 518, 1079ff, 1110ff (strndup, strdup)
  
  The following are unfixed, because it is unknown, whether the variable
  is freed using free() or not:
  src/config/e2_cache.c, line 235 (*str = strdup)
  src/utils/e2_utils.c, line 379 (path = strdup)
  src/filesystems/e2_fs_walk.c, line 284 (parked_dirs = ...)

  Solution: Use either an own implementation, a strncpy/memcpy call or 
  the system independant g_strndup implementation of the glib
  (see also the patch set).

* Usage of getdelim. getdelim does not exist in ANSI nor POSIX nor the
  FreeBSD libc and causes the following sources to break:
  src/dialogs/e2_file_info_dialog.c
  src/filesystem/e2_fs.c

* Usage of mempcpy. mempcpy does not exist in ANSI nor POSIX nor the
  FreeBSD libc and causes the following sources to break:
  src/filesystem/e2_fs_walk.c
  src/utils/e2_utils.c

Until the the last both issues (getdelim and mempcpy) are not fixed, I
cannot update emelfm2 version of the FreeBSD ports or use it on a
FreeBSD system (other BSDs/Unices might have the same problem), so a fix
would be much appreciated.

Regards
Marcus
diff -Nur emelfm2-0.1.0/plugins/e2p_du.c emelfm2-0.1.0.new/plugins/e2p_du.c
--- emelfm2-0.1.0/plugins/e2p_du.c      Fri May 20 15:01:25 2005
+++ emelfm2-0.1.0.new/plugins/e2p_du.c  Thu Jul 21 09:33:54 2005
@@ -184,7 +184,7 @@
        g_list_free (base);
 
        static gchar big[3] = { '1', ',', '\0' };
-       gchar *comma = nl_langinfo (THOUSANDS_SEP);
+       gchar *comma = nl_langinfo (THOUSEP);
        if (comma != NULL && *comma != '\0')
                big[1] = *comma;
        text = g_string_new(_("total size: "));
diff -Nur emelfm2-0.1.0/src/command/e2_command.c 
emelfm2-0.1.0.new/src/command/e2_command.c
--- emelfm2-0.1.0/src/command/e2_command.c      Thu Jun  2 15:06:25 2005
+++ emelfm2-0.1.0.new/src/command/e2_command.c  Thu Jul 21 09:56:11 2005
@@ -27,6 +27,7 @@
 #include "e2_command.h"
 #include <string.h>
 #include <sys/wait.h>
+#include <signal.h>
 #include "e2_alias.h"
 
 GList *children = NULL;
diff -Nur emelfm2-0.1.0/src/e2_filelist.c emelfm2-0.1.0.new/src/e2_filelist.c
--- emelfm2-0.1.0/src/e2_filelist.c     Tue Jun 14 08:55:34 2005
+++ emelfm2-0.1.0.new/src/e2_filelist.c Thu Jul 21 09:34:12 2005
@@ -1179,7 +1179,7 @@
        {
                case 1:
                {
-                       comma = nl_langinfo (THOUSANDS_SEP);
+                       comma = nl_langinfo (THOUSEP);
                        if (comma == NULL || *comma == '\0')
                                comma = ",";
                        break;
diff -Nur emelfm2-0.1.0/src/e2_task_backend.c 
emelfm2-0.1.0.new/src/e2_task_backend.c
--- emelfm2-0.1.0/src/e2_task_backend.c Sun Jun 19 11:53:12 2005
+++ emelfm2-0.1.0.new/src/e2_task_backend.c     Thu Jul 21 10:49:14 2005
@@ -44,6 +44,15 @@
 #include "e2_fs.h"
 #endif
 
+/* Define TEMP_FAILURE_ENTRY on systems, which do not have it. */
+#ifndef TEMP_FAILURE_RETRY
+#define TEMP_FAILURE_RETRY(expr) \
+    ({ long int _res; \
+       do _res = (long int) (expr); \
+       while (_res == -1L && errno == EINTR); \
+       _res; })
+#endif
+
 //this is the deepest level of nested dirs that will be processed
 //NOTE: in general, functions that use nftw() will fail silently if
 //this limit is exceeded in practice
@@ -506,7 +515,7 @@
                dest = e2_utils_strcat (newroot, 
                        (gchar *)filename+strlen (oldroot));
        else
-               dest = strdup (filename);
+               dest = g_strdup (filename);
 
        switch (fileflags)
        {
@@ -1067,9 +1076,9 @@
                        data->oldroot_len = 0;
                eop = strrchr (dest, G_DIR_SEPARATOR);
                if (eop != NULL)
-                       data->newroot = strndup (dest, (eop-dest));
+                       data->newroot = g_strndup (dest, (eop-dest));
                else
-                       data->newroot = strdup (dest);
+                       data->newroot = g_strdup (dest);
                data->dirdata = NULL;
                E2_TwFlags flags = E2TW_DEFAULT;        //breadth-first
                gboolean retval = e2_fs_tw (src, _e2_task_twcb_copy, data, 
E2_DIRNEST_LIMIT, flags);
@@ -1098,22 +1107,22 @@
                //replace the old 'root' with the new one, to make the dest path
                gchar *eop = strrchr (src, G_DIR_SEPARATOR);
                if (eop != NULL)
-                       oldroot = strndup (src, (eop-src));
+                       oldroot = g_strndup (src, (eop-src));
                else
-                       oldroot = strdup (src);
+                       oldroot = g_strdup (src);
                eop = strrchr (dest, G_DIR_SEPARATOR);
                if (eop != NULL)
-                       newroot = strndup (dest, (eop-dest));
+                       newroot = g_strndup (dest, (eop-dest));
                else
-                       newroot = strdup (dest);
+                       newroot = g_strdup (dest);
                dirdata = NULL;
 //             CHECKME depth-first ??
                gint flags = FTW_ACTIONRETVAL;  //breadth-first, detailed 
reporting
                gboolean retval = (!nftw (src, _e2_task_twcb_copy, 
E2_DIRNEST_LIMIT, flags));
 
                //cleanups
-               free (oldroot);
-               free (newroot);
+               g_free (oldroot);
+               g_free (newroot);
 
                if (dirdata != NULL)
                {       //revert new dir permissions, LIFO order

Other related posts: