emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master ffb4c76 1/2: src/editfns.c (group-name): New functi


From: Eli Zaretskii
Subject: [Emacs-diffs] master ffb4c76 1/2: src/editfns.c (group-name): New function.
Date: Sat, 10 Nov 2018 04:17:37 -0500 (EST)

branch: master
commit ffb4c76d99ba9d4f5a0d876c23b2837d31291141
Author: Jules Tamagnan <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    src/editfns.c (group-name): New function.
---
 doc/lispref/os.texi       |  5 +++++
 etc/NEWS                  |  3 +++
 src/editfns.c             | 16 ++++++++++++++++
 test/src/editfns-tests.el |  7 +++++++
 4 files changed, 31 insertions(+)

diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index cb33757..6d1b3f3 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1230,6 +1230,11 @@ groups on the system.  If Emacs cannot retrieve this 
information, the
 return value is @code{nil}.
 @end defun
 
address@hidden user-login-name gid
+This runction returns the group name that corresponds to @var{gid},
+or @code{nil} if there is no such group.
address@hidden defun
+
 
 @node Time of Day
 @section Time of Day
diff --git a/etc/NEWS b/etc/NEWS
index 29bbde9..c11b998 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1263,6 +1263,9 @@ where there's no better alternative.  We believe that the 
incorrect
 uses of this function all but disappeared by now, so we are
 un-obsoleting it.
 
++++
+** New function 'group-name' returns a group name based on a group-GID
+
 
 * Changes in Emacs 27.1 on Non-Free Operating Systems
 
diff --git a/src/editfns.c b/src/editfns.c
index e995b38..15a0fa7 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1143,6 +1143,21 @@ of the user with that uid, or nil if there is no such 
user.  */)
   return (pw ? build_string (pw->pw_name) : Qnil);
 }
 
+DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0,
+       doc: /* If argument GID is an integer or a float, return the login name
+of the group with that gid, or nil if there is no such GID.  */)
+  (Lisp_Object gid)
+{
+  struct group *gr;
+  gid_t id;
+
+  CONS_TO_INTEGER (gid, gid_t, id);
+  block_input ();
+  gr = getgrgid (id);
+  unblock_input ();
+  return (gr ? build_string (gr->gr_name) : Qnil);
+}
+
 DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
        0, 0, 0,
        doc: /* Return the name of the user's real uid, as a string.
@@ -4487,6 +4502,7 @@ it to be non-nil.  */);
   defsubr (&Sinsert_byte);
 
   defsubr (&Suser_login_name);
+  defsubr (&Sgroup_name);
   defsubr (&Suser_real_login_name);
   defsubr (&Suser_uid);
   defsubr (&Suser_real_uid);
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 17b2c51..6ee0ab0 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -351,4 +351,11 @@
     (should (equal (format "%-#50.40x" v3)
                    "-0x000000003ffffffffffffffe000000000000000        "))))
 
+(ert-deftest group-name ()
+  (let ((list `((0 . "root")
+                (1000 . ,(user-login-name 1000))
+                (1212345 . nil))))
+    (dolist (test list)
+      (should (equal (group-name (car test)) (cdr test))))))
+
 ;;; editfns-tests.el ends here



reply via email to

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