permisiions string

  • From: David Jensen <david567@xxxxxxxxxxxxxx>
  • To: emelfm2@xxxxxxxxxxxxx <emelfm2@xxxxxxxxxxxxx>
  • Date: Fri, 2 May 2008 12:12:58 -0500

Attached is a patch to simplify e2_fs_get_perm_string:
It compiles to nearly half the size.

The string is treated as ascii in e2_filelist.c.  Should it be
really enclosed _()?

FWIW
David Jensen
--- emelfm2-0.4/src/filesystem/e2_fs.c  2008-02-18 18:22:09.000000000 -0600
+++ emelfm2-0.4.new/src/filesystem/e2_fs.c      2008-05-02 11:56:52.000000000 
-0500
@@ -2792,22 +2792,16 @@
 */
 void e2_fs_get_perm_string (gchar *buf, gint len, mode_t mode)
 {
-       gchar *perm_sets[8];
-       perm_sets[0] = _("---");
-       perm_sets[1] = _("--x");
-       perm_sets[2] = _("-w-");
-       perm_sets[3] = _("-wx");
-       perm_sets[4] = _("r--");
-       perm_sets[5] = _("r-x");
-       perm_sets[6] = _("rw-");
-       perm_sets[7] = _("rwx");
-
-       gint u, g, o;
-       u = (mode & S_IRWXU) >> 6;
-       g = (mode & S_IRWXG) >> 3;
-       o = (mode & S_IRWXO);
+       g_snprintf (buf, len, _("-rwxrwxrwx"));
+
+       gint mask = 1;
+       gint i;
+       for (i = 9; i > 1; --i) {
+               if (!(mode & mask))
+                       buf[i] = '-';
+               mask = mask << 1;
+       }
 
-       g_snprintf (buf, len, "-%s%s%s", perm_sets[u], perm_sets[g], 
perm_sets[o]);
 
        //_I( FIXME the things below do not suppport translation !!
        if (S_ISLNK(mode))

Other related posts: