aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2018-11-10 11:16:17 +0200
committerEli Zaretskii2018-11-10 11:16:17 +0200
commitd6b7b60cd0b4af8c0760589e132593b5c716d8ce (patch)
tree140b22b62d9456423ba283aaa2ce827b4d3a26b2
parentffb4c76d99ba9d4f5a0d876c23b2837d31291141 (diff)
downloademacs-d6b7b60cd0b4af8c0760589e132593b5c716d8ce.tar.gz
emacs-d6b7b60cd0b4af8c0760589e132593b5c716d8ce.zip
Fix last change
* src/editfns.c (Fgroup_name): Fix the doc string. Move closer to the "group" functions. * src/w32.c (getgrgid): Return NULL if GID is not the group ID of the user of this Emacs session * test/src/editfns-tests.el (test-group-name): Rename from 'group-name'. Add tests for non-Posix hosts. Test error when the argument to group-name is invalid. * etc/NEWS: Fix wording of last added entry.
-rw-r--r--etc/NEWS2
-rw-r--r--src/editfns.c33
-rw-r--r--src/w32.c4
-rw-r--r--test/src/editfns-tests.el19
4 files changed, 35 insertions, 23 deletions
diff --git a/etc/NEWS b/etc/NEWS
index c11b9988e44..7f3e74457da 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1264,7 +1264,7 @@ uses of this function all but disappeared by now, so we are
1264un-obsoleting it. 1264un-obsoleting it.
1265 1265
1266+++ 1266+++
1267** New function 'group-name' returns a group name based on a group-GID 1267** New function 'group-name' returns a group name corresponding to GID.
1268 1268
1269 1269
1270* Changes in Emacs 27.1 on Non-Free Operating Systems 1270* Changes in Emacs 27.1 on Non-Free Operating Systems
diff --git a/src/editfns.c b/src/editfns.c
index 15a0fa76597..8df4ed107e9 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1143,21 +1143,6 @@ 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
1161DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name, 1146DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
1162 0, 0, 0, 1147 0, 0, 0,
1163 doc: /* Return the name of the user's real uid, as a string. 1148 doc: /* Return the name of the user's real uid, as a string.
@@ -1191,6 +1176,24 @@ Value is a fixnum, if it's small enough, otherwise a bignum. */)
1191 return INT_TO_INTEGER (uid); 1176 return INT_TO_INTEGER (uid);
1192} 1177}
1193 1178
1179DEFUN ("group-name", Fgroup_name, Sgroup_name, 1, 1, 0,
1180 doc: /* Return the name of the group whose numeric group ID is GID.
1181The argument GID should be an integer or a float.
1182Return nil if a group with such GID does not exists or is not known. */)
1183 (Lisp_Object gid)
1184{
1185 struct group *gr;
1186 gid_t id;
1187
1188 if (!NUMBERP (gid) && !CONSP (gid))
1189 error ("Invalid GID specification");
1190 CONS_TO_INTEGER (gid, gid_t, id);
1191 block_input ();
1192 gr = getgrgid (id);
1193 unblock_input ();
1194 return gr ? build_string (gr->gr_name) : Qnil;
1195}
1196
1194DEFUN ("group-gid", Fgroup_gid, Sgroup_gid, 0, 0, 0, 1197DEFUN ("group-gid", Fgroup_gid, Sgroup_gid, 0, 0, 0,
1195 doc: /* Return the effective gid of Emacs. 1198 doc: /* Return the effective gid of Emacs.
1196Value is a fixnum, if it's small enough, otherwise a bignum. */) 1199Value is a fixnum, if it's small enough, otherwise a bignum. */)
diff --git a/src/w32.c b/src/w32.c
index e643c421506..3eaa1279dd6 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -2043,7 +2043,9 @@ getpwuid (unsigned uid)
2043struct group * 2043struct group *
2044getgrgid (gid_t gid) 2044getgrgid (gid_t gid)
2045{ 2045{
2046 return &dflt_group; 2046 if (gid == dflt_passwd.pw_gid)
2047 return &dflt_group;
2048 return NULL;
2047} 2049}
2048 2050
2049struct passwd * 2051struct passwd *
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 6ee0ab09f7b..7b6c990f350 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -351,11 +351,18 @@
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 () 354(ert-deftest test-group-name ()
355 (let ((list `((0 . "root") 355 (cond
356 (1000 . ,(user-login-name 1000)) 356 ((memq system-type '(windows-nt ms-dos))
357 (1212345 . nil)))) 357 (should (stringp (group-name (group-gid))))
358 (dolist (test list) 358 (should-not (group-name 123456789))
359 (should (equal (group-name (car test)) (cdr test)))))) 359 (should-error (group-name 'foo)))
360 (t
361 (let ((list `((0 . "root")
362 (1000 . ,(user-login-name 1000))
363 (1212345 . nil))))
364 (dolist (test list)
365 (should (equal (group-name (car test)) (cdr test)))))
366 (should-error (group-name 'foo)))))
360 367
361;;; editfns-tests.el ends here 368;;; editfns-tests.el ends here