emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs/src dired.c


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs/src dired.c
Date: Fri, 20 Mar 2009 17:58:10 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Eli Zaretskii <eliz>    09/03/20 17:58:10

Modified files:
        src            : dired.c 

Log message:
        (make_uid, make_gid): New functions.
        (Ffile_attributes): Use them to avoid negative UID and GID.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/src/dired.c?cvsroot=emacs&r1=1.161&r2=1.162

Patches:
Index: dired.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/dired.c,v
retrieving revision 1.161
retrieving revision 1.162
diff -u -b -r1.161 -r1.162
--- dired.c     18 Mar 2009 20:37:34 -0000      1.161
+++ dired.c     20 Mar 2009 17:58:10 -0000      1.162
@@ -894,6 +894,29 @@
 #endif
 }
 
+/* Make an integer or float number for UID and GID, while being
+   careful not to produce negative numbers due to signed integer
+   overflow.  */
+static Lisp_Object
+make_uid (struct stat *st)
+{
+  EMACS_INT uid = st->st_uid;
+
+  if (sizeof (st->st_uid) > sizeof (uid) || uid < 0 || FIXNUM_OVERFLOW_P (uid))
+    return make_float ((double)st->st_uid);
+  return make_number (uid);
+}
+
+static Lisp_Object
+make_gid (struct stat *st)
+{
+  EMACS_INT gid = st->st_gid;
+
+  if (sizeof (st->st_gid) > sizeof (gid) || gid < 0 || FIXNUM_OVERFLOW_P (gid))
+    return make_float ((double)st->st_gid);
+  return make_number (gid);
+}
+
 DEFUN ("file-attributes", Ffile_attributes, Sfile_attributes, 1, 2, 0,
        doc: /* Return a list of attributes of file FILENAME.
 Value is nil if specified file cannot be opened.
@@ -941,7 +964,7 @@
   Lisp_Object handler;
   struct gcpro gcpro1;
   EMACS_INT ino, uid, gid;
-  char *uname, *gname;
+  char *uname = NULL, *gname = NULL;
 
   filename = Fexpand_file_name (filename, Qnil);
 
@@ -976,32 +999,23 @@
 #endif
     }
   values[1] = make_number (s.st_nlink);
-  uid = s.st_uid;
-  gid = s.st_gid;
-  if (NILP (id_format) || EQ (id_format, Qinteger))
-    {
-      if (sizeof (s.st_uid) > sizeof (uid) || uid < 0
-         || FIXNUM_OVERFLOW_P (uid))
-       values[2] = make_float ((double)s.st_uid);
-      else
-       values[2] = make_number (uid);
-      if (sizeof (s.st_gid) > sizeof (gid) || gid < 0
-         || FIXNUM_OVERFLOW_P (gid))
-       values[3] = make_float ((double)s.st_gid);
-      else
-       values[3] = make_number (gid);
-    }
-  else
+
+  if (!(NILP (id_format) || EQ (id_format, Qinteger)))
     {
       BLOCK_INPUT;
       uname = stat_uname (&s);
-      values[2] = (uname ? build_string (uname)
-                  : make_fixnum_or_float (uid));
       gname = stat_gname (&s);
-      values[3] = (gname ? build_string (gname)
-                  : make_fixnum_or_float (gid));
       UNBLOCK_INPUT;
     }
+  if (uname)
+    values[2] = build_string (uname);
+  else
+    values[2] = make_uid (&s);
+  if (gname)
+    values[3] = build_string (gname);
+  else
+    values[3] = make_gid (&s);
+
   values[4] = make_time (s.st_atime);
   values[5] = make_time (s.st_mtime);
   values[6] = make_time (s.st_ctime);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]