POSIX incompatible strndup() usage

  • From: Marcus von Appen <mva@xxxxxxxxxxxx>
  • To: emelfm2 <emelfm2@xxxxxxxxxxxxx>
  • Date: Thu, 3 Apr 2008 15:29:21 +0200

Hi,

does it have a specific reason that you are using the GNU libc specific
strndup() call in plugins/e2p_crypt.c and
src/command/complete/e2_complete__path.c instead of g_strndup() from
glib2?  If not, please change it to g_strndup(), so it can be used
without much patching on !Linux operating systems :-).

A patch is attached.

Regards
Marcus
diff -ur f/emelfm2-0.4/plugins/e2p_crypt.c emelfm2-0.4/plugins/e2p_crypt.c
--- f/emelfm2-0.4/plugins/e2p_crypt.c   2007-11-22 22:23:11.000000000 +0100
+++ emelfm2-0.4/plugins/e2p_crypt.c     2008-04-03 15:18:20.000000000 +0200
@@ -1545,7 +1546,7 @@
        {
                sep = strchr (execpath, ':');   //ascii scan ok
                if (sep != NULL)
-                       execpath = strndup (execpath, sep-execpath);
+                       execpath = g_strndup (execpath, sep-execpath);
                //FIXME preserve execpath so that later members can be used
        }
 #ifdef E2_VFS
diff -ur f/emelfm2-0.4/src/command/complete/e2_complete__path.c 
emelfm2-0.4/src/command/complete/e2_complete__path.c
--- f/emelfm2-0.4/src/command/complete/e2_complete__path.c      2008-03-22 
03:58:43.000000000 +0100
+++ emelfm2-0.4/src/command/complete/e2_complete__path.c        2008-04-03 
15:15:09.000000000 +0200
@@ -147,7 +147,7 @@
        {
                gchar *p1, *p2, *localpath;
                p1 = g_utf8_next_char (strrchr (word, G_DIR_SEPARATOR));        
//the 'real' word to complete
-               p2 = strndup (word, p1 - word); //prefix for matches
+               p2 = g_strndup (word, p1 - word);       //prefix for matches
                if (word[0] == G_DIR_SEPARATOR)
                {       //word is an absolute path string
                        localpath = F_FILENAME_TO_LOCALE (p2);

Other related posts: