APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Mats Lidell <mats.lidell(a)cag.se>
# Date 1366409098 -7200
# Node ID c30fdcab7bc8eb4769a1a11d82d76bf20d6857c3
# Parent 02d0124c631454a744ad752c06e5c5966d781e12
Added optional argument ID-FORMAT to file-attributes for GNU compatibility.
src/ChangeLog:
2013-04-19 Mats Lidell <matsl(a)xemacs.org>
* sysdep.c (qxe_getgrgid): Encapsulation of getgrgid.
* syspwd.h: Ditto.
* dired.c (Ffile_attributes): Added optional ID-FORMAT for
compatibility with GNU.
diff -r 02d0124c6314 -r c30fdcab7bc8 src/ChangeLog
--- a/src/ChangeLog Thu Mar 28 08:33:57 2013 -0600
+++ b/src/ChangeLog Sat Apr 20 00:04:58 2013 +0200
@@ -1,3 +1,11 @@
+2013-04-19 Mats Lidell <matsl(a)xemacs.org>
+
+ * sysdep.c (qxe_getgrgid): Encapsulation of getgrgid.
+ * syspwd.h: Ditto.
+
+ * dired.c (Ffile_attributes): Added optional ID-FORMAT for
+ compatibility with GNU.
+
2013-03-28 Jerry James <james(a)xemacs.org>
* config.h.in: AC_FUNC_FSEEKO is the name of the autoconf macro.
diff -r 02d0124c6314 -r c30fdcab7bc8 src/dired.c
--- a/src/dired.c Thu Mar 28 08:33:57 2013 -0600
+++ b/src/dired.c Sat Apr 20 00:04:58 2013 +0200
@@ -1,5 +1,5 @@
/* Lisp functions for making directory listings.
- Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1985, 1986, 1992, 1993, 1994, 2013 Free Software Foundation, Inc.
Copyright (C) 2001, 2002 Ben Wing.
This file is part of XEmacs.
@@ -820,14 +820,20 @@
}
#endif
-DEFUN ("file-attributes", Ffile_attributes, 1, 1, 0, /*
+DEFUN ("file-attributes", Ffile_attributes, 1, 2, 0, /*
Return a list of attributes of file FILENAME.
Value is nil if specified file cannot be opened.
+
+ID-FORMAT specifies the preferred format of attributes uid and gid (see
+below) - valid values are 'string and 'integer. The latter is the
+default.
+
Otherwise, list elements are:
0. t for directory, string (name linked to) for symbolic link, or nil.
1. Number of links to file.
- 2. File uid.
- 3. File gid.
+ 2. File uid as a string or a number. If a string value cannot be
+ looked up, a numeric value, either an integer or a float, is returned.
+ 3. File gid, likewise.
4. Last access time, as a list of two integers.
First integer has high-order 16 bits of time, second has low 16 bits.
5. Last modification time, likewise.
@@ -840,7 +846,7 @@
If file does not exist, returns nil.
*/
- (filename))
+ (filename, id_format))
{
/* This function can GC. GC checked 1997.06.04. */
Lisp_Object directory = Qnil;
@@ -849,6 +855,9 @@
Lisp_Object handler, mode, modestring = Qnil, size, gid;
struct gcpro gcpro1, gcpro2, gcpro3;
+ Lisp_Object uidInfo = Qnil;
+ Lisp_Object gidInfo = Qnil;
+
GCPRO3 (filename, directory, modestring);
filename = Fexpand_file_name (filename, Qnil);
@@ -858,7 +867,10 @@
if (!NILP (handler))
{
UNGCPRO;
- return call2 (handler, Qfile_attributes, filename);
+ if (NILP(id_format))
+ return call2 (handler, Qfile_attributes, filename);
+ else
+ return call3 (handler, Qfile_attributes, filename, id_format);
}
if (qxe_lstat (XSTRING_DATA (filename), &s) < 0)
@@ -925,11 +937,25 @@
gid = (s.st_gid != getegid ()) ? Qt : Qnil;
#endif /* BSD4_2 or BSD4_3 */
+ if (NILP(id_format) || EQ (id_format, Qinteger))
+ {
+ uidInfo = make_integer (s.st_uid);
+ gidInfo = make_integer (s.st_gid);
+ }
+ else
+ {
+ struct passwd *pw = qxe_getpwuid (s.st_uid);
+ struct group *gr = qxe_getgrgid (s.st_gid);
+
+ uidInfo = build_istring (pw ? (Ibyte *) pw->pw_name : NULL);
+ gidInfo = build_istring (gr ? (Ibyte *) gr->gr_name : NULL);
+ }
+
RETURN_UNGCPRO (listn (12,
mode,
make_integer (s.st_nlink),
- make_integer (s.st_uid),
- make_integer (s.st_gid),
+ uidInfo,
+ gidInfo,
make_time (s.st_atime),
make_time (s.st_mtime),
make_time (s.st_ctime),
diff -r 02d0124c6314 -r c30fdcab7bc8 src/sysdep.c
--- a/src/sysdep.c Thu Mar 28 08:33:57 2013 -0600
+++ b/src/sysdep.c Sat Apr 20 00:04:58 2013 +0200
@@ -1,5 +1,5 @@
/* Interfaces to system-dependent kernel and library entries.
- Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
+ Copyright (C) 1985-1988, 1992-1995, 2013 Free Software Foundation, Inc.
Copyright (C) 1995 Tinker Systems.
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2010 Ben Wing.
@@ -3127,6 +3127,13 @@
#endif /* WIN32_NATIVE */
}
+// TODO: WIN32 mapping
+struct group *
+qxe_getgrgid (gid_t gid)
+{
+ return getgrgid (gid);
+}
+
#ifndef WIN32_NATIVE
struct passwd *
diff -r 02d0124c6314 -r c30fdcab7bc8 src/syspwd.h
--- a/src/syspwd.h Thu Mar 28 08:33:57 2013 -0600
+++ b/src/syspwd.h Sat Apr 20 00:04:58 2013 +0200
@@ -20,6 +20,7 @@
#ifndef WIN32_NATIVE
# include <pwd.h>
+# include <grp.h>
#else /* WIN32_NATIVE */
@@ -52,6 +53,7 @@
struct passwd *qxe_getpwnam (const Ibyte *name);
struct passwd *qxe_getpwuid (uid_t uid);
+struct group *qxe_getgrgid (gid_t gid);
struct passwd *qxe_getpwent (void);
#endif /* emacs */
diff -r 02d0124c6314 -r c30fdcab7bc8 tests/automated/dired-tests.el
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/automated/dired-tests.el Sat Apr 20 00:04:58 2013 +0200
@@ -0,0 +1,53 @@
+;; Copyright (C) 2013 Free Software Foundation, Inc.
+
+;; Author: Mats Lidell <matsl(a)xemacs.org>
+;; Maintainer:
+;; Created: 2013
+;; Keywords: tests
+
+;; This file is part of XEmacs.
+
+;; XEmacs is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by the
+;; Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+;; for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with XEmacs. If not, see <
http://www.gnu.org/licenses/>.
+
+;;; Synched up with: Not in FSF.
+
+;;; Commentary:
+
+;; Test tag support.
+;; See test-harness.el for instructions on how to run these tests.
+
+(require 'test-harness)
+
+(let* ((test-file-name (make-temp-file "dired-test"))
+ (attr (file-attributes test-file-name)))
+ (Assert (equal (nth 0 attr) nil))
+ (Assert (equal (nth 1 attr) 1))
+ (Assert (numberp (nth 2 attr)))
+ (Assert (equal (nth 2 attr) (user-uid)))
+ (Assert (numberp (nth 3 attr)))
+ (Assert (equal (nth 4 attr) (nth 5 attr)))
+ (Assert (equal (nth 4 attr) (nth 6 attr)))
+ (Assert (equal (nth 7 attr) 0)))
+
+;; Optional ID-FORMAT set -> uid and gid are strings
+(let* ((test-file-name (make-temp-file "dired-test"))
+ (attr (file-attributes test-file-name t)))
+ (Assert (equal (nth 0 attr) nil))
+ (Assert (equal (nth 1 attr) 1))
+ (Assert (stringp (nth 2 attr)))
+ (Assert (equal (nth 2 attr) (user-login-name)))
+ (Assert (stringp (nth 3 attr)))
+ (Assert (equal (nth 4 attr) (nth 5 attr)))
+ (Assert (equal (nth 4 attr) (nth 6 attr)))
+ (Assert (equal (nth 7 attr) 0)))
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-patches