aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJules Tamagnan2018-10-30 10:22:03 -0700
committerEli Zaretskii2018-11-10 10:06:50 +0200
commitffb4c76d99ba9d4f5a0d876c23b2837d31291141 (patch)
tree799541b022a0ff4f28d846bcbb7c51e79a5d9a92
parent4f0e54223a60a34818365475440e023747eab7e9 (diff)
downloademacs-ffb4c76d99ba9d4f5a0d876c23b2837d31291141.tar.gz
emacs-ffb4c76d99ba9d4f5a0d876c23b2837d31291141.zip
src/editfns.c (group-name): New function.
-rw-r--r--doc/lispref/os.texi5
-rw-r--r--etc/NEWS3
-rw-r--r--src/editfns.c16
-rw-r--r--test/src/editfns-tests.el7
4 files changed, 31 insertions, 0 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index cb337573259..6d1b3f3dbc9 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
1230return value is @code{nil}. 1230return value is @code{nil}.
1231@end defun 1231@end defun
1232 1232
1233@defun user-login-name gid
1234This runction returns the group name that corresponds to @var{gid},
1235or @code{nil} if there is no such group.
1236@end defun
1237
1233 1238
1234@node Time of Day 1239@node Time of Day
1235@section Time of Day 1240@section Time of Day
diff --git a/etc/NEWS b/etc/NEWS
index 29bbde9395e..c11b9988e44 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1263,6 +1263,9 @@ where there's no better alternative. We believe that the incorrect
1263uses of this function all but disappeared by now, so we are 1263uses of this function all but disappeared by now, so we are
1264un-obsoleting it. 1264un-obsoleting it.
1265 1265
1266+++
1267** New function 'group-name' returns a group name based on a group-GID
1268
1266 1269
1267* Changes in Emacs 27.1 on Non-Free Operating Systems 1270* Changes in Emacs 27.1 on Non-Free Operating Systems
1268 1271
diff --git a/src/editfns.c b/src/editfns.c
index e995b38a44d..15a0fa76597 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. */)
1143 return (pw ? build_string (pw->pw_name) : Qnil); 1143 return (pw ? build_string (pw->pw_name) : Qnil);
1144} 1144}
1145 1145
1146DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0,
1147 doc: /* If argument GID is an integer or a float, return the login name
1148of the group with that gid, or nil if there is no such GID. */)
1149 (Lisp_Object gid)
1150{
1151 struct group *gr;
1152 gid_t id;
1153
1154 CONS_TO_INTEGER (gid, gid_t, id);
1155 block_input ();
1156 gr = getgrgid (id);
1157 unblock_input ();
1158 return (gr ? build_string (gr->gr_name) : Qnil);
1159}
1160
1146DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name, 1161DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
1147 0, 0, 0, 1162 0, 0, 0,
1148 doc: /* Return the name of the user's real uid, as a string. 1163 doc: /* Return the name of the user's real uid, as a string.
@@ -4487,6 +4502,7 @@ it to be non-nil. */);
4487 defsubr (&Sinsert_byte); 4502 defsubr (&Sinsert_byte);
4488 4503
4489 defsubr (&Suser_login_name); 4504 defsubr (&Suser_login_name);
4505 defsubr (&Sgroup_name);
4490 defsubr (&Suser_real_login_name); 4506 defsubr (&Suser_real_login_name);
4491 defsubr (&Suser_uid); 4507 defsubr (&Suser_uid);
4492 defsubr (&Suser_real_uid); 4508 defsubr (&Suser_real_uid);
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 17b2c510734..6ee0ab09f7b 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -351,4 +351,11 @@
351 (should (equal (format "%-#50.40x" v3) 351 (should (equal (format "%-#50.40x" v3)
352 "-0x000000003ffffffffffffffe000000000000000 ")))) 352 "-0x000000003ffffffffffffffe000000000000000 "))))
353 353
354(ert-deftest group-name ()
355 (let ((list `((0 . "root")
356 (1000 . ,(user-login-name 1000))
357 (1212345 . nil))))
358 (dolist (test list)
359 (should (equal (group-name (car test)) (cdr test))))))
360
354;;; editfns-tests.el ends here 361;;; editfns-tests.el ends here